Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: show skeleton on loading on home page #694

Merged
merged 2 commits into from
Sep 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion src/components/collection/CollectionsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ type Props = {
showIsContentTag?: boolean;
};

const height = 300;

const CollectionsGrid = ({
collections,
isLoading,
Expand All @@ -30,7 +32,21 @@ const CollectionsGrid = ({
const { t } = useLibraryTranslation();

if (isLoading) {
return <Skeleton />;
return (
<Grid
container
spacing={4}
alignItems="stretch"
justifyContent="flex-start"
id={id}
>
{Array.from({ length: 4 }).map(() => (
<Grid xs={6} sm={4} md={3} lg={3} xl={2}>
<Skeleton height={height} sx={{ transform: 'unset' }} />
</Grid>
))}
</Grid>
);
}

return (
Expand Down
4 changes: 3 additions & 1 deletion src/components/collection/ItemCollection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ type ItemCollectionProps = {
title: string;
collections?: DiscriminatedItem[];
sx?: SxProps<Theme>;
isLoading?: boolean;
};

const ItemCollection = ({
Expand All @@ -22,6 +23,7 @@ const ItemCollection = ({
title,
collections,
sx,
isLoading = false,
}: ItemCollectionProps) => {
return (
<StyledContainer sx={sx} id={id}>
Expand All @@ -34,7 +36,7 @@ const ItemCollection = ({
<CollectionsGrid
collections={collections}
id={collectionGridId}
isLoading={false}
isLoading={isLoading}
/>
</StyledContainer>
);
Expand Down
17 changes: 12 additions & 5 deletions src/components/pages/Home.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,32 +26,39 @@ const Home = () => {

const { hooks } = useContext(QueryClientContext);

const { data: graasperCollections } =
const { data: graasperCollections, isLoading: isGraasperCollectionsLoading } =
hooks.usePublishedItemsForMember(GRAASPER_ID);
const { data: mostLikedCollections } = hooks.useMostLikedPublishedItems({
limit: HOMEPAGE_NB_ELEMENTS_TO_SHOW,
});
const { data: recentCollections } = hooks.useMostRecentPublishedItems({
const {
data: mostLikedCollections,
isLoading: isMostLikedCollectionsLoading,
} = hooks.useMostLikedPublishedItems({
limit: HOMEPAGE_NB_ELEMENTS_TO_SHOW,
});
const { data: recentCollections, isLoading: isMostRecentLoading } =
hooks.useMostRecentPublishedItems({
limit: HOMEPAGE_NB_ELEMENTS_TO_SHOW,
});

return (
<MainWrapper>
<StyledBackgroundContainer>
<HomeHeader />

<ItemCollection
isLoading={isGraasperCollectionsLoading}
id={GRAASP_SELECTION_TITLE_ID}
collectionGridId={GRAASPER_COLLECTIONS_GRID_ID}
collections={graasperCollections}
title={t(LIBRARY.HOME_GRAASPER_COLLECTIONS_TITLE)}
/>
<ItemCollection
isLoading={isMostLikedCollectionsLoading}
id={MOST_LIKED_TITLE_ID}
collections={mostLikedCollections}
title={t(LIBRARY.HOME_MOST_LIKED_COLLECTIONS_TITLE)}
/>
<ItemCollection
isLoading={isMostRecentLoading}
id={RECENT_PUBLICATIONS_TITLE_ID}
collections={recentCollections}
title={t(LIBRARY.HOME_RECENT_COLLECTIONS_TITLE)}
Expand Down