|
@@ -2,11 +2,12 @@ import React, { FC, Fragment, useCallback, useEffect, useMemo, useState } from '
|
|
|
|
|
|
import { useLanguages } from '@/api/hooks'
|
|
|
import {
|
|
|
+ ChannelEdge,
|
|
|
ChannelOrderByInput,
|
|
|
- ChannelWhereInput,
|
|
|
GetChannelsConnectionDocument,
|
|
|
GetChannelsConnectionQuery,
|
|
|
GetChannelsConnectionQueryVariables,
|
|
|
+ VideoEdge,
|
|
|
} from '@/api/queries'
|
|
|
import { ChannelWithVideos } from '@/components'
|
|
|
import { useInfiniteGrid } from '@/components/InfiniteGrids/useInfiniteGrid'
|
|
@@ -26,8 +27,11 @@ import {
|
|
|
|
|
|
type InfiniteChannelWithVideosGridProps = {
|
|
|
onDemand?: boolean
|
|
|
+ sortByViews?: boolean
|
|
|
title?: string
|
|
|
skipCount?: number
|
|
|
+ first?: number
|
|
|
+ orderBy?: ChannelOrderByInput
|
|
|
isReady?: boolean
|
|
|
className?: string
|
|
|
languageSelector?: boolean
|
|
@@ -36,6 +40,7 @@ type InfiniteChannelWithVideosGridProps = {
|
|
|
name: string
|
|
|
url: string
|
|
|
}
|
|
|
+ additionalSortFn?: (edge?: ChannelEdge[] | VideoEdge[]) => (ChannelEdge | VideoEdge)[]
|
|
|
}
|
|
|
|
|
|
const INITIAL_ROWS = 3
|
|
@@ -46,10 +51,14 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
title,
|
|
|
skipCount = 0,
|
|
|
isReady = true,
|
|
|
+ first,
|
|
|
+ orderBy = ChannelOrderByInput.CreatedAtAsc,
|
|
|
className,
|
|
|
+ sortByViews,
|
|
|
languageSelector,
|
|
|
idIn = null,
|
|
|
additionalLink,
|
|
|
+ additionalSortFn,
|
|
|
}) => {
|
|
|
const [selectedLanguage, setSelectedLanguage] = useState<string | null | undefined>(null)
|
|
|
const [targetRowsCount, setTargetRowsCount] = useState(INITIAL_ROWS)
|
|
@@ -58,7 +67,9 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
setTargetRowsCount((prevState) => prevState + 3)
|
|
|
}, [])
|
|
|
|
|
|
- const queryVariables: { where: ChannelWhereInput } = {
|
|
|
+ const queryVariables: GetChannelsConnectionQueryVariables = {
|
|
|
+ ...(first ? { first } : {}),
|
|
|
+ ...(orderBy ? { orderBy } : {}),
|
|
|
where: {
|
|
|
...(selectedLanguage ? { languageId_eq: selectedLanguage } : {}),
|
|
|
...(idIn ? { id_in: idIn } : {}),
|
|
@@ -75,11 +86,13 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
query: GetChannelsConnectionDocument,
|
|
|
isReady: languageSelector ? isReady && !!selectedLanguage : isReady,
|
|
|
skipCount,
|
|
|
- orderBy: ChannelOrderByInput.CreatedAtAsc,
|
|
|
+ orderBy,
|
|
|
queryVariables,
|
|
|
targetRowsCount,
|
|
|
dataAccessor: (rawData) => rawData?.channelsConnection,
|
|
|
itemsPerRow: INITIAL_CHANNELS_PER_ROW,
|
|
|
+ sortByViews,
|
|
|
+ additionalSortFn,
|
|
|
})
|
|
|
|
|
|
if (error) {
|
|
@@ -88,7 +101,6 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
|
|
|
const placeholderItems = Array.from({ length: placeholdersCount }, () => ({ id: undefined }))
|
|
|
const shouldShowLoadMoreButton = onDemand && !loading && displayedItems.length < totalCount
|
|
|
-
|
|
|
const itemsToShow = [...displayedItems, ...placeholderItems]
|
|
|
|
|
|
const mappedLanguages = useMemo(() => {
|
|
@@ -131,7 +143,8 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
items={mappedLanguages || []}
|
|
|
disabled={languagesLoading}
|
|
|
value={selectedLanguage}
|
|
|
- size="regular"
|
|
|
+ size="small"
|
|
|
+ helperText={null}
|
|
|
onChange={onSelectLanguage}
|
|
|
/>
|
|
|
</LanguageSelectWrapper>
|
|
@@ -142,7 +155,7 @@ export const InfiniteChannelWithVideosGrid: FC<InfiniteChannelWithVideosGridProp
|
|
|
size="medium"
|
|
|
variant="secondary"
|
|
|
iconPlacement="right"
|
|
|
- icon={<SvgGlyphChevronRight width={12} height={12} />}
|
|
|
+ icon={<SvgGlyphChevronRight />}
|
|
|
>
|
|
|
{additionalLink.name}
|
|
|
</AdditionalLink>
|