Ott 475 watch match from last pause (#171)
* feat(#475): added match last watch seconds request * feat(#475): resuming stream/full matchkeep-around/af30b88d367751c9e05a735e4a0467a96238ef47
parent
c12897677f
commit
6a2bd02403
@ -0,0 +1,65 @@ |
|||||||
|
import { |
||||||
|
useEffect, |
||||||
|
useState, |
||||||
|
useMemo, |
||||||
|
} from 'react' |
||||||
|
import { useLocation } from 'react-router' |
||||||
|
|
||||||
|
import isBoolean from 'lodash/isBoolean' |
||||||
|
|
||||||
|
import type { LastPlayPosition } from 'requests' |
||||||
|
import { getMatchLastWatchSeconds } from 'requests' |
||||||
|
|
||||||
|
import { |
||||||
|
useSportNameParam, |
||||||
|
usePageId, |
||||||
|
useRequest, |
||||||
|
} from 'hooks' |
||||||
|
|
||||||
|
export const RESUME_KEY = 'resume' |
||||||
|
|
||||||
|
const readResumeParam = (search: string) => { |
||||||
|
const params = new URLSearchParams(search) |
||||||
|
const rawValue = params.get(RESUME_KEY) |
||||||
|
if (!rawValue) return false |
||||||
|
|
||||||
|
const value = JSON.parse(rawValue) |
||||||
|
return isBoolean(value) && Boolean(value) |
||||||
|
} |
||||||
|
|
||||||
|
const initialPosition = { |
||||||
|
half: 0, |
||||||
|
second: 0, |
||||||
|
} |
||||||
|
|
||||||
|
export const useLastPlayPosition = () => { |
||||||
|
const { search } = useLocation() |
||||||
|
const { sportType } = useSportNameParam() |
||||||
|
const matchId = usePageId() |
||||||
|
const [ |
||||||
|
lastPlayPosition, |
||||||
|
setPosition, |
||||||
|
] = useState<LastPlayPosition>(initialPosition) |
||||||
|
const { |
||||||
|
isFetching: isLastPlayPositionFetching, |
||||||
|
request: requestLastPlayPosition, |
||||||
|
} = useRequest(getMatchLastWatchSeconds) |
||||||
|
|
||||||
|
const resume = useMemo(() => readResumeParam(search), [search]) |
||||||
|
|
||||||
|
useEffect(() => { |
||||||
|
if (resume) { |
||||||
|
requestLastPlayPosition(sportType, matchId).then(setPosition) |
||||||
|
} |
||||||
|
}, [ |
||||||
|
sportType, |
||||||
|
matchId, |
||||||
|
resume, |
||||||
|
requestLastPlayPosition, |
||||||
|
]) |
||||||
|
|
||||||
|
return { |
||||||
|
isLastPlayPositionFetching, |
||||||
|
lastPlayPosition, |
||||||
|
} |
||||||
|
} |
||||||
@ -0,0 +1,43 @@ |
|||||||
|
import { |
||||||
|
DATA_URL, |
||||||
|
PROCEDURES, |
||||||
|
SportTypes, |
||||||
|
} from 'config' |
||||||
|
import { callApi, getResponseData } from 'helpers' |
||||||
|
|
||||||
|
const proc = PROCEDURES.get_user_match_second |
||||||
|
|
||||||
|
type Response = { |
||||||
|
_p_half: number | null, |
||||||
|
_p_second: number | null, |
||||||
|
} |
||||||
|
|
||||||
|
export type LastPlayPosition = { |
||||||
|
half: number, |
||||||
|
second: number, |
||||||
|
} |
||||||
|
|
||||||
|
export const getMatchLastWatchSeconds = async ( |
||||||
|
sportType: SportTypes, |
||||||
|
matchId: number, |
||||||
|
) => { |
||||||
|
const config = { |
||||||
|
body: { |
||||||
|
params: { |
||||||
|
_p_match_id: matchId, |
||||||
|
_p_sport: sportType, |
||||||
|
}, |
||||||
|
proc, |
||||||
|
}, |
||||||
|
} |
||||||
|
|
||||||
|
const response: Response = await callApi({ |
||||||
|
config, |
||||||
|
url: DATA_URL, |
||||||
|
}).then(getResponseData(proc)) |
||||||
|
|
||||||
|
return { |
||||||
|
half: response?._p_half ?? 0, |
||||||
|
second: response?._p_second ?? 0, |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue