fix(#462): match watch second to LS
parent
9376098b61
commit
b59c5ce832
@ -1,37 +0,0 @@ |
|||||||
import { useEffect, useState } from 'react' |
|
||||||
|
|
||||||
import type { LastPlayPosition } from 'requests' |
|
||||||
import { getMatchLastWatchSeconds } from 'requests' |
|
||||||
|
|
||||||
import { usePageParams } from 'hooks/usePageParams' |
|
||||||
import { useRequest } from 'hooks/useRequest' |
|
||||||
|
|
||||||
const initialPosition = { |
|
||||||
half: 0, |
|
||||||
second: 0, |
|
||||||
} |
|
||||||
|
|
||||||
export const useLastPlayPosition = () => { |
|
||||||
const { profileId: matchId, sportType } = usePageParams() |
|
||||||
const [ |
|
||||||
lastPlayPosition, |
|
||||||
setPosition, |
|
||||||
] = useState<LastPlayPosition>(initialPosition) |
|
||||||
const { |
|
||||||
isFetching: isLastPlayPositionFetching, |
|
||||||
request: requestLastPlayPosition, |
|
||||||
} = useRequest(getMatchLastWatchSeconds) |
|
||||||
|
|
||||||
useEffect(() => { |
|
||||||
requestLastPlayPosition(sportType, matchId).then(setPosition) |
|
||||||
}, [ |
|
||||||
sportType, |
|
||||||
matchId, |
|
||||||
requestLastPlayPosition, |
|
||||||
]) |
|
||||||
|
|
||||||
return { |
|
||||||
isLastPlayPositionFetching, |
|
||||||
lastPlayPosition, |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,23 +0,0 @@ |
|||||||
import { useMemo } from 'react' |
|
||||||
import { useLocation } from 'react-router' |
|
||||||
|
|
||||||
import isNumber from 'lodash/isNumber' |
|
||||||
|
|
||||||
export const RESUME_KEY = 'resume' |
|
||||||
|
|
||||||
const readResumeParam = (search: string) => { |
|
||||||
const params = new URLSearchParams(search) |
|
||||||
const rawValue = params.get(RESUME_KEY) |
|
||||||
if (!rawValue) return undefined |
|
||||||
|
|
||||||
const value = JSON.parse(rawValue) |
|
||||||
return isNumber(value) ? value : 0 |
|
||||||
} |
|
||||||
|
|
||||||
export const useUrlParam = () => { |
|
||||||
const { search } = useLocation() |
|
||||||
|
|
||||||
const resume = useMemo(() => readResumeParam(search), [search]) |
|
||||||
|
|
||||||
return resume |
|
||||||
} |
|
||||||
@ -1,43 +0,0 @@ |
|||||||
import { |
|
||||||
DATA_URL, |
|
||||||
PROCEDURES, |
|
||||||
|
|
||||||
} from 'config' |
|
||||||
import { callApi } 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: number, |
|
||||||
matchId: number, |
|
||||||
) => { |
|
||||||
const config = { |
|
||||||
body: { |
|
||||||
params: { |
|
||||||
_p_match_id: matchId, |
|
||||||
_p_sport: sportType, |
|
||||||
}, |
|
||||||
proc, |
|
||||||
}, |
|
||||||
} |
|
||||||
|
|
||||||
const response: Response = await callApi({ |
|
||||||
config, |
|
||||||
url: DATA_URL, |
|
||||||
}) |
|
||||||
|
|
||||||
return { |
|
||||||
half: response?._p_half ?? 0, |
|
||||||
second: response?._p_second ?? 0, |
|
||||||
} |
|
||||||
} |
|
||||||
@ -1,38 +0,0 @@ |
|||||||
import { |
|
||||||
DATA_URL, |
|
||||||
PROCEDURES, |
|
||||||
} from 'config' |
|
||||||
import { callApi } from 'helpers' |
|
||||||
|
|
||||||
const proc = PROCEDURES.save_user_match_second |
|
||||||
|
|
||||||
type Args = { |
|
||||||
half?: number, |
|
||||||
matchId: number, |
|
||||||
seconds: number, |
|
||||||
sport: number, |
|
||||||
} |
|
||||||
|
|
||||||
export const reportPlayerProgress = ({ |
|
||||||
half, |
|
||||||
matchId, |
|
||||||
seconds, |
|
||||||
sport, |
|
||||||
}: Args) => { |
|
||||||
const config = { |
|
||||||
body: { |
|
||||||
params: { |
|
||||||
_p_half: half, |
|
||||||
_p_match_id: matchId, |
|
||||||
_p_second: seconds, |
|
||||||
_p_sport: sport, |
|
||||||
}, |
|
||||||
proc, |
|
||||||
}, |
|
||||||
} |
|
||||||
|
|
||||||
callApi({ |
|
||||||
config, |
|
||||||
url: DATA_URL, |
|
||||||
}) |
|
||||||
} |
|
||||||
Loading…
Reference in new issue