Skip to content

Commit 972ab35

Browse files
fix(ui): show skeletons only for currently loading images
1 parent 55235f4 commit 972ab35

File tree

1 file changed

+31
-35
lines changed

1 file changed

+31
-35
lines changed

invokeai/frontend/web/src/features/gallery/components/ImageGalleryContent.tsx

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,9 @@ import { boardsSelector } from '../store/boardSlice';
6464
import { ChevronUpIcon } from '@chakra-ui/icons';
6565
import { useListAllBoardsQuery } from 'services/api/endpoints/boards';
6666
import { mode } from 'theme/util/mode';
67+
import { ImageDTO } from 'services/api/types';
68+
69+
const LOADING_IMAGE_ARRAY = Array(20).fill('loading');
6770

6871
const itemSelector = createSelector(
6972
[(state: RootState) => state],
@@ -79,10 +82,10 @@ const itemSelector = createSelector(
7982
? i.board_id === selectedBoardId
8083
: true;
8184
return isInCategory && isInSelectedBoard;
82-
});
85+
}) as (ImageDTO | string)[];
8386

8487
return {
85-
images,
88+
images: isLoading ? images.concat(LOADING_IMAGE_ARRAY) : images,
8689
allImagesTotal,
8790
isLoading,
8891
categories,
@@ -356,24 +359,28 @@ const ImageGalleryContent = () => {
356359
</Box>
357360
</Box>
358361
<Flex direction="column" gap={2} h="full" w="full">
359-
{isLoading ? (
360-
<LoadingGallery />
361-
) : images.length || areMoreAvailable ? (
362+
{images.length || areMoreAvailable ? (
362363
<>
363364
<Box ref={rootRef} data-overlayscrollbars="" h="100%">
364365
{shouldUseSingleGalleryColumn ? (
365366
<Virtuoso
366367
style={{ height: '100%' }}
367-
data={images}
368+
data={images as (ImageDTO | string)[]}
368369
endReached={handleEndReached}
369370
scrollerRef={(ref) => setScrollerRef(ref)}
370371
itemContent={(index, item) => (
371372
<Flex sx={{ pb: 2 }}>
372-
<HoverableImage
373-
key={`${item.image_name}-${item.thumbnail_url}`}
374-
image={item}
375-
isSelected={selectedImage === item?.image_name}
376-
/>
373+
{typeof item === 'string' ? (
374+
<Skeleton
375+
sx={{ w: 'full', h: 'full', aspectRatio: '1/1' }}
376+
/>
377+
) : (
378+
<HoverableImage
379+
key={`${item.image_name}-${item.thumbnail_url}`}
380+
image={item}
381+
isSelected={selectedImage === item?.image_name}
382+
/>
383+
)}
377384
</Flex>
378385
)}
379386
/>
@@ -388,11 +395,19 @@ const ImageGalleryContent = () => {
388395
}}
389396
scrollerRef={setScroller}
390397
itemContent={(index, item) => (
391-
<HoverableImage
392-
key={`${item.image_name}-${item.thumbnail_url}`}
393-
image={item}
394-
isSelected={selectedImage === item?.image_name}
395-
/>
398+
<Flex sx={{ pb: 2 }}>
399+
{typeof item === 'string' ? (
400+
<Skeleton
401+
sx={{ w: 'full', h: 'full', aspectRatio: '1/1' }}
402+
/>
403+
) : (
404+
<HoverableImage
405+
key={`${item.image_name}-${item.thumbnail_url}`}
406+
image={item}
407+
isSelected={selectedImage === item?.image_name}
408+
/>
409+
)}
410+
</Flex>
396411
)}
397412
/>
398413
)}
@@ -445,25 +460,6 @@ const ListContainer = forwardRef((props: ListContainerProps, ref) => {
445460
);
446461
});
447462

448-
const LoadingGallery = () => {
449-
return (
450-
<Box data-overlayscrollbars="" h="100%">
451-
<VirtuosoGrid
452-
style={{ height: '100%' }}
453-
data={new Array(20)}
454-
components={{
455-
Item: ItemContainer,
456-
List: ListContainer,
457-
}}
458-
itemContent={(index, item) => (
459-
<Flex sx={{ pb: 2 }}>
460-
<Skeleton sx={{ width: 'full', paddingBottom: '100%' }} />
461-
</Flex>
462-
)}
463-
/>
464-
</Box>
465-
);
466-
};
467463
const EmptyGallery = () => {
468464
const { t } = useTranslation();
469465
return (

0 commit comments

Comments
 (0)