Skip to content

Commit

Permalink
Fix orion requests issue in video ending view (#1028)
Browse files Browse the repository at this point in the history
* fix issue with redundant orion requests

* cr fixes
  • Loading branch information
drillprop authored Jul 22, 2021
1 parent f27c482 commit 5bcf11e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 11 deletions.
12 changes: 12 additions & 0 deletions src/api/hooks/video.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,13 @@ import { MutationHookOptions, QueryHookOptions } from '@apollo/client'

import {
AddVideoViewMutation,
GetBasicVideosQuery,
GetBasicVideosQueryVariables,
GetVideoQuery,
GetVideosQuery,
GetVideosQueryVariables,
useAddVideoViewMutation,
useGetBasicVideosQuery,
useGetVideoQuery,
useGetVideosQuery,
} from '@/api/queries'
Expand Down Expand Up @@ -52,3 +55,12 @@ export const useAddVideoView = (opts?: AddVideoViewOpts) => {
...rest,
}
}

type BasicVideosQueryOpts = QueryHookOptions<GetBasicVideosQuery>
export const useBasicVideos = (variables?: GetBasicVideosQueryVariables, opts?: BasicVideosQueryOpts) => {
const { data, ...rest } = useGetBasicVideosQuery({ ...opts, variables })
return {
videos: data?.videos,
...rest,
}
}
68 changes: 68 additions & 0 deletions src/api/queries/__generated__/videos.generated.tsx

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 16 additions & 0 deletions src/api/queries/videos.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ fragment LicenseFields on License {
customText
}

fragment BasicVideoFields on Video {
id
title
thumbnailPhotoUrls
thumbnailPhotoAvailability
thumbnailPhotoDataObject {
...DataObjectFields
}
}

fragment VideoFields on Video {
id
title
Expand Down Expand Up @@ -84,6 +94,12 @@ query GetVideos($offset: Int, $limit: Int, $where: VideoWhereInput, $orderBy: Vi
}
}

query GetBasicVideos($where: VideoWhereInput) {
videos(where: $where) {
...BasicVideoFields
}
}

### Orion

# modyfying this query name will need a sync-up in `src/api/client/resolvers.ts`
Expand Down
21 changes: 17 additions & 4 deletions src/providers/assets/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AllChannelFieldsFragment,
AssetAvailability,
BasicChannelFieldsFragment,
BasicVideoFieldsFragment,
VideoFieldsFragment,
} from '@/api/queries'
import { createStorageNodeUrl } from '@/utils/asset'
Expand All @@ -25,7 +26,13 @@ export const testAssetDownload = (url: string, type: AssetType) => {
})
}
export const readAssetData = (
entity: VideoFieldsFragment | AllChannelFieldsFragment | BasicChannelFieldsFragment | null | undefined,
entity:
| VideoFieldsFragment
| BasicVideoFieldsFragment
| AllChannelFieldsFragment
| BasicChannelFieldsFragment
| null
| undefined,
assetType: AssetType
): AssetResolutionData | null => {
if (entity?.__typename === 'Channel') {
Expand All @@ -44,9 +51,15 @@ export const readAssetData = (
}
} else if (entity?.__typename === 'Video') {
return {
availability: assetType === AssetType.MEDIA ? entity.mediaAvailability : entity.thumbnailPhotoAvailability,
urls: assetType === AssetType.MEDIA ? entity.mediaUrls : entity.thumbnailPhotoUrls,
dataObject: assetType === AssetType.MEDIA ? entity.mediaDataObject : entity.thumbnailPhotoDataObject,
availability:
assetType === AssetType.MEDIA
? (entity as VideoFieldsFragment).mediaAvailability
: entity.thumbnailPhotoAvailability,
urls: assetType === AssetType.MEDIA ? (entity as VideoFieldsFragment).mediaUrls : entity.thumbnailPhotoUrls,
dataObject:
assetType === AssetType.MEDIA
? (entity as VideoFieldsFragment).mediaDataObject
: entity.thumbnailPhotoDataObject,
assetType,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/providers/assets/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AllChannelFieldsFragment,
AssetAvailability,
BasicChannelFieldsFragment,
BasicVideoFieldsFragment,
DataObject,
VideoFieldsFragment,
} from '@/api/queries'
Expand All @@ -14,6 +15,7 @@ export enum AssetType {
}

export type UseAssetDataArgs =
| { entity?: BasicVideoFieldsFragment | null; assetType: AssetType.THUMBNAIL }
| { entity?: VideoFieldsFragment | null; assetType: AssetType.THUMBNAIL | AssetType.MEDIA }
| { entity?: AllChannelFieldsFragment | null; assetType: AssetType.COVER | AssetType.AVATAR }
| { entity?: BasicChannelFieldsFragment | null; assetType: AssetType.AVATAR }
Expand Down
8 changes: 4 additions & 4 deletions src/shared/components/VideoPlayer/VideoOverlay.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import React, { useEffect, useState } from 'react'
import { CSSTransition, SwitchTransition } from 'react-transition-group'

import { useVideos } from '@/api/hooks'
import { AssetAvailability, VideoFieldsFragment } from '@/api/queries'
import { useBasicVideos } from '@/api/hooks'
import { AssetAvailability, BasicVideoFieldsFragment } from '@/api/queries'
import { transitions } from '@/shared/theme'
import { getRandomIntInclusive } from '@/utils/number'

Expand All @@ -23,8 +23,8 @@ export const VideoOverlay: React.FC<VideoOverlaProps> = ({
currentThumbnailUrl,
videoId,
}) => {
const [randomNextVideo, setRandomNextVideo] = useState<VideoFieldsFragment | null>(null)
const { videos } = useVideos({
const [randomNextVideo, setRandomNextVideo] = useState<BasicVideoFieldsFragment | null>(null)
const { videos } = useBasicVideos({
where: {
channelId_eq: channelId,
isPublic_eq: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useEffect, useState } from 'react'
import { useNavigate } from 'react-router'

import { VideoFieldsFragment } from '@/api/queries'
import { BasicVideoFieldsFragment } from '@/api/queries'
import { absoluteRoutes } from '@/config/routes'
import { AssetType, useAsset } from '@/providers'
import { SvgGlyphRestart, SvgPlayerPause, SvgPlayerPlay } from '@/shared/icons'
Expand All @@ -24,7 +24,7 @@ type EndingOverlayProps = {
currentThumbnailUrl?: string | null
isFullScreen?: boolean
onPlayAgain?: () => void
randomNextVideo?: VideoFieldsFragment | null
randomNextVideo?: BasicVideoFieldsFragment | null
isEnded: boolean
}
// 10 seconds
Expand Down Expand Up @@ -97,7 +97,7 @@ export const EndingOverlay: React.FC<EndingOverlayProps> = ({
Up next
</SubHeading>
<Heading variant="h3">{randomNextVideo.title}</Heading>
<StyledChannelLink id={randomNextVideo.channel.id} avatarSize="default" />
<StyledChannelLink id={channelId} avatarSize="default" />
</VideoInfo>
<CountDownWrapper>
<StyledCircularProgressBar
Expand Down

0 comments on commit 5bcf11e

Please sign in to comment.