From 2fc0e2a5bec387c1459b58365caf1d7ec266aa40 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Tue, 16 Aug 2022 14:29:36 +0400 Subject: [PATCH] fix(#2684): fix calculate duration for match from scout --- .../components/FinishedMatch/hooks/index.tsx | 12 ++++++++---- src/features/MatchPopup/store/hooks/index.tsx | 16 +++++++--------- src/features/MultiSourcePlayer/index.tsx | 1 - 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx index 5ac60af6..20d8a741 100644 --- a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx +++ b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx @@ -3,6 +3,7 @@ import { useToggle } from 'hooks/useToggle' import type { Settings } from 'features/MatchPopup' import { useMatchPopupStore } from 'features/MatchPopup' +import { useEffect } from 'react' import { usePlayerLogger } from './usePlayerLogger' import { useEpisodes } from './useEpisodes' import { useChapters } from './useChapters' @@ -12,6 +13,7 @@ export const useFinishedMatch = () => { handlePlaylistClick, matchPlaylists, selectedPlaylist, + setChapters, setSettings, } = useMatchPopupStore() const { @@ -35,8 +37,14 @@ export const useFinishedMatch = () => { } handlePlaylistClick(playlist, e) } + const { chapters } = useChapters({ episodes, selectedPlaylist }) + + useEffect(() => { + setChapters(chapters) + }, [chapters, setChapters]) return { + chapters, closeSettingsPopup, isSettingsPopupOpen, onPlayingChange, @@ -45,9 +53,5 @@ export const useFinishedMatch = () => { playlists: matchPlaylists, selectedPlaylist, setEpisodesSettings, - ...useChapters({ - episodes, - selectedPlaylist, - }), } } diff --git a/src/features/MatchPopup/store/hooks/index.tsx b/src/features/MatchPopup/store/hooks/index.tsx index 28d41021..a563f377 100644 --- a/src/features/MatchPopup/store/hooks/index.tsx +++ b/src/features/MatchPopup/store/hooks/index.tsx @@ -15,6 +15,8 @@ import { useToggle } from 'hooks' import { buildPlaylists } from 'features/MatchPage/helpers/buildPlaylists' import { Playlists } from 'features/MatchPage/types' +import { Chapters } from 'features/MultiSourcePlayer/types' +import { useDuration } from 'features/MultiSourcePlayer/hooks/useDuration' import { useSettingsState } from './useSettingsState' import { useSportActions } from './useSportActions' @@ -23,8 +25,6 @@ import type { MatchData } from '../../types' import { PlayerPlaylistFormats } from '../../types' import { usePlayerClickHandler } from './usePlayerClickHandler' import { usePlaylistLexics } from './usePlaylistLexics' -import { calculateDuration } from '../../../MatchPage/helpers/fullMatchDuration' -import { useMatchPage } from '../../../MatchPage/store/hooks' type ArgsFetchMatchPlaylists = { id: number, @@ -37,8 +37,7 @@ const initialPlaylists = buildPlaylists(null) export const useMatchPopup = () => { const { pathname } = useLocation() const [match, setMatch] = useState(null) - const { profile } = useMatchPage() - + const [chapters, setChapters] = useState([]) const [matchPlaylists, setMatchPlaylists] = useState(initialPlaylists) const { close: closePopup, @@ -89,14 +88,14 @@ export const useMatchPopup = () => { useEffect(() => { setMatchPlaylists(initialPlaylists) }, [pathname]) - + const fullMatchDuration = useDuration(chapters) / 1000 const fetchMatchPlaylists = useCallback(({ id, sportType, withFullMatchDuration = true, }: ArgsFetchMatchPlaylists) => { getMatchPlaylists({ - fullMatchDuration: calculateDuration(profile), + fullMatchDuration, matchId: id, selectedActions: [], sportType, @@ -104,8 +103,7 @@ export const useMatchPopup = () => { }).then(fetchLexics) .then(buildPlaylists) .then(setMatchPlaylists) - }, [fetchLexics, profile]) - + }, [fetchLexics, fullMatchDuration]) const openMatchPopup = (selectedMatch: MatchData) => { if (!selectedMatch) return setMatch(selectedMatch) @@ -115,7 +113,6 @@ export const useMatchPopup = () => { sportType: selectedMatch.sportType, }) } - return { actions, closePopup, @@ -132,5 +129,6 @@ export const useMatchPopup = () => { setSettings, settings, ...usePlayerClickHandler(), + setChapters, } } diff --git a/src/features/MultiSourcePlayer/index.tsx b/src/features/MultiSourcePlayer/index.tsx index 1ad21b9b..e0e03a81 100644 --- a/src/features/MultiSourcePlayer/index.tsx +++ b/src/features/MultiSourcePlayer/index.tsx @@ -72,7 +72,6 @@ export const MultiSourcePlayer = (props: Props) => { wrapperRef, } = useMultiSourcePlayer(props) const firstPlayerActive = activePlayer === Players.PLAYER1 - return (