From 602050f347b75d51ab1053257be0dcbbf118e0b1 Mon Sep 17 00:00:00 2001 From: Andrei Dekterev Date: Tue, 22 Mar 2022 15:36:33 +0700 Subject: [PATCH] fix(#1701): return multisource and finished matches players --- .../components/FinishedMatch/helpers.tsx | 137 ++++++++++++++++++ .../components/FinishedMatch/hooks/index.tsx | 53 +++++++ .../FinishedMatch/hooks/useChapters.tsx | 46 ++++++ .../FinishedMatch/hooks/useEpisodes.tsx | 69 +++++++++ .../FinishedMatch/hooks/usePlayerLogger.tsx | 72 +++++++++ .../components/FinishedMatch/styled.tsx | 27 ++++ src/features/MatchPage/index.tsx | 2 + .../__tests__/index.tsx | 47 ++++++ .../helpers/calculateChapterStyles/index.tsx | 59 ++++++++ .../components/ProgressBar/hooks.tsx | 48 ++++++ .../components/ProgressBar/stories.tsx | 126 ++++++++++++++++ .../components/Settings/hooks.tsx | 27 ++++ .../components/Settings/index.tsx | 47 ++++++ .../components/Settings/styled.tsx | 78 ++++++++++ src/features/MultiSourcePlayer/config.tsx | 3 + .../MultiSourcePlayer/helpers/index.tsx | 35 +++++ .../MultiSourcePlayer/hooks/useDuration.tsx | 9 ++ .../hooks/usePlayingHandlers.tsx | 102 +++++++++++++ .../hooks/useProgressChangeHandler.tsx | 51 +++++++ .../hooks/useVideoQuality.tsx | 38 +++++ src/features/MultiSourcePlayer/types.tsx | 18 +++ src/requests/getVideos.tsx | 40 +++++ src/requests/index.tsx | 1 + 23 files changed, 1135 insertions(+) create mode 100644 src/features/MatchPage/components/FinishedMatch/helpers.tsx create mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/index.tsx create mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/useChapters.tsx create mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/useEpisodes.tsx create mode 100644 src/features/MatchPage/components/FinishedMatch/hooks/usePlayerLogger.tsx create mode 100644 src/features/MatchPage/components/FinishedMatch/styled.tsx create mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterStyles/__tests__/index.tsx create mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterStyles/index.tsx create mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/hooks.tsx create mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/stories.tsx create mode 100644 src/features/MultiSourcePlayer/components/Settings/hooks.tsx create mode 100644 src/features/MultiSourcePlayer/components/Settings/index.tsx create mode 100644 src/features/MultiSourcePlayer/components/Settings/styled.tsx create mode 100644 src/features/MultiSourcePlayer/config.tsx create mode 100644 src/features/MultiSourcePlayer/helpers/index.tsx create mode 100644 src/features/MultiSourcePlayer/hooks/useDuration.tsx create mode 100644 src/features/MultiSourcePlayer/hooks/usePlayingHandlers.tsx create mode 100644 src/features/MultiSourcePlayer/hooks/useProgressChangeHandler.tsx create mode 100644 src/features/MultiSourcePlayer/hooks/useVideoQuality.tsx create mode 100644 src/features/MultiSourcePlayer/types.tsx create mode 100644 src/requests/getVideos.tsx diff --git a/src/features/MatchPage/components/FinishedMatch/helpers.tsx b/src/features/MatchPage/components/FinishedMatch/helpers.tsx new file mode 100644 index 00000000..9639a342 --- /dev/null +++ b/src/features/MatchPage/components/FinishedMatch/helpers.tsx @@ -0,0 +1,137 @@ +import map from 'lodash/map' +import last from 'lodash/last' +import uniq from 'lodash/uniq' +import filter from 'lodash/filter' +import reduce from 'lodash/reduce' +import concat from 'lodash/concat' +import orderBy from 'lodash/orderBy' +import isEmpty from 'lodash/isEmpty' +import groupBy from 'lodash/groupBy' + +import type { + Videos, + Episodes, + Episode, +} from 'requests' + +import type { Chapters, Urls } from 'features/MultiSourcePlayer/types' + +import type { PlaylistOption } from '../../types' +import { FULL_GAME_KEY } from '../../helpers/buildPlaylists' + +const getUniquePeriods = (videos: Videos) => uniq(map(videos, ({ period }) => period)) + +type Video = { + duration: number, + period: number, + urls: Urls, +} + +const getVideoByPeriod = (videos: Videos, period: number) => { + const videosWithSamePeriod = filter(videos, { period }) + if (isEmpty(videosWithSamePeriod)) return null + + const urls = reduce( + videosWithSamePeriod, + (acc: Urls, video) => ({ + ...acc, + [video.quality]: video.url, + }), + {}, + ) + const [video] = videosWithSamePeriod + return { + duration: video.duration, + period: video.period, + urls, + } +} + +const getVideoByPeriods = (videos: Videos, periods: Array) => ( + reduce( + periods, + (acc: Array