Skip to content

Commit

Permalink
fix(home): ensure that videos skeletons are correctly displayed
Browse files Browse the repository at this point in the history
  • Loading branch information
AXeL-dev committed Nov 21, 2022
1 parent 31cb853 commit db02d81
Showing 1 changed file with 10 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from 'react';
import React, { useEffect, useRef } from 'react';
import { Box, Grid } from '@mui/material';
import { HomeView, Video } from 'types';
import VideoCard from './VideoCard';
Expand Down Expand Up @@ -29,8 +29,16 @@ function ChannelVideos(props: ChannelVideosProps) {
onVideoPlay,
onLoadMore,
} = props;
const showSkeletons = useRef(true);
const skeletonNumber = Math.min(maxResults - videos.length, itemsPerRow);

useEffect(() => {
if (!isLoading) {
showSkeletons.current = hasMore ?? true;
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isLoading]);

return (
<Box sx={{ display: 'flex', pl: 6 }}>
<Grid container spacing={config.gridSpacing} columns={config.gridColumns}>
Expand All @@ -39,7 +47,7 @@ function ChannelVideos(props: ChannelVideosProps) {
<VideoCard video={video} view={view} onVideoPlay={onVideoPlay} />
</GridItem>
))}
{isLoading && hasMore && skeletonNumber > 0
{isLoading && showSkeletons.current && skeletonNumber > 0
? Array.from(new Array(skeletonNumber)).map((_, index: number) => (
<GridItem key={index}>
<VideoSkeleton />
Expand Down

0 comments on commit db02d81

Please sign in to comment.