Skip to content
This repository has been archived by the owner on Jul 26, 2023. It is now read-only.

Commit

Permalink
refactor track init in video preview
Browse files Browse the repository at this point in the history
  • Loading branch information
myl7 committed Jun 1, 2022
1 parent 2831975 commit 270be90
Showing 1 changed file with 12 additions and 14 deletions.
26 changes: 12 additions & 14 deletions components/previews/VideoPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,17 +109,15 @@ const VideoPreview: FC<{ file: OdFileObject }> = ({ file }) => {

const [linkMenuOpen, setLinkMenuOpen] = useState(false)
const [trackMenuOpen, setTrackMenuOpen] = useState(false)
const [targetTracks, setTargetTracks] = useState<Plyr.Track[]>(() => {
return Array.from(['.vtt', '.ass', '.srt']).map(suffix => {
return {
kind: 'subtitles',
label: `${file.name.substring(0, file.name.lastIndexOf('.'))}${suffix}`,
src: `/api/raw/?path=${asPath.substring(0, asPath.lastIndexOf('.'))}${suffix}${
hashedToken ? `&odpt=${hashedToken}` : ''
}`,
}
})
})
const [tracks, setTracks] = useState<Plyr.Track[]>(() =>
Array.from(['.vtt', '.ass', '.srt']).map(suffix => ({
kind: 'subtitles',
label: `${file.name.substring(0, file.name.lastIndexOf('.'))}${suffix}`,
src: `/api/raw/?path=${asPath.substring(0, asPath.lastIndexOf('.'))}${suffix}${
hashedToken ? `&odpt=${hashedToken}` : ''
}`,
}))
)

const { t } = useTranslation()

Expand All @@ -144,8 +142,8 @@ const VideoPreview: FC<{ file: OdFileObject }> = ({ file }) => {
<>
<CustomEmbedLinkMenu path={asPath} menuOpen={linkMenuOpen} setMenuOpen={setLinkMenuOpen} />
<CustomVideoSubMenu
tracks={targetTracks}
setTracks={setTargetTracks}
tracks={tracks}
setTracks={setTracks}
menuOpen={trackMenuOpen}
setMenuOpen={setTrackMenuOpen}
/>
Expand All @@ -161,7 +159,7 @@ const VideoPreview: FC<{ file: OdFileObject }> = ({ file }) => {
width={file.video?.width}
height={file.video?.height}
thumbnail={thumbnail}
tracks={targetTracks}
tracks={tracks}
isFlv={isFlv}
mpegts={mpegts}
/>
Expand Down

0 comments on commit 270be90

Please sign in to comment.