|
|
|
|
@ -1,7 +1,9 @@ |
|
|
|
|
import { useEffect, useState } from 'react' |
|
|
|
|
import { |
|
|
|
|
useCallback, |
|
|
|
|
useEffect, |
|
|
|
|
useState, |
|
|
|
|
} from 'react' |
|
|
|
|
|
|
|
|
|
import isNull from 'lodash/isNull' |
|
|
|
|
import isEmpty from 'lodash/isEmpty' |
|
|
|
|
import filter from 'lodash/filter' |
|
|
|
|
|
|
|
|
|
import type { LiveVideos, Videos } from 'requests' |
|
|
|
|
@ -17,22 +19,21 @@ export const useVideoData = () => { |
|
|
|
|
const { sportType } = useSportNameParam() |
|
|
|
|
const matchId = usePageId() |
|
|
|
|
|
|
|
|
|
const fetchMatchVideos = useCallback(async () => { |
|
|
|
|
const videosResponse = await getVideos(sportType, matchId) |
|
|
|
|
const filteredVideosResponseByAbc = filter(videosResponse, (vid) => vid.abc !== 1) |
|
|
|
|
setVideos(filteredVideosResponseByAbc) |
|
|
|
|
}, [sportType, matchId]) |
|
|
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
const requestVideos = async () => { |
|
|
|
|
const live = await getLiveVideos(sportType, matchId) |
|
|
|
|
if (isNull(live) || isEmpty(live)) { |
|
|
|
|
const videosResponse = await getVideos(sportType, matchId) |
|
|
|
|
const filteredVideosResponseByAbc = filter(videosResponse, (vid) => vid.abc !== 1) |
|
|
|
|
setVideos(filteredVideosResponseByAbc) |
|
|
|
|
} else { |
|
|
|
|
setLiveVideos(live) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
requestVideos() |
|
|
|
|
getLiveVideos(sportType, matchId) |
|
|
|
|
.then(setLiveVideos) |
|
|
|
|
.catch(fetchMatchVideos) |
|
|
|
|
}, |
|
|
|
|
[ |
|
|
|
|
sportType, |
|
|
|
|
matchId, |
|
|
|
|
fetchMatchVideos, |
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
return { |
|
|
|
|
|