From 227e9833143ec75f78c82856217fcfe705bcb89a Mon Sep 17 00:00:00 2001 From: Mirlan Date: Mon, 28 Dec 2020 17:39:40 +0600 Subject: [PATCH] Ott 595 playlists (#262) * Ott 595 part 1/links to playlist (#256) * refactor(595): moved match profile card into components * refactor(595): extracted players into separate component * refactor(595): moved scroll to video player into player component * feat(595): added links to playlist page * Ott 595 part 2/prep (#258) * feat(595): added useObjectState hook * refactor(595): get video qualities from chapters type * refactor(595): moved full match chapters building * refactor(595): calculate progress bar chapters progresses * fix(595): set progress limit * refactor(595): save only chapter progress * refactor(595): converted active chapter index ref into state * Ott 595 part 3/playper prep (#259) * refactor(595): playlist play prep refactoring * refactor(595): removed interviews block * feat(595): added requests and changed lexics * refactor(595): building and playing playlist (#260) * refactor(595): go to match on popup playlist click (#261) --- src/config/lexics/indexLexics.tsx | 2 +- src/config/procedures.tsx | 1 + src/config/profileTypes.tsx | 2 + .../MatchProfileCard/index.tsx | 0 .../MatchProfileCard/styled.tsx | 6 +- .../MatchPage/helpers/buildChapters.tsx | 121 ++++++++++++++++++ .../MatchPage/helpers/buildPlaylists.tsx | 53 ++++++++ src/features/MatchPage/hooks/useChapters.tsx | 35 +++++ src/features/MatchPage/hooks/useMatchPage.tsx | 49 +++++++ .../MatchPage/hooks/usePlaylistData.tsx | 42 ++++++ src/features/MatchPage/hooks/usePlaylists.tsx | 69 ++++++++++ .../MatchPage/hooks/useRouteState.tsx | 37 ++++++ src/features/MatchPage/hooks/useVideoData.tsx | 40 ------ src/features/MatchPage/index.tsx | 33 ++--- src/features/MatchPage/styled.tsx | 14 +- src/features/MatchPage/types.tsx | 48 +++++++ .../EpisodeDurationInputs/hooks.tsx | 2 +- .../components/MatchPlaylist/index.tsx | 56 +++----- .../components/PlayerActions/index.tsx | 2 +- .../components/PlayersList/index.tsx | 54 ++++---- .../components/PlayersList/styled.tsx | 28 ++-- .../components/PlayersListDesktop/index.tsx | 12 +- .../components/PlayersListMobile/index.tsx | 11 +- .../components/PlaylistButton/index.tsx | 37 ++++-- .../components/PlaylistPage/index.tsx | 3 - src/features/MatchPopup/config.tsx | 4 - src/features/MatchPopup/store/hooks/index.tsx | 21 ++- .../store/hooks/usePlayerClickHandler.tsx | 41 ++++++ .../store/hooks/useSettingsState.tsx | 32 ++--- src/features/MatchPopup/types.tsx | 24 ++++ .../__tests__/index.tsx | 36 ------ .../calculateChapterProgress/index.tsx | 8 -- .../__tests__/index.tsx | 8 +- .../helpers/calculateChapterStyles/index.tsx | 47 ++++++- .../components/ProgressBar/hooks.tsx | 13 +- .../components/ProgressBar/index.tsx | 12 +- .../components/ProgressBar/stories.tsx | 7 + .../MultiSourcePlayer/helpers/index.tsx | 4 +- .../MultiSourcePlayer/hooks/index.tsx | 115 +++++++++++------ .../hooks/usePlayingHandlers.tsx | 42 ++++++ .../hooks/usePlayingState.tsx | 35 ----- .../hooks/useProgressChangeHandler.tsx | 45 +++---- .../hooks/useVideoQuality.tsx | 13 +- .../MultiSourcePlayer/hooks/useVideos.tsx | 83 ------------ src/features/MultiSourcePlayer/index.tsx | 3 + src/features/MultiSourcePlayer/types.tsx | 1 + src/features/StreamPlayer/hooks/useSlider.tsx | 22 +++- src/features/StreamPlayer/index.tsx | 1 + src/features/VideoPlayer/hooks/index.tsx | 10 +- src/helpers/getProfileFallbackLogo/index.tsx | 8 +- src/hooks/index.tsx | 1 + src/hooks/useObjectState.tsx | 36 ++++++ src/requests/getMatchPlaylists.tsx | 23 ++-- src/requests/getPlayerPlaylists.tsx | 53 ++++++++ src/requests/index.tsx | 1 + src/requests/search.tsx | 2 +- 56 files changed, 1041 insertions(+), 467 deletions(-) rename src/features/MatchPage/{ => components}/MatchProfileCard/index.tsx (100%) rename src/features/MatchPage/{ => components}/MatchProfileCard/styled.tsx (96%) create mode 100644 src/features/MatchPage/helpers/buildChapters.tsx create mode 100644 src/features/MatchPage/helpers/buildPlaylists.tsx create mode 100644 src/features/MatchPage/hooks/useChapters.tsx create mode 100644 src/features/MatchPage/hooks/useMatchPage.tsx create mode 100644 src/features/MatchPage/hooks/usePlaylistData.tsx create mode 100644 src/features/MatchPage/hooks/usePlaylists.tsx create mode 100644 src/features/MatchPage/hooks/useRouteState.tsx delete mode 100644 src/features/MatchPage/hooks/useVideoData.tsx create mode 100644 src/features/MatchPage/types.tsx delete mode 100644 src/features/MatchPopup/config.tsx create mode 100644 src/features/MatchPopup/store/hooks/usePlayerClickHandler.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterProgress/__tests__/index.tsx delete mode 100644 src/features/MultiSourcePlayer/components/ProgressBar/helpers/calculateChapterProgress/index.tsx create mode 100644 src/features/MultiSourcePlayer/hooks/usePlayingHandlers.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/usePlayingState.tsx delete mode 100644 src/features/MultiSourcePlayer/hooks/useVideos.tsx create mode 100644 src/hooks/useObjectState.tsx create mode 100644 src/requests/getPlayerPlaylists.tsx diff --git a/src/config/lexics/indexLexics.tsx b/src/config/lexics/indexLexics.tsx index 0240c147..1aef1460 100644 --- a/src/config/lexics/indexLexics.tsx +++ b/src/config/lexics/indexLexics.tsx @@ -6,7 +6,7 @@ const matchPopupLexics = { go_back_to_match: 13405, match_interviews: 13031, match_playlist_ball_in_play: 2489, - match_playlist_full_game: 13028, + match_playlist_full_match: 13028, match_playlist_goals: 3559, match_playlist_highlights: 13033, match_settings: 13490, diff --git a/src/config/procedures.tsx b/src/config/procedures.tsx index df44e040..f52c6f62 100644 --- a/src/config/procedures.tsx +++ b/src/config/procedures.tsx @@ -22,6 +22,7 @@ export const PROCEDURES = { lst_c_country: 'lst_c_country', ott_match_popup: 'ott_match_popup', ott_match_popup_actions: 'ott_match_popup_actions', + ott_match_popup_player_playlist: 'ott_match_popup_player_playlist', param_lexical: 'param_lexical', save_user_custom_subscription: 'save_user_custom_subscription', save_user_favorite: 'save_user_favorite', diff --git a/src/config/profileTypes.tsx b/src/config/profileTypes.tsx index 1c6c1cd9..629038a3 100644 --- a/src/config/profileTypes.tsx +++ b/src/config/profileTypes.tsx @@ -2,10 +2,12 @@ export enum ProfileTypes { TOURNAMENTS = 1, TEAMS = 2, PLAYERS = 3, + MATCHES = 4, } export const PROFILE_NAMES = { [ProfileTypes.TOURNAMENTS]: 'tournaments', [ProfileTypes.TEAMS]: 'teams', [ProfileTypes.PLAYERS]: 'players', + [ProfileTypes.MATCHES]: 'matches', } as const diff --git a/src/features/MatchPage/MatchProfileCard/index.tsx b/src/features/MatchPage/components/MatchProfileCard/index.tsx similarity index 100% rename from src/features/MatchPage/MatchProfileCard/index.tsx rename to src/features/MatchPage/components/MatchProfileCard/index.tsx diff --git a/src/features/MatchPage/MatchProfileCard/styled.tsx b/src/features/MatchPage/components/MatchProfileCard/styled.tsx similarity index 96% rename from src/features/MatchPage/MatchProfileCard/styled.tsx rename to src/features/MatchPage/components/MatchProfileCard/styled.tsx index eae1dd08..887c21f1 100644 --- a/src/features/MatchPage/MatchProfileCard/styled.tsx +++ b/src/features/MatchPage/components/MatchProfileCard/styled.tsx @@ -10,14 +10,15 @@ export const Wrapper = styled.div` line-height: 24px; color: white; min-height: 28px; - max-width: 85%; + width: 100%; + margin-bottom: 14px; @media ${devices.desktop} { font-size: 22px; } + @media ${devices.laptop} { font-size: 18px; - max-width: 80%; } @media ${devices.tablet} { @@ -25,6 +26,7 @@ export const Wrapper = styled.div` font-size: 16px; padding: 15px 20px 0 20px; flex-wrap: wrap; + margin-bottom: 0; } ` diff --git a/src/features/MatchPage/helpers/buildChapters.tsx b/src/features/MatchPage/helpers/buildChapters.tsx new file mode 100644 index 00000000..091d7b0d --- /dev/null +++ b/src/features/MatchPage/helpers/buildChapters.tsx @@ -0,0 +1,121 @@ +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, + PlaylistData, + Episode, +} from 'requests' + +import type { Chapters, Urls } from 'features/MultiSourcePlayer/types' + +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