Ott 952 popup player actions (#340)

* refactor(952): light settings popup refactoring

* fix(952): fetch player actions on format select
keep-around/af30b88d367751c9e05a735e4a0467a96238ef47
Mirlan 5 years ago committed by GitHub
parent de55ca88b0
commit 5869da52fd
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 9
      src/features/MatchPage/components/FinishedMatch/hooks/index.tsx
  2. 4
      src/features/MatchPage/components/FinishedMatch/index.tsx
  3. 59
      src/features/MatchPage/components/SettingsDesktop/index.tsx
  4. 57
      src/features/MatchPage/components/SettingsDesktop/useDesktopSettings.tsx
  5. 15
      src/features/MatchPage/components/SettingsPopup/index.tsx
  6. 1
      src/features/MatchPopup/store/hooks/index.tsx

@ -1,7 +1,5 @@
import { useEffect } from 'react' import { useEffect } from 'react'
import isEqual from 'lodash/isEqual'
import type { MatchInfo } from 'requests' import type { MatchInfo } from 'requests'
import { import {
@ -23,14 +21,12 @@ export type Props = {
export const useFinishedMatch = ({ profile }: Props) => { export const useFinishedMatch = ({ profile }: Props) => {
const { const {
actions,
fetchMatchPlaylists, fetchMatchPlaylists,
handlePlaylistClick, handlePlaylistClick,
matchPlaylists, matchPlaylists,
selectedPlaylist, selectedPlaylist,
setMatch, setMatch,
setSettings, setSettings,
settings,
} = useMatchPopupStore() } = useMatchPopupStore()
const { sportType } = useSportNameParam() const { sportType } = useSportNameParam()
const matchId = usePageId() const matchId = usePageId()
@ -64,15 +60,11 @@ export const useFinishedMatch = ({ profile }: Props) => {
]) ])
const setEpisodesSettings = (newSettings: Settings) => { const setEpisodesSettings = (newSettings: Settings) => {
const settingsChanged = !isEqual(newSettings, settings)
if (settingsChanged) {
setSettings(newSettings) setSettings(newSettings)
}
closeSettingsPopup() closeSettingsPopup()
} }
return { return {
actions,
closeSettingsPopup, closeSettingsPopup,
isSettingsPopupOpen, isSettingsPopupOpen,
onPlaylistSelect: handlePlaylistClick, onPlaylistSelect: handlePlaylistClick,
@ -81,7 +73,6 @@ export const useFinishedMatch = ({ profile }: Props) => {
profile, profile,
selectedPlaylist, selectedPlaylist,
setEpisodesSettings, setEpisodesSettings,
settings,
...useChapters({ ...useChapters({
episodes, episodes,
selectedPlaylist, selectedPlaylist,

@ -16,7 +16,6 @@ import { Modal } from './styled'
export const FinishedMatch = (props: Props) => { export const FinishedMatch = (props: Props) => {
const { profile } = props const { profile } = props
const { const {
actions,
chapters, chapters,
closeSettingsPopup, closeSettingsPopup,
isSettingsPopupOpen, isSettingsPopupOpen,
@ -27,7 +26,6 @@ export const FinishedMatch = (props: Props) => {
playlists, playlists,
selectedPlaylist, selectedPlaylist,
setEpisodesSettings, setEpisodesSettings,
settings,
} = useFinishedMatch(props) } = useFinishedMatch(props)
return ( return (
@ -38,9 +36,7 @@ export const FinishedMatch = (props: Props) => {
withCloseButton={false} withCloseButton={false}
> >
<SettingsPopup <SettingsPopup
actions={actions}
onWatchEpisodesClick={setEpisodesSettings} onWatchEpisodesClick={setEpisodesSettings}
settings={settings}
closePopup={closeSettingsPopup} closePopup={closeSettingsPopup}
profile={profile} profile={profile}
selectedPlaylist={selectedPlaylist} selectedPlaylist={selectedPlaylist}

@ -2,14 +2,10 @@ import { Fragment } from 'react'
import styled from 'styled-components/macro' import styled from 'styled-components/macro'
import type { Actions } from 'requests' import isEqual from 'lodash/isEqual'
import { import type { Settings } from 'features/MatchPopup'
EpisodeDuration, import { PlayerPlaylistFormats } from 'features/MatchPopup'
PlayerPlaylistFormats,
SelectedActions,
Settings,
} from 'features/MatchPopup'
import { ButtonSolid } from 'features/Common' import { ButtonSolid } from 'features/Common'
import { T9n } from 'features/T9n' import { T9n } from 'features/T9n'
import { PlaylistFormats } from 'features/MatchPopup/components/PlaylistFormats' import { PlaylistFormats } from 'features/MatchPopup/components/PlaylistFormats'
@ -30,59 +26,50 @@ const WatchButton = styled(ButtonSolid)`
` `
type Props = { type Props = {
actions: Actions,
episodeDuration: EpisodeDuration,
isMatchPlaylist?: boolean, isMatchPlaylist?: boolean,
onWatchEpisodesClick: (values: Settings) => void, onWatchEpisodesClick: (values: Settings) => void,
selectedActions: SelectedActions,
selectedPlaylistFormat: PlayerPlaylistFormats,
} }
export const SettingsDesktop = ({ export const SettingsDesktop = ({
actions,
episodeDuration,
isMatchPlaylist, isMatchPlaylist,
onWatchEpisodesClick, onWatchEpisodesClick,
selectedActions,
selectedPlaylistFormat,
}: Props) => { }: Props) => {
const { const {
actionsValue, actions,
episodeDurationValue, localSettings,
selectedPlaylistFormatValue, onActionsChange,
setActionsValue, onEpisodeDurationsChange,
setEpisodeDurationValue, onPlaylistFormatChange,
setSelectedPlaylistFormatValue, settings,
} = useSettingsDesktop({ } = useSettingsDesktop()
const {
episodeDuration, episodeDuration,
selectedActions, selectedActions,
selectedPlaylistFormat, selectedFormat,
}) } = localSettings
const marginTop = isMatchPlaylist ? 0 : 62 const marginTop = isMatchPlaylist ? 0 : 62
return ( return (
<Fragment> <Fragment>
<PlaylistFormats <PlaylistFormats
marginTop={marginTop} marginTop={marginTop}
selectedFormat={selectedPlaylistFormatValue} selectedFormat={selectedFormat}
onFormatSelect={setSelectedPlaylistFormatValue} onFormatSelect={onPlaylistFormatChange}
/> />
<EpisodeDurationInputs <EpisodeDurationInputs
value={episodeDurationValue} value={episodeDuration}
onChange={setEpisodeDurationValue} onChange={onEpisodeDurationsChange}
/> />
{selectedPlaylistFormatValue === PlayerPlaylistFormats.SELECTED_ACTIONS && ( {selectedFormat === PlayerPlaylistFormats.SELECTED_ACTIONS && (
<PlayerActions <PlayerActions
actions={actions} actions={actions}
onActionClick={setActionsValue} onActionClick={onActionsChange}
selectedActions={actionsValue} selectedActions={selectedActions}
/> />
)} )}
<ButtonsWrapper> <ButtonsWrapper>
<WatchButton onClick={() => onWatchEpisodesClick({ <WatchButton
episodeDuration: episodeDurationValue, disabled={isEqual(localSettings, settings)}
selectedActions: actionsValue, onClick={() => onWatchEpisodesClick(localSettings)}
selectedFormat: selectedPlaylistFormatValue,
})}
> >
{isMatchPlaylist {isMatchPlaylist
? <T9n t='save' /> ? <T9n t='save' />

@ -1,37 +1,40 @@
import { useState } from 'react' import { useObjectState } from 'hooks'
import type { import type {
EpisodeDuration,
PlayerPlaylistFormats,
SelectedActions, SelectedActions,
EpisodeDuration,
} from 'features/MatchPopup' } from 'features/MatchPopup'
import { PlayerPlaylistFormats, useMatchPopupStore } from 'features/MatchPopup'
type Args = { export const useSettingsDesktop = () => {
episodeDuration: EpisodeDuration, const {
selectedActions: SelectedActions, actions,
selectedPlaylistFormat: PlayerPlaylistFormats, fetchSportActions,
} settings,
} = useMatchPopupStore()
const [localSettings, setSettings] = useObjectState(settings)
export const useSettingsDesktop = ({ const onPlaylistFormatChange = (playlistFormat: PlayerPlaylistFormats) => {
episodeDuration, setSettings({ selectedFormat: playlistFormat })
selectedActions, if (playlistFormat === PlayerPlaylistFormats.SELECTED_ACTIONS) {
selectedPlaylistFormat, fetchSportActions()
}: Args) => { }
const [actionsValue, setActionsValue] = useState<SelectedActions>(selectedActions) }
const [
episodeDurationValue, const onActionsChange = (selectedActions: SelectedActions) => {
setEpisodeDurationValue] = useState<EpisodeDuration>(episodeDuration) setSettings({ selectedActions })
const [ }
selectedPlaylistFormatValue,
setSelectedPlaylistFormatValue, const onEpisodeDurationsChange = (episodeDuration: EpisodeDuration) => {
] = useState<PlayerPlaylistFormats>(selectedPlaylistFormat) setSettings({ episodeDuration })
}
return { return {
actionsValue, actions,
episodeDurationValue, localSettings,
selectedPlaylistFormatValue, onActionsChange,
setActionsValue, onEpisodeDurationsChange,
setEpisodeDurationValue, onPlaylistFormatChange,
setSelectedPlaylistFormatValue, settings,
} }
} }

@ -2,7 +2,7 @@ import { MDASH } from 'config'
import styled from 'styled-components/macro' 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 { PlaylistOption } from 'features/MatchPage/types'
import type { Settings } from 'features/MatchPopup' import type { Settings } from 'features/MatchPopup'
import { PlaylistTypes } from 'features/MatchPage/types' import { PlaylistTypes } from 'features/MatchPage/types'
@ -37,20 +37,17 @@ const Content = styled.div<ContentProps>`
` `
type Props = { type Props = {
actions: Actions,
closePopup: () => void, closePopup: () => void,
onWatchEpisodesClick: (values: Settings) => void, onWatchEpisodesClick: (settings: Settings) => void,
profile: MatchInfo, profile: MatchInfo,
selectedPlaylist?: PlaylistOption, selectedPlaylist?: PlaylistOption,
settings: Settings,
} }
export const SettingsPopup = ({ export const SettingsPopup = ({
actions,
closePopup, closePopup,
onWatchEpisodesClick, onWatchEpisodesClick,
profile, profile,
selectedPlaylist, selectedPlaylist,
settings,
}: Props) => { }: Props) => {
if (!profile || !selectedPlaylist) return null if (!profile || !selectedPlaylist) return null
@ -71,7 +68,7 @@ export const SettingsPopup = ({
<CloseButton onClick={closePopup} /> <CloseButton onClick={closePopup} />
</HeaderActions> </HeaderActions>
<TitleWrapper> <TitleWrapper>
{selectedPlaylist && <Name nameObj={selectedPlaylist} />} <Name nameObj={selectedPlaylist} />
<TeamNames> <TeamNames>
<Name nameObj={profile.team1} /> <Name nameObj={profile.team1} />
{` ${MDASH} `} {` ${MDASH} `}
@ -90,12 +87,8 @@ export const SettingsPopup = ({
)} )}
<MediaQuery minDevice='tablet'> <MediaQuery minDevice='tablet'>
<SettingsDesktop <SettingsDesktop
actions={actions}
episodeDuration={settings.episodeDuration}
onWatchEpisodesClick={onWatchEpisodesClick} onWatchEpisodesClick={onWatchEpisodesClick}
isMatchPlaylist={isMatchPlaylist} isMatchPlaylist={isMatchPlaylist}
selectedActions={settings.selectedActions}
selectedPlaylistFormat={settings.selectedFormat}
/> />
</MediaQuery> </MediaQuery>
</Content> </Content>

@ -102,6 +102,7 @@ export const useMatchPopup = () => {
closePopup, closePopup,
episodeDuration, episodeDuration,
fetchMatchPlaylists, fetchMatchPlaylists,
fetchSportActions,
goBack, goBack,
goTo, goTo,
isOpen, isOpen,

Loading…
Cancel
Save