From cd0a0be6e3d1d5f163fd16b6a88aa3c50b5cd625 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Mon, 1 Aug 2022 12:02:05 +0400 Subject: [PATCH] fix(#1701): stop back to start video after episodes --- .../components/Chapters/index.tsx | 41 ++++++++++--------- .../components/ProgressBar/hooks.tsx | 3 +- .../components/ProgressBar/index.tsx | 4 +- src/features/StreamPlayer/hooks/index.tsx | 5 +++ src/features/StreamPlayer/index.tsx | 1 + 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/features/StreamPlayer/components/Chapters/index.tsx b/src/features/StreamPlayer/components/Chapters/index.tsx index 5ff72fa4..a5491c41 100644 --- a/src/features/StreamPlayer/components/Chapters/index.tsx +++ b/src/features/StreamPlayer/components/Chapters/index.tsx @@ -1,3 +1,5 @@ +import { RefObject } from 'react' + import map from 'lodash/map' import type { Chapter } from '../../types' @@ -16,24 +18,25 @@ type ChapterWithStyles = Chapter & { type Props = { chapters: Array, + videoRef?: RefObject, } -export const Chapters = ({ chapters }: Props) => ( - - { - map( - chapters, - ({ - loaded, - played, - width, - }, index) => ( - - - - - ), - ) - } - -) +export const Chapters = ({ chapters, videoRef }: Props) => { + const maxWidthProgressBar = videoRef?.current?.offsetWidth + return ( + + {map(chapters, ({ + loaded, + played, + width, + }, index) => ( + + + + + ))} + + ) +} diff --git a/src/features/StreamPlayer/components/ProgressBar/hooks.tsx b/src/features/StreamPlayer/components/ProgressBar/hooks.tsx index fea576e8..2167084d 100644 --- a/src/features/StreamPlayer/components/ProgressBar/hooks.tsx +++ b/src/features/StreamPlayer/components/ProgressBar/hooks.tsx @@ -1,4 +1,4 @@ -import { useMemo } from 'react' +import { useMemo, RefObject } from 'react' import { secondsToHms } from 'helpers' @@ -15,6 +15,7 @@ export type Props = { onTouchEnd?: () => any, onTouchStart?: () => any, playedProgress: number, + videoRef?: RefObject, } export const useProgressBar = ({ diff --git a/src/features/StreamPlayer/components/ProgressBar/index.tsx b/src/features/StreamPlayer/components/ProgressBar/index.tsx index 741f09ea..b2897fcd 100644 --- a/src/features/StreamPlayer/components/ProgressBar/index.tsx +++ b/src/features/StreamPlayer/components/ProgressBar/index.tsx @@ -8,7 +8,7 @@ import { useProgressBar } from './hooks' import { ProgressBarList } from './styled' export const ProgressBar = (props: Props) => { - const { onPlayedProgressChange } = props + const { onPlayedProgressChange, videoRef } = props const progressBarRef = useSlider({ onChange: onPlayedProgressChange }) const { calculatedChapters, @@ -18,7 +18,7 @@ export const ProgressBar = (props: Props) => { return ( - + diff --git a/src/features/StreamPlayer/hooks/index.tsx b/src/features/StreamPlayer/hooks/index.tsx index 3a06ec9b..a55e1866 100644 --- a/src/features/StreamPlayer/hooks/index.tsx +++ b/src/features/StreamPlayer/hooks/index.tsx @@ -298,6 +298,11 @@ export const useVideoPlayer = ({ }, [playing, onPlayingChange]) useEffect(() => { + if ((isLive + && chapters[0]?.isFullMatchChapter + && chaptersProps[0]?.isFullMatchChapter) + || isEmpty(chapters)) return + setPlayerState({ ...initialState, chapters: chaptersProps, diff --git a/src/features/StreamPlayer/index.tsx b/src/features/StreamPlayer/index.tsx index 67bcec54..19605c0e 100644 --- a/src/features/StreamPlayer/index.tsx +++ b/src/features/StreamPlayer/index.tsx @@ -153,6 +153,7 @@ export const StreamPlayer = (props: Props) => { onPlayedProgressChange={onProgressChange} playedProgress={playedProgress} loadedProgress={loadedProgress} + videoRef={videoRef} />