From 568c3b810fb2f1a474e89bc4a0f5441356d1a832 Mon Sep 17 00:00:00 2001 From: vec Date: Mon, 8 Jan 2024 01:48:18 +0800 Subject: [PATCH] =?UTF-8?q?[fix]=20=E5=9B=BE=E7=89=87=E5=8A=A0=E8=BD=BD?= =?UTF-8?q?=E9=A1=BA=E5=BA=8F=E4=B8=8D=E5=AF=B9=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- front/src/components/PhotoBox/index.tsx | 10 ++-- front/src/layouts/GalleryHome/index.tsx | 67 ++++++++++++++----------- 2 files changed, 43 insertions(+), 34 deletions(-) diff --git a/front/src/components/PhotoBox/index.tsx b/front/src/components/PhotoBox/index.tsx index c068ba3..d54c79e 100644 --- a/front/src/components/PhotoBox/index.tsx +++ b/front/src/components/PhotoBox/index.tsx @@ -86,7 +86,8 @@ export const PhotoBoxDimension = forwardRef< DimensionUnknown, Props>((props, re }) const PhotoBox = forwardRef((props, ref) => { - const { type, vertial_gutter, box_width, photo, hideMember, avatar, desc, style, vote_button_status } = props + const { type, vertial_gutter, box_width, photo, hideMember, + avatar, desc, style, vote_button_status } = props const [thumb_loaded, thumb] = useQueueload(photo.thumb) const [avatar_loaded, avatarThumb] = useQueueload(avatar?.thumb) @@ -99,8 +100,8 @@ const PhotoBox = forwardRef((props, ref) => { const coverFrameStyle = useMemo(() => ({ height, - background: avatar_loaded ? 'white' : '' - }), [avatar_loaded, height]) + background: thumb_loaded ? 'white' : '' + }), [thumb_loaded, height]) const show_desc = Boolean(desc.trim().length) const show_bottom_block = !hideMember || show_desc @@ -113,7 +114,8 @@ const PhotoBox = forwardRef((props, ref) => { className={`image-box-wrapper ${(type === 'compact') && 'compact'} ${none_bottom_block ? 'none-bottom-block' : 'has-bottom-block'}`} style={{ '--vertical-gutter': `${vertial_gutter}px`, - width: `calc(${box_width}px)`, ...(style ?? {}) + width: `calc(${box_width}px)`, + ...(style ?? {}) } as React.CSSProperties} >
diff --git a/front/src/layouts/GalleryHome/index.tsx b/front/src/layouts/GalleryHome/index.tsx index 84729b6..c9e219a 100644 --- a/front/src/layouts/GalleryHome/index.tsx +++ b/front/src/layouts/GalleryHome/index.tsx @@ -50,38 +50,41 @@ function usePhotoLoadingPriority( } const resort = useCallback(function _resortHandler() { - const in_screen_photos = photo_list.map(photo => { - const photo_el = document.getElementById(id('PHOTO', photo.id)) - if (!photo_el) { return } - const bounding = photo_el.getBoundingClientRect() - if ( - (bounding.y > (0 - bounding.height)) && - (bounding.y < window.innerHeight) - ) { - return { photo, bounding } - } else { - return - } - }).filter(p => p) as { photo: Photo, bounding: DOMRect }[] + requestAnimationFrame(() => { + const in_screen_photos = photo_list.map(photo => { + const photo_el = document.getElementById(id('PHOTO', photo.id)) + if (!photo_el) { return } + const bounding = photo_el.getBoundingClientRect() + if ( + (bounding.y > (0 - bounding.height)) && + (bounding.y < window.innerHeight) + ) { + console.log(bounding, photo_el) + return { photo, bounding } + } else { + return null + } + }).filter(p => p) as { photo: Photo, bounding: DOMRect }[] - const sorted = in_screen_photos.sort((a, b) => { - return a.bounding.y > b.bounding.y ? 1 : -1 - }) + const sorted = in_screen_photos.sort((a, b) => { + return a.bounding.y > b.bounding.y ? 1 : -1 + }) + + const all_tasks = getGlobalQueue() + setGlobalQueue( + all_tasks.map((t, idx) => { + return { ...t, priority: all_tasks.length - idx } + }) + ) - const all_tasks = getGlobalQueue() - setGlobalQueue( - all_tasks.map((t, idx) => { - return { ...t, priority: all_tasks.length - idx } + sorted.forEach(({ photo }, idx) => { + const src = id_src_map.get(photo.id) + if (!src) return + globalQueueLoad(src, 10000 - idx) + if (photo.member) { + globalQueueLoad(photo.member.avatar_thumb_url, 5000 - idx) + } }) - ) - - sorted.forEach(({ photo }, idx) => { - const src = id_src_map.get(photo.id) - if (!src) return - globalQueueLoad(src, 10000 - idx) - if (photo.member) { - globalQueueLoad(photo.member.avatar_thumb_url, 5000 - idx) - } }) }, [id_src_map, photo_list]) @@ -146,13 +149,17 @@ export default () => { return (active === null) ? [] : active.photos.map(p => p.id) }, [active]) - usePhotoLoadingPriority( + const resort = usePhotoLoadingPriority( useMemo(() => [ ...(active ? active.photos : []), ...list.map(g => g.photos).flat(), ], [active, list]) ) + useEffect(() => { + resort() + }, [resort]) + const [imageDetail, setImageDetail] = useState(null) const [currentQQNum, setCurrentQQNum] = useState(0)