fix(#727): save match stats fix

pull/289/head
Rakov 2 years ago
parent bef03ff120
commit 2a95f32aeb
  1. 32
      src/features/StreamPlayer/hooks/index.tsx
  2. 19
      src/requests/saveMatchStats.tsx

@ -116,6 +116,7 @@ export const useVideoPlayer = ({
playingOrder, playingOrder,
playingProgress, playingProgress,
playNextEpisode, playNextEpisode,
profile,
selectedPlaylist, selectedPlaylist,
setCircleAnimation, setCircleAnimation,
setIsFullScreen, setIsFullScreen,
@ -651,15 +652,28 @@ export const useVideoPlayer = ({
// ведем статистику просмотра матча // ведем статистику просмотра матча
const { start: startCollectingStats, stop: stopCollectingStats } = useInterval({ const { start: startCollectingStats, stop: stopCollectingStats } = useInterval({
callback: useCallback(() => { callback: useCallback(
if (timeForStatistics.current !== 0) { () => {
saveMatchStats({ if (timeForStatistics.current !== 0) {
matchId: profileId, saveMatchStats({
matchSecond: timeForStatistics.current, matchDate: profile?.date,
sportType, matchId: profileId,
}) matchSecond: timeForStatistics.current,
} seasonId: profile?.season.id,
}, [profileId, sportType]), sportType,
teamFirst: profile?.team1.id,
teamSecond: profile?.team2.id,
tournamentId: profile?.tournament.id,
})
}
},
[profile?.date,
profile?.season.id,
profile?.team1.id, profile?.team2.id,
profile?.tournament.id,
profileId, sportType,
],
),
intervalDuration: VIEW_INTERVAL_MS, intervalDuration: VIEW_INTERVAL_MS,
startImmediate: false, startImmediate: false,
}) })

@ -3,26 +3,41 @@ import { VIEWS_API } from 'config'
import { callApi } from 'helpers' import { callApi } from 'helpers'
type Props = { type Props = {
matchDate?: string,
matchId: number, matchId: number,
matchSecond: number, matchSecond: number,
seasonId?: number,
sportType: number, sportType: number,
teamFirst?: number,
teamSecond?: number,
tournamentId?: number,
} }
export const VIEW_INTERVAL_MS = 5000 export const VIEW_INTERVAL_MS = 5000
export const saveMatchStats = ({ export const saveMatchStats = ({
matchDate,
matchId, matchId,
matchSecond, matchSecond,
seasonId,
sportType, sportType,
teamFirst,
teamSecond,
tournamentId,
}: Props) => { }: Props) => {
const url = `${VIEWS_API}/user/view` const url = `${VIEWS_API}/v2/user/view`
const config = { const config = {
body: { body: {
interval: VIEW_INTERVAL_MS / 1000, duration: VIEW_INTERVAL_MS / 1000,
match_date: matchDate,
match_id: matchId, match_id: matchId,
season: seasonId,
second: matchSecond, second: matchSecond,
sport_id: sportType, sport_id: sportType,
team1: teamFirst,
team2: teamSecond,
tournament: tournamentId,
}, },
} }

Loading…
Cancel
Save