|
@@ -8,7 +8,7 @@ import {
|
|
GetVideosConnectionQueryVariables,
|
|
GetVideosConnectionQueryVariables,
|
|
VideoWhereInput,
|
|
VideoWhereInput,
|
|
} from '@/api/queries'
|
|
} from '@/api/queries'
|
|
-import { Grid, SkeletonLoader, Text } from '@/shared/components'
|
|
|
|
|
|
+import { Grid, LoadMoreButton, SkeletonLoader, Text } from '@/shared/components'
|
|
import { sizes } from '@/shared/theme'
|
|
import { sizes } from '@/shared/theme'
|
|
import { SentryLogger } from '@/utils/logs'
|
|
import { SentryLogger } from '@/utils/logs'
|
|
|
|
|
|
@@ -33,7 +33,7 @@ type InfiniteVideoGridProps = {
|
|
currentlyWatchedVideoId?: string
|
|
currentlyWatchedVideoId?: string
|
|
}
|
|
}
|
|
|
|
|
|
-const INITIAL_ROWS = 4
|
|
|
|
|
|
+const INITIAL_ROWS = 2
|
|
const INITIAL_VIDEOS_PER_ROW = 4
|
|
const INITIAL_VIDEOS_PER_ROW = 4
|
|
|
|
|
|
export const InfiniteVideoGrid: React.FC<InfiniteVideoGridProps> = ({
|
|
export const InfiniteVideoGrid: React.FC<InfiniteVideoGridProps> = ({
|
|
@@ -73,24 +73,24 @@ export const InfiniteVideoGrid: React.FC<InfiniteVideoGridProps> = ({
|
|
|
|
|
|
const targetRowsCount = targetRowsCountByCategory[cachedCategoryId]
|
|
const targetRowsCount = targetRowsCountByCategory[cachedCategoryId]
|
|
|
|
|
|
- const onScrollToBottom = useCallback(() => {
|
|
|
|
|
|
+ const fetchMore = useCallback(() => {
|
|
setTargetRowsCountByCategory((prevState) => ({
|
|
setTargetRowsCountByCategory((prevState) => ({
|
|
...prevState,
|
|
...prevState,
|
|
[cachedCategoryId]: targetRowsCount + 2,
|
|
[cachedCategoryId]: targetRowsCount + 2,
|
|
}))
|
|
}))
|
|
}, [cachedCategoryId, targetRowsCount])
|
|
}, [cachedCategoryId, targetRowsCount])
|
|
|
|
|
|
- const { placeholdersCount, displayedItems, error } = useInfiniteGrid<
|
|
|
|
|
|
+ const { placeholdersCount, displayedItems, error, allItemsLoaded, loading } = useInfiniteGrid<
|
|
GetVideosConnectionQuery,
|
|
GetVideosConnectionQuery,
|
|
GetVideosConnectionQuery['videosConnection'],
|
|
GetVideosConnectionQuery['videosConnection'],
|
|
GetVideosConnectionQueryVariables
|
|
GetVideosConnectionQueryVariables
|
|
>({
|
|
>({
|
|
query: GetVideosConnectionDocument,
|
|
query: GetVideosConnectionDocument,
|
|
- onScrollToBottom,
|
|
|
|
isReady: ready,
|
|
isReady: ready,
|
|
skipCount,
|
|
skipCount,
|
|
queryVariables,
|
|
queryVariables,
|
|
targetRowsCount,
|
|
targetRowsCount,
|
|
|
|
+ onDemand: true,
|
|
dataAccessor: (rawData) => {
|
|
dataAccessor: (rawData) => {
|
|
if (currentlyWatchedVideoId) {
|
|
if (currentlyWatchedVideoId) {
|
|
return (
|
|
return (
|
|
@@ -158,6 +158,11 @@ export const InfiniteVideoGrid: React.FC<InfiniteVideoGridProps> = ({
|
|
<section className={className}>
|
|
<section className={className}>
|
|
{title && (!ready ? <StyledSkeletonLoader height={23} width={250} /> : <Title variant="h5">{title}</Title>)}
|
|
{title && (!ready ? <StyledSkeletonLoader height={23} width={250} /> : <Title variant="h5">{title}</Title>)}
|
|
<Grid onResize={(sizes) => setVideosPerRow(sizes.length)}>{gridContent}</Grid>
|
|
<Grid onResize={(sizes) => setVideosPerRow(sizes.length)}>{gridContent}</Grid>
|
|
|
|
+ {!allItemsLoaded && !loading && (
|
|
|
|
+ <LoadMoreButtonWrapper>
|
|
|
|
+ <LoadMoreButton onClick={fetchMore} />
|
|
|
|
+ </LoadMoreButtonWrapper>
|
|
|
|
+ )}
|
|
</section>
|
|
</section>
|
|
)
|
|
)
|
|
}
|
|
}
|
|
@@ -169,3 +174,7 @@ const Title = styled(Text)`
|
|
const StyledSkeletonLoader = styled(SkeletonLoader)`
|
|
const StyledSkeletonLoader = styled(SkeletonLoader)`
|
|
margin-bottom: ${sizes(4)};
|
|
margin-bottom: ${sizes(4)};
|
|
`
|
|
`
|
|
|
|
+
|
|
|
|
+const LoadMoreButtonWrapper = styled.div`
|
|
|
|
+ margin-top: ${sizes(10)};
|
|
|
|
+`
|