You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
864 B
37 lines
864 B
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,
|
|
}
|
|
}
|
|
|