@@ -7,7 +7,7 @@ import { motion } from 'framer-motion'
77import { Loading } from 'src/components'
88import { AuthenticatedWrapper } from 'src/components/Common/AuthenticatedWrapper'
99import { useBroadcastController } from 'src/hooks/useBroadcastController'
10- import { Broadcast } from 'src/types'
10+ import { Broadcast , BroadcastRound } from 'src/types'
1111
1212const fadeInUp = {
1313 initial : { opacity : 0 , y : 15 } ,
@@ -23,6 +23,25 @@ const staggerContainer = {
2323 } ,
2424}
2525
26+ const getPreferredBroadcastRound = (
27+ broadcast : Broadcast ,
28+ ) : BroadcastRound | undefined => {
29+ const defaultRound = broadcast . rounds . find (
30+ ( r ) => r . id === broadcast . defaultRoundId ,
31+ )
32+ if ( defaultRound ) return defaultRound
33+
34+ const liveRound = broadcast . rounds . find ( ( r ) => r . ongoing )
35+ if ( liveRound ) return liveRound
36+
37+ const startedRounds = broadcast . rounds
38+ . filter ( ( r ) => r . startsAt <= Date . now ( ) )
39+ . sort ( ( a , b ) => b . startsAt - a . startsAt )
40+ if ( startedRounds . length > 0 ) return startedRounds [ 0 ]
41+
42+ return broadcast . rounds [ 0 ]
43+ }
44+
2645const BroadcastsPage : NextPage = ( ) => {
2746 const router = useRouter ( )
2847 const { broadcastSections, broadcastState, loadBroadcasts } =
@@ -43,10 +62,7 @@ const BroadcastsPage: NextPage = () => {
4362 } , [ loadBroadcasts ] )
4463
4564 const handleSelectBroadcast = ( broadcast : Broadcast ) => {
46- const defaultRound =
47- broadcast . rounds . find ( ( r ) => r . id === broadcast . defaultRoundId ) ||
48- broadcast . rounds . find ( ( r ) => r . ongoing ) ||
49- broadcast . rounds [ 0 ]
65+ const defaultRound = getPreferredBroadcastRound ( broadcast )
5066
5167 if ( defaultRound ) {
5268 router . push ( `/broadcast/${ broadcast . tour . id } /${ defaultRound . id } ` )
@@ -210,7 +226,11 @@ const BroadcastsPage: NextPage = () => {
210226 const ongoingRounds = broadcast . rounds . filter (
211227 ( r ) => r . ongoing ,
212228 )
229+ const startedRounds = broadcast . rounds . filter (
230+ ( r ) => r . startsAt <= Date . now ( ) ,
231+ )
213232 const hasOngoingRounds = ongoingRounds . length > 0
233+ const hasStartedRounds = startedRounds . length > 0
214234 const isActive =
215235 section . type . includes ( 'active' ) ||
216236 section . type . includes ( 'community' )
@@ -272,18 +292,18 @@ const BroadcastsPage: NextPage = () => {
272292
273293 < button
274294 onClick = { ( ) => handleSelectBroadcast ( broadcast ) }
275- disabled = { ! hasOngoingRounds && ! isPast }
295+ disabled = { ! hasStartedRounds && ! isPast }
276296 className = { `border-t py-2 text-sm font-medium tracking-wide transition-all duration-300 ${
277297 hasOngoingRounds
278298 ? 'border-red-500/30 bg-red-500/20 text-red-400 group-hover:bg-red-500/30'
279- : isPast
299+ : hasStartedRounds || isPast
280300 ? 'border-glass-border bg-white/5 text-white/60 group-hover:bg-white/10 group-hover:text-white/80'
281301 : 'cursor-not-allowed border-glass-border bg-white/5 text-white/40'
282302 } `}
283303 >
284304 { hasOngoingRounds
285305 ? 'Watch Live'
286- : isPast
306+ : hasStartedRounds || isPast
287307 ? 'View Tournament'
288308 : 'Coming Soon' }
289309 </ button >
0 commit comments