|
|
|
@ -1,7 +1,18 @@ |
|
|
|
import { useState } from 'react' |
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
|
|
|
|
import { useQuery } from 'react-query' |
|
|
|
|
|
|
|
|
|
|
|
import { T9n } from 'features/T9n' |
|
|
|
import { T9n } from 'features/T9n' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { usePageParams } from 'hooks' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { querieKeys } from 'config' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { |
|
|
|
|
|
|
|
downloadPlaylist, |
|
|
|
|
|
|
|
type DownloadPlaylistProps, |
|
|
|
|
|
|
|
} from 'requests/downloadPlaylist' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import { Radio } from 'features/Common' |
|
|
|
import { |
|
|
|
import { |
|
|
|
Header, |
|
|
|
Header, |
|
|
|
Footer, |
|
|
|
Footer, |
|
|
|
@ -13,20 +24,76 @@ import { |
|
|
|
FirstTitle, |
|
|
|
FirstTitle, |
|
|
|
SecondTitle, |
|
|
|
SecondTitle, |
|
|
|
RadioButtonsWrapper, |
|
|
|
RadioButtonsWrapper, |
|
|
|
Input, |
|
|
|
|
|
|
|
Label, |
|
|
|
Label, |
|
|
|
} from './styled' |
|
|
|
} from './styled' |
|
|
|
|
|
|
|
|
|
|
|
type Props = { |
|
|
|
type Props = { |
|
|
|
closePopup: () => void, |
|
|
|
closePopup: () => void, |
|
|
|
isModalOpen: boolean, |
|
|
|
isModalOpen: boolean, |
|
|
|
|
|
|
|
openDownloadNotification: () => void, |
|
|
|
|
|
|
|
setPlaylistConfig: (config: DownloadPlaylistProps) => void, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const fileType: Record<'download_single_file'| 'download_files_for_periods', string> = { |
|
|
|
|
|
|
|
download_files_for_periods: 'download_files_for_periods', |
|
|
|
|
|
|
|
download_single_file: 'download_single_file', |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const initialRadioBtns: Record<string, boolean> = { |
|
|
|
|
|
|
|
entire_record: true, |
|
|
|
|
|
|
|
in_game_time_only: false, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
export const MatchDownloadPopup = ({ |
|
|
|
export const MatchDownloadPopup = ({ |
|
|
|
closePopup, |
|
|
|
closePopup, |
|
|
|
isModalOpen, |
|
|
|
isModalOpen, |
|
|
|
|
|
|
|
openDownloadNotification, |
|
|
|
|
|
|
|
setPlaylistConfig, |
|
|
|
}: Props) => { |
|
|
|
}: Props) => { |
|
|
|
const [selected, setSelected] = useState(true) |
|
|
|
const [downloadConfig, setDownloadConfig] = useState<typeof initialRadioBtns>(initialRadioBtns) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const { profileId: match_id, sportType: sport_id } = usePageParams() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const config: DownloadPlaylistProps = { |
|
|
|
|
|
|
|
ball_in_play: downloadConfig.in_game_time_only, |
|
|
|
|
|
|
|
match_id, |
|
|
|
|
|
|
|
sport_id, |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const { refetch } = useQuery( |
|
|
|
|
|
|
|
querieKeys.downloadPlaylist, |
|
|
|
|
|
|
|
() => downloadPlaylist(config), |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
enabled: false, // disable this query from automatically running
|
|
|
|
|
|
|
|
refetchOnWindowFocus: false, |
|
|
|
|
|
|
|
staleTime: 0, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleDownload = (id = fileType.download_single_file) => { |
|
|
|
|
|
|
|
if (downloadConfig.in_game_time_only) { |
|
|
|
|
|
|
|
config.concat = fileType.download_single_file === id |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setPlaylistConfig(config) |
|
|
|
|
|
|
|
refetch() |
|
|
|
|
|
|
|
closePopup() |
|
|
|
|
|
|
|
openDownloadNotification() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
setPlaylistConfig(config) |
|
|
|
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
|
|
|
|
}, [ |
|
|
|
|
|
|
|
downloadConfig, |
|
|
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const handleChange = (id: string) => { |
|
|
|
|
|
|
|
setDownloadConfig((prev) => Object.keys(prev) |
|
|
|
|
|
|
|
.reduce((result: typeof initialRadioBtns, key: keyof typeof initialRadioBtns) => ({ |
|
|
|
|
|
|
|
...result, |
|
|
|
|
|
|
|
[key]: id === key, |
|
|
|
|
|
|
|
}), {} as typeof initialRadioBtns)) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<Modal |
|
|
|
<Modal |
|
|
|
@ -42,28 +109,28 @@ export const MatchDownloadPopup = ({ |
|
|
|
</HeaderTitle> |
|
|
|
</HeaderTitle> |
|
|
|
</Header> |
|
|
|
</Header> |
|
|
|
<RadioButtonsWrapper> |
|
|
|
<RadioButtonsWrapper> |
|
|
|
<Label> |
|
|
|
{Object.entries(downloadConfig).map(([id, checked], index) => ( |
|
|
|
<Input |
|
|
|
<Label> |
|
|
|
defaultChecked={selected} |
|
|
|
<Radio |
|
|
|
name='in_game_time_only' |
|
|
|
name={id} |
|
|
|
onClick={() => setSelected(true)} |
|
|
|
key={id} |
|
|
|
/> |
|
|
|
checked={checked} |
|
|
|
<T9n t='in_game_time_only' /> |
|
|
|
onChange={(e) => handleChange(e.target.name)} |
|
|
|
</Label> |
|
|
|
/> |
|
|
|
<Label> |
|
|
|
<T9n t={id} /> |
|
|
|
<Input |
|
|
|
</Label> |
|
|
|
name='entire_record' |
|
|
|
))} |
|
|
|
defaultChecked={!selected} |
|
|
|
|
|
|
|
onClick={() => setSelected(false)} |
|
|
|
|
|
|
|
/> |
|
|
|
|
|
|
|
<T9n t='entire_record' /> |
|
|
|
|
|
|
|
</Label> |
|
|
|
|
|
|
|
</RadioButtonsWrapper> |
|
|
|
</RadioButtonsWrapper> |
|
|
|
<Footer> |
|
|
|
<Footer> |
|
|
|
<ScApplyButton> |
|
|
|
<ScApplyButton |
|
|
|
|
|
|
|
onClick={() => handleDownload(fileType.download_single_file)} |
|
|
|
|
|
|
|
> |
|
|
|
<T9n t='download_single_file' /> |
|
|
|
<T9n t='download_single_file' /> |
|
|
|
</ScApplyButton> |
|
|
|
</ScApplyButton> |
|
|
|
<ScApplyButton disabled={!selected}> |
|
|
|
<ScApplyButton |
|
|
|
|
|
|
|
disabled={!downloadConfig.in_game_time_only} |
|
|
|
|
|
|
|
onClick={() => handleDownload(fileType.download_files_for_periods)} |
|
|
|
|
|
|
|
> |
|
|
|
<T9n t='download_files_for_periods' /> |
|
|
|
<T9n t='download_files_for_periods' /> |
|
|
|
</ScApplyButton> |
|
|
|
</ScApplyButton> |
|
|
|
</Footer> |
|
|
|
</Footer> |
|
|
|
|