Skip to content

Commit

Permalink
Prefetch on video view only when video is already playing
Browse files Browse the repository at this point in the history
  • Loading branch information
WRadoslaw committed Feb 19, 2024
1 parent 67741bb commit 76b9dc7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 3 additions & 1 deletion packages/atlas/src/views/viewer/VideoView/MoreVideos.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type MoreVideosProps = {
categoryName?: string | null
videoId?: string
type: 'channel' | 'category'
shouldPrefetch?: boolean
}

const NUMBER_OF_VIDEOS = 6
Expand All @@ -33,6 +34,7 @@ export const MoreVideos: FC<MoreVideosProps> = ({
categoryName,
videoId,
type,
shouldPrefetch,
}) => {
const videoCategories = categoryId ? displayCategoriesLookup[categoryId].videoCategories : undefined
const where =
Expand Down Expand Up @@ -64,7 +66,7 @@ export const MoreVideos: FC<MoreVideosProps> = ({
id={video.id}
detailsVariant="withChannelName"
direction={lgMatch ? 'horizontal' : 'vertical'}
prefetch={idx < 5}
prefetch={idx < 5 && shouldPrefetch}
/>
</GridItem>
))}
Expand Down
12 changes: 11 additions & 1 deletion packages/atlas/src/views/viewer/VideoView/VideoView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ export const VideoView: FC = () => {
const { likeOrDislikeVideo } = useReactionTransactions()
const { withdrawBid } = useNftTransactions()
const { trackLikeAdded, trackDislikeAdded } = useSegmentAnalytics()
const [canPrefetchNew, setCanPrefetchNew] = useState(false)

const mdMatch = useMediaMatch('md')
const { addVideoView } = useAddVideoView()
Expand Down Expand Up @@ -202,6 +203,9 @@ export const VideoView: FC = () => {
// eslint-disable-next-line react-hooks/exhaustive-deps
const handleTimeUpdate = useCallback(
throttle((time) => {
if (!canPrefetchNew) {
setCanPrefetchNew(true)
}
if (video?.id) {
updateWatchedVideos('INTERRUPTED', video.id, time)
}
Expand Down Expand Up @@ -317,7 +321,13 @@ export const VideoView: FC = () => {
onWithdrawBid={(bid, createdAt) => id && createdAt && bid && withdrawBid(id, bid, createdAt)}
/>
)}
<MoreVideos channelId={channelId} channelName={channelName} videoId={id} type="channel" />
<MoreVideos
channelId={channelId}
channelName={channelName}
videoId={id}
type="channel"
shouldPrefetch={canPrefetchNew}
/>
{belongsToCategories?.map((category) => (
<MoreVideos
key={category.id}
Expand Down

0 comments on commit 76b9dc7

Please sign in to comment.