|
|
|
@ -11,25 +11,30 @@ import { MatchDownloadPopup } from 'features/MatchPage/components/MatchDownloadP |
|
|
|
|
|
|
|
|
|
|
|
import { usePageParams } from 'hooks/usePageParams' |
|
|
|
import { usePageParams } from 'hooks/usePageParams' |
|
|
|
|
|
|
|
|
|
|
|
import { useQueryClient } from 'react-query' |
|
|
|
import { useQuery } from 'react-query' |
|
|
|
import { DownloadResponse } from 'requests/downloadPlaylist' |
|
|
|
import { downloadPlaylist, type DownloadPlaylistProps } from 'requests/downloadPlaylist' |
|
|
|
import { querieKeys } from 'config' |
|
|
|
import { querieKeys } from 'config' |
|
|
|
import { useInterval } from 'hooks' |
|
|
|
import { useInterval } from 'hooks' |
|
|
|
import { useEffect } from 'react' |
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
import { downloadFile } from 'helpers' |
|
|
|
import { downloadFile } from 'helpers' |
|
|
|
import { DownloadButton, Title } from '../../styled' |
|
|
|
import { DownloadButton, Title } from '../../styled' |
|
|
|
import { Item } from '../MatchPlaylists' |
|
|
|
import { Item } from '../MatchPlaylists' |
|
|
|
|
|
|
|
|
|
|
|
type TMatchDownloadButton = { |
|
|
|
type TMatchDownloadButton = { |
|
|
|
|
|
|
|
close: () => void, |
|
|
|
open: () => void, |
|
|
|
open: () => void, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const INTERVAL_CHECK_DOWNLOAD_STATUS = 60 * 1000 |
|
|
|
const INTERVAL_CHECK_DOWNLOAD_STATUS = 60 * 1000 |
|
|
|
|
|
|
|
|
|
|
|
export const MatchDownloadButton = ({ open: openDownloadNotification }:TMatchDownloadButton) => { |
|
|
|
export const MatchDownloadButton = ({ |
|
|
|
|
|
|
|
close: closeDownloadNotification, |
|
|
|
|
|
|
|
open: openDownloadNotification, |
|
|
|
|
|
|
|
}:TMatchDownloadButton) => { |
|
|
|
const { user, userInfo } = useAuthStore() |
|
|
|
const { user, userInfo } = useAuthStore() |
|
|
|
const { profile } = useMatchPageStore() |
|
|
|
const { profile } = useMatchPageStore() |
|
|
|
const { sportType } = usePageParams() |
|
|
|
const { sportType } = usePageParams() |
|
|
|
|
|
|
|
const [playlistConfig, setPlaylistConfig] = useState<DownloadPlaylistProps | null>(null) |
|
|
|
|
|
|
|
|
|
|
|
const { |
|
|
|
const { |
|
|
|
close, |
|
|
|
close, |
|
|
|
@ -59,25 +64,28 @@ export const MatchDownloadButton = ({ open: openDownloadNotification }:TMatchDow |
|
|
|
return null |
|
|
|
return null |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
const client = useQueryClient() |
|
|
|
const { data, refetch } = useQuery( |
|
|
|
|
|
|
|
querieKeys.downloadPlaylist, |
|
|
|
const data = client.getQueryData<DownloadResponse>(querieKeys.downloadPlaylist) |
|
|
|
() => playlistConfig && downloadPlaylist(playlistConfig), |
|
|
|
|
|
|
|
{ |
|
|
|
const handleRefetch = () => { |
|
|
|
enabled: false, |
|
|
|
client.refetchQueries(querieKeys.downloadPlaylist) |
|
|
|
refetchOnWindowFocus: false, |
|
|
|
} |
|
|
|
staleTime: 0, |
|
|
|
|
|
|
|
}, |
|
|
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
|
|
const { start, stop } = useInterval({ |
|
|
|
const { start, stop } = useInterval({ |
|
|
|
callback: handleRefetch, |
|
|
|
callback: refetch, |
|
|
|
intervalDuration: INTERVAL_CHECK_DOWNLOAD_STATUS, |
|
|
|
intervalDuration: INTERVAL_CHECK_DOWNLOAD_STATUS, |
|
|
|
startImmediate: false, |
|
|
|
startImmediate: false, |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
useEffect(() => { |
|
|
|
start() |
|
|
|
if (!data) return undefined |
|
|
|
|
|
|
|
|
|
|
|
if (data?.status === 'COMPLETED' && data.urls) { |
|
|
|
if (data?.status === 'COMPLETED' && data.urls) { |
|
|
|
downloadFile(data.urls) |
|
|
|
downloadFile(data.urls) |
|
|
|
|
|
|
|
closeDownloadNotification() |
|
|
|
stop() |
|
|
|
stop() |
|
|
|
} else if (data?.status === 'ERROR') { |
|
|
|
} else if (data?.status === 'ERROR') { |
|
|
|
stop() |
|
|
|
stop() |
|
|
|
@ -85,7 +93,7 @@ export const MatchDownloadButton = ({ open: openDownloadNotification }:TMatchDow |
|
|
|
|
|
|
|
|
|
|
|
return () => stop() |
|
|
|
return () => stop() |
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
|
|
}, [data?.status]) |
|
|
|
}, [data?.status, refetch]) |
|
|
|
|
|
|
|
|
|
|
|
const isNeedDownloadButton = user && (isAvailableTournaments() || isAvailableTeams()) |
|
|
|
const isNeedDownloadButton = user && (isAvailableTournaments() || isAvailableTeams()) |
|
|
|
|
|
|
|
|
|
|
|
@ -97,8 +105,15 @@ export const MatchDownloadButton = ({ open: openDownloadNotification }:TMatchDow |
|
|
|
isModalOpen={isOpen} |
|
|
|
isModalOpen={isOpen} |
|
|
|
closePopup={close} |
|
|
|
closePopup={close} |
|
|
|
openDownloadNotification={openDownloadNotification} |
|
|
|
openDownloadNotification={openDownloadNotification} |
|
|
|
|
|
|
|
setPlaylistConfig={setPlaylistConfig} |
|
|
|
/> |
|
|
|
/> |
|
|
|
<DownloadButton onClick={open}> |
|
|
|
<DownloadButton onClick={ |
|
|
|
|
|
|
|
() => { |
|
|
|
|
|
|
|
open() |
|
|
|
|
|
|
|
start() |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
> |
|
|
|
<Title> |
|
|
|
<Title> |
|
|
|
<T9n t='download_full_match' /> |
|
|
|
<T9n t='download_full_match' /> |
|
|
|
</Title> |
|
|
|
</Title> |
|
|
|
|