Skip to content

Commit

Permalink
improve statistic condition
Browse files Browse the repository at this point in the history
  • Loading branch information
CleanBread committed Jan 8, 2025
1 parent 5b565dc commit 66981fe
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/compositions/LiveStatistics/LiveStatistics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,18 @@ const LiveStatistics: React.FC<LiveStatisticsProps> = ({ withCollapse = true, wi
const [ isVisible, setVisible ] = useState(true)
const [ isWarningVisible, setWarningVisible ] = useState(false)
const { liveClient } = useApolloClients()
const gameId = useSyncExternalStore(
const storeGameId = useSyncExternalStore(
liveStatisticsGameIdStore.subscribe,
liveStatisticsGameIdStore.getSnapshot,
() => ''
)

let gameId = storeGameId

if (params.gameId) {
gameId = params.gameId as string
}

const game = useMemo(() => {
return liveClient!.cache.readFragment<MainGameInfoFragment>({
id: liveClient!.cache.identify({ __typename: 'Game', id: gameId }),
Expand All @@ -58,7 +64,7 @@ const LiveStatistics: React.FC<LiveStatisticsProps> = ({ withCollapse = true, wi
return
}

if (gameId && gameId !== params.gameId) {
if (gameId && storeGameId !== gameId) {
setWarningVisible(true)

setTimeout(() => {
Expand All @@ -67,7 +73,7 @@ const LiveStatistics: React.FC<LiveStatisticsProps> = ({ withCollapse = true, wi
}
}, 5000)
}
}, [ gameId, params.gameId ])
}, [ storeGameId, params.gameId ])

if (!isAvailable || !gameId || !LIVE_STATISTICS_SUPPORTED_SPORTS.includes(+game?.sport?.sportId!)) {
return null
Expand Down

0 comments on commit 66981fe

Please sign in to comment.