From 5869da52fde41694610e6b33e6340bcd7237fd02 Mon Sep 17 00:00:00 2001 From: Mirlan Date: Thu, 25 Mar 2021 13:36:31 +0600 Subject: [PATCH] Ott 952 popup player actions (#340) * refactor(952): light settings popup refactoring * fix(952): fetch player actions on format select --- .../components/FinishedMatch/hooks/index.tsx | 11 +--- .../components/FinishedMatch/index.tsx | 4 -- .../components/SettingsDesktop/index.tsx | 59 ++++++++----------- .../SettingsDesktop/useDesktopSettings.tsx | 57 +++++++++--------- .../components/SettingsPopup/index.tsx | 15 ++--- src/features/MatchPopup/store/hooks/index.tsx | 1 + 6 files changed, 59 insertions(+), 88 deletions(-) diff --git a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx index 53cceab1..fabfc537 100644 --- a/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx +++ b/src/features/MatchPage/components/FinishedMatch/hooks/index.tsx @@ -1,7 +1,5 @@ import { useEffect } from 'react' -import isEqual from 'lodash/isEqual' - import type { MatchInfo } from 'requests' import { @@ -23,14 +21,12 @@ export type Props = { export const useFinishedMatch = ({ profile }: Props) => { const { - actions, fetchMatchPlaylists, handlePlaylistClick, matchPlaylists, selectedPlaylist, setMatch, setSettings, - settings, } = useMatchPopupStore() const { sportType } = useSportNameParam() const matchId = usePageId() @@ -64,15 +60,11 @@ export const useFinishedMatch = ({ profile }: Props) => { ]) const setEpisodesSettings = (newSettings: Settings) => { - const settingsChanged = !isEqual(newSettings, settings) - if (settingsChanged) { - setSettings(newSettings) - } + setSettings(newSettings) closeSettingsPopup() } return { - actions, closeSettingsPopup, isSettingsPopupOpen, onPlaylistSelect: handlePlaylistClick, @@ -81,7 +73,6 @@ export const useFinishedMatch = ({ profile }: Props) => { profile, selectedPlaylist, setEpisodesSettings, - settings, ...useChapters({ episodes, selectedPlaylist, diff --git a/src/features/MatchPage/components/FinishedMatch/index.tsx b/src/features/MatchPage/components/FinishedMatch/index.tsx index ce73427d..e6be9cc2 100644 --- a/src/features/MatchPage/components/FinishedMatch/index.tsx +++ b/src/features/MatchPage/components/FinishedMatch/index.tsx @@ -16,7 +16,6 @@ import { Modal } from './styled' export const FinishedMatch = (props: Props) => { const { profile } = props const { - actions, chapters, closeSettingsPopup, isSettingsPopupOpen, @@ -27,7 +26,6 @@ export const FinishedMatch = (props: Props) => { playlists, selectedPlaylist, setEpisodesSettings, - settings, } = useFinishedMatch(props) return ( @@ -38,9 +36,7 @@ export const FinishedMatch = (props: Props) => { withCloseButton={false} > void, - selectedActions: SelectedActions, - selectedPlaylistFormat: PlayerPlaylistFormats, } export const SettingsDesktop = ({ - actions, - episodeDuration, isMatchPlaylist, onWatchEpisodesClick, - selectedActions, - selectedPlaylistFormat, }: Props) => { const { - actionsValue, - episodeDurationValue, - selectedPlaylistFormatValue, - setActionsValue, - setEpisodeDurationValue, - setSelectedPlaylistFormatValue, - } = useSettingsDesktop({ + actions, + localSettings, + onActionsChange, + onEpisodeDurationsChange, + onPlaylistFormatChange, + settings, + } = useSettingsDesktop() + const { episodeDuration, selectedActions, - selectedPlaylistFormat, - }) + selectedFormat, + } = localSettings const marginTop = isMatchPlaylist ? 0 : 62 return ( - {selectedPlaylistFormatValue === PlayerPlaylistFormats.SELECTED_ACTIONS && ( + {selectedFormat === PlayerPlaylistFormats.SELECTED_ACTIONS && ( )} - onWatchEpisodesClick({ - episodeDuration: episodeDurationValue, - selectedActions: actionsValue, - selectedFormat: selectedPlaylistFormatValue, - })} + onWatchEpisodesClick(localSettings)} > {isMatchPlaylist ? diff --git a/src/features/MatchPage/components/SettingsDesktop/useDesktopSettings.tsx b/src/features/MatchPage/components/SettingsDesktop/useDesktopSettings.tsx index 0bd6e8a9..5f35af2f 100644 --- a/src/features/MatchPage/components/SettingsDesktop/useDesktopSettings.tsx +++ b/src/features/MatchPage/components/SettingsDesktop/useDesktopSettings.tsx @@ -1,37 +1,40 @@ -import { useState } from 'react' +import { useObjectState } from 'hooks' import type { - EpisodeDuration, - PlayerPlaylistFormats, SelectedActions, + EpisodeDuration, } from 'features/MatchPopup' +import { PlayerPlaylistFormats, useMatchPopupStore } from 'features/MatchPopup' -type Args = { - episodeDuration: EpisodeDuration, - selectedActions: SelectedActions, - selectedPlaylistFormat: PlayerPlaylistFormats, -} +export const useSettingsDesktop = () => { + const { + actions, + fetchSportActions, + settings, + } = useMatchPopupStore() + const [localSettings, setSettings] = useObjectState(settings) + + const onPlaylistFormatChange = (playlistFormat: PlayerPlaylistFormats) => { + setSettings({ selectedFormat: playlistFormat }) + if (playlistFormat === PlayerPlaylistFormats.SELECTED_ACTIONS) { + fetchSportActions() + } + } + + const onActionsChange = (selectedActions: SelectedActions) => { + setSettings({ selectedActions }) + } -export const useSettingsDesktop = ({ - episodeDuration, - selectedActions, - selectedPlaylistFormat, -}: Args) => { - const [actionsValue, setActionsValue] = useState(selectedActions) - const [ - episodeDurationValue, - setEpisodeDurationValue] = useState(episodeDuration) - const [ - selectedPlaylistFormatValue, - setSelectedPlaylistFormatValue, - ] = useState(selectedPlaylistFormat) + const onEpisodeDurationsChange = (episodeDuration: EpisodeDuration) => { + setSettings({ episodeDuration }) + } return { - actionsValue, - episodeDurationValue, - selectedPlaylistFormatValue, - setActionsValue, - setEpisodeDurationValue, - setSelectedPlaylistFormatValue, + actions, + localSettings, + onActionsChange, + onEpisodeDurationsChange, + onPlaylistFormatChange, + settings, } } diff --git a/src/features/MatchPage/components/SettingsPopup/index.tsx b/src/features/MatchPage/components/SettingsPopup/index.tsx index fa7b98f3..2ab5035d 100644 --- a/src/features/MatchPage/components/SettingsPopup/index.tsx +++ b/src/features/MatchPage/components/SettingsPopup/index.tsx @@ -2,7 +2,7 @@ import { MDASH } from 'config' import styled from 'styled-components/macro' -import type { Actions, MatchInfo } from 'requests' +import type { MatchInfo } from 'requests' import type { PlaylistOption } from 'features/MatchPage/types' import type { Settings } from 'features/MatchPopup' import { PlaylistTypes } from 'features/MatchPage/types' @@ -37,20 +37,17 @@ const Content = styled.div` ` type Props = { - actions: Actions, closePopup: () => void, - onWatchEpisodesClick: (values: Settings) => void, + onWatchEpisodesClick: (settings: Settings) => void, profile: MatchInfo, selectedPlaylist?: PlaylistOption, - settings: Settings, } + export const SettingsPopup = ({ - actions, closePopup, onWatchEpisodesClick, profile, selectedPlaylist, - settings, }: Props) => { if (!profile || !selectedPlaylist) return null @@ -71,7 +68,7 @@ export const SettingsPopup = ({ - {selectedPlaylist && } + {` ${MDASH} `} @@ -90,12 +87,8 @@ export const SettingsPopup = ({ )} diff --git a/src/features/MatchPopup/store/hooks/index.tsx b/src/features/MatchPopup/store/hooks/index.tsx index 3017a2fd..378adfbd 100644 --- a/src/features/MatchPopup/store/hooks/index.tsx +++ b/src/features/MatchPopup/store/hooks/index.tsx @@ -102,6 +102,7 @@ export const useMatchPopup = () => { closePopup, episodeDuration, fetchMatchPlaylists, + fetchSportActions, goBack, goTo, isOpen,