|
@@ -1,8 +1,6 @@
|
|
import React, { FC, useState } from 'react'
|
|
import React, { FC, useState } from 'react'
|
|
|
|
|
|
-import { useChannel } from '@/api/hooks'
|
|
|
|
-import { GetVideosConnectionDocument, GetVideosConnectionQuery, GetVideosConnectionQueryVariables } from '@/api/queries'
|
|
|
|
-import { useInfiniteGrid } from '@/components/InfiniteGrids/useInfiniteGrid'
|
|
|
|
|
|
+import { useChannel, useChannelPreviewVideos } from '@/api/hooks'
|
|
import { VideoTile } from '@/components/VideoTile'
|
|
import { VideoTile } from '@/components/VideoTile'
|
|
import { absoluteRoutes } from '@/config/routes'
|
|
import { absoluteRoutes } from '@/config/routes'
|
|
import { useHandleFollowChannel } from '@/hooks'
|
|
import { useHandleFollowChannel } from '@/hooks'
|
|
@@ -26,47 +24,36 @@ type ChannelWithVideosProps = {
|
|
}
|
|
}
|
|
|
|
|
|
const INITIAL_VIDEOS_PER_ROW = 4
|
|
const INITIAL_VIDEOS_PER_ROW = 4
|
|
-const INITAL_ROWS = 1
|
|
|
|
|
|
+const INITIAL_ROWS = 1
|
|
|
|
|
|
export const ChannelWithVideos: FC<ChannelWithVideosProps> = ({ channelId }) => {
|
|
export const ChannelWithVideos: FC<ChannelWithVideosProps> = ({ channelId }) => {
|
|
const [videosPerRow, setVideosPerRow] = useState(INITIAL_VIDEOS_PER_ROW)
|
|
const [videosPerRow, setVideosPerRow] = useState(INITIAL_VIDEOS_PER_ROW)
|
|
- const { channel, loading } = useChannel(channelId || '')
|
|
|
|
|
|
+ const { channel, loading: channelLoading, error: channelError } = useChannel(channelId || '', {
|
|
|
|
+ skip: !channelId,
|
|
|
|
+ onError: (error) => SentryLogger.error('Failed to fetch channel', 'ChannelWithVideos', error),
|
|
|
|
+ })
|
|
|
|
+ const { videos, loading: videosLoading, error: videosError } = useChannelPreviewVideos(channelId, {
|
|
|
|
+ onError: (error) => SentryLogger.error('Failed to fetch videos', 'ChannelWithVideos', error),
|
|
|
|
+ })
|
|
|
|
|
|
const { url: avatarUrl, isLoadingAsset: isLoadingAvatar } = useAsset({ entity: channel, assetType: AssetType.AVATAR })
|
|
const { url: avatarUrl, isLoadingAsset: isLoadingAvatar } = useAsset({ entity: channel, assetType: AssetType.AVATAR })
|
|
const { toggleFollowing, isFollowing } = useHandleFollowChannel(channelId)
|
|
const { toggleFollowing, isFollowing } = useHandleFollowChannel(channelId)
|
|
- const { displayedItems, placeholdersCount, error } = useInfiniteGrid<
|
|
|
|
- GetVideosConnectionQuery,
|
|
|
|
- GetVideosConnectionQuery['videosConnection'],
|
|
|
|
- GetVideosConnectionQueryVariables
|
|
|
|
- >({
|
|
|
|
- query: GetVideosConnectionDocument,
|
|
|
|
- isReady: !!channelId,
|
|
|
|
- skipCount: 0,
|
|
|
|
- queryVariables: {
|
|
|
|
- where: {
|
|
|
|
- channelId_eq: channelId,
|
|
|
|
- isPublic_eq: true,
|
|
|
|
- isCensored_eq: false,
|
|
|
|
- },
|
|
|
|
- },
|
|
|
|
- targetRowsCount: INITAL_ROWS,
|
|
|
|
- dataAccessor: (rawData) => rawData?.videosConnection,
|
|
|
|
- itemsPerRow: videosPerRow,
|
|
|
|
- onError: (error) => SentryLogger.error('Failed to fetch videos', 'ChannelWithVideos', error),
|
|
|
|
- })
|
|
|
|
|
|
|
|
- const placeholderItems = Array.from({ length: placeholdersCount }, () => ({ id: undefined }))
|
|
|
|
|
|
+ const targetItemsCount = videosPerRow * INITIAL_ROWS
|
|
|
|
+ const displayedVideos = (videos || []).slice(0, targetItemsCount)
|
|
|
|
+ const placeholderItems = videosLoading ? Array.from({ length: targetItemsCount }, () => ({ id: undefined })) : []
|
|
|
|
+
|
|
const gridContent = (
|
|
const gridContent = (
|
|
<>
|
|
<>
|
|
- {[...displayedItems, ...placeholderItems]?.map((video, idx) => (
|
|
|
|
|
|
+ {[...displayedVideos, ...placeholderItems].map((video, idx) => (
|
|
<VideoTile id={video.id} key={`channels-with-videos-${idx}`} showChannel />
|
|
<VideoTile id={video.id} key={`channels-with-videos-${idx}`} showChannel />
|
|
))}
|
|
))}
|
|
</>
|
|
</>
|
|
)
|
|
)
|
|
|
|
|
|
- const isLoading = !channelId || loading
|
|
|
|
|
|
+ const isLoading = !channelId || channelLoading
|
|
|
|
|
|
- if (error) {
|
|
|
|
|
|
+ if (channelError || videosError) {
|
|
return null
|
|
return null
|
|
}
|
|
}
|
|
|
|
|