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.
 
 
 
 
spa_instat_tv/src/features/MatchSidePlaylists/hooks.tsx

42 lines
1.1 KiB

import { useEffect } from 'react'
import { useQueryClient } from 'react-query'
import findIndex from 'lodash/findIndex'
import isNil from 'lodash/isNil'
import { querieKeys } from 'config'
import type { MatchScore } from 'requests'
import { MatchStatuses } from 'requests'
import { useMatchPageStore } from 'features/MatchPage/store'
import { Tabs } from './config'
export const useMatchSidePlaylists = () => {
const {
closePopup,
profile: matchProfile,
selectedTab,
setSelectedTab,
} = useMatchPageStore()
const client = useQueryClient()
const matchScore = client.getQueryData<MatchScore>(querieKeys.matchScore)
const videoBounds = matchScore?.video_bounds || matchProfile?.video_bounds
const matchStatus = matchScore?.c_match_calc_status || matchProfile?.c_match_calc_status
const showTabs = Number(matchStatus) > MatchStatuses.Upcoming
&& findIndex(videoBounds, ({ h, s }) => h === '1' && !isNil(s)) !== -1
useEffect(() => {
if (selectedTab !== Tabs.EVENTS) closePopup()
}, [selectedTab, closePopup])
return {
onTabClick: setSelectedTab,
selectedTab,
showTabs,
}
}