11import { TableCellValue } from 'mobx-lark' ;
2- import { FC , useEffect , useMemo , useState } from 'react' ;
2+ import { FC } from 'react' ;
33import { Container } from 'react-bootstrap' ;
44
5+ import { Agenda } from '../../../models/Hackathon' ;
56import { LarkImage } from '../../LarkImage' ;
7+ import { AgendaCountdown } from './AgendaCountdown' ;
8+ import { TimeUnit } from '../../Base/Countdown' ;
69import styles from './Hero.module.less' ;
710
811export type HackathonHeroNavItem = Record < 'label' | 'href' , string > ;
@@ -22,13 +25,14 @@ export interface HackathonHeroProps extends Record<
2225 | 'imageFallback' ,
2326 string
2427> {
28+ agendaItems : Agenda [ ] ;
2529 badges : string [ ] ;
2630 bottomCard ?: HackathonHeroCard ;
2731 chips ?: string [ ] ;
28- countdownLabel ?: string ;
29- countdownUnitLabels : string [ ] ;
30- countdownTo ?: string ;
32+ countdownUnits : TimeUnit [ ] ;
33+ endTime ?: TableCellValue ;
3134 image ?: TableCellValue ;
35+ startTime ?: TableCellValue ;
3236 navigation : HackathonHeroNavItem [ ] ;
3337 primaryAction : HackathonHeroAction ;
3438 secondaryAction : HackathonHeroAction ;
@@ -74,38 +78,6 @@ const FloatingCard: FC<{
7478 </ div >
7579) ;
7680
77- const useCountdown = ( countdownTo ?: string ) => {
78- const target = useMemo ( ( ) => {
79- const value = countdownTo ? new Date ( countdownTo ) . getTime ( ) : NaN ;
80-
81- return Number . isFinite ( value ) ? value : NaN ;
82- } , [ countdownTo ] ) ;
83- const [ now , setNow ] = useState < number | null > ( null ) ;
84-
85- useEffect ( ( ) => {
86- if ( ! Number . isFinite ( target ) ) return ;
87-
88- setNow ( Date . now ( ) ) ;
89-
90- const timer = window . setInterval ( ( ) => setNow ( Date . now ( ) ) , 1000 ) ;
91-
92- return ( ) => window . clearInterval ( timer ) ;
93- } , [ target ] ) ;
94-
95- return useMemo ( ( ) => {
96- if ( ! Number . isFinite ( target ) || now === null ) return [ '--' , '--' , '--' , '--' ] ;
97-
98- const rest = Math . max ( 0 , target - now ) ;
99- const totalSeconds = Math . floor ( rest / 1000 ) ;
100- const days = Math . floor ( totalSeconds / 86400 ) ;
101- const hours = Math . floor ( ( totalSeconds % 86400 ) / 3600 ) ;
102- const minutes = Math . floor ( ( totalSeconds % 3600 ) / 60 ) ;
103- const seconds = totalSeconds % 60 ;
104-
105- return [ days , hours , minutes , seconds ] . map ( value => String ( value ) . padStart ( 2 , '0' ) ) ;
106- } , [ now , target ] ) ;
107- } ;
108-
10981const splitHeroTitle = ( name : string , subtitle : string ) => {
11082 const segments = name . split ( / \s + / ) . filter ( Boolean ) ;
11183
@@ -122,28 +94,28 @@ const splitHeroTitle = (name: string, subtitle: string) => {
12294} ;
12395
12496export const HackathonHero : FC < HackathonHeroProps > = ( {
97+ agendaItems,
12598 badges,
12699 bottomCard,
127100 chips,
128- countdownLabel,
129- countdownUnitLabels,
130- countdownTo,
101+ countdownUnits,
131102 description,
103+ endTime,
132104 image,
133105 imageFallback,
134106 locationText,
135107 name,
136108 navigation,
137109 primaryAction,
138110 secondaryAction,
111+ startTime,
139112 subtitle,
140113 topCard,
141114 visualChip,
142115 visualCopy,
143116 visualKicker,
144117 visualTitle,
145118} ) => {
146- const countdown = useCountdown ( countdownTo ) ;
147119 const title = splitHeroTitle ( name , subtitle ) ;
148120
149121 return (
@@ -192,25 +164,12 @@ export const HackathonHero: FC<HackathonHeroProps> = ({
192164
193165 < p className = { styles . description } > { description } </ p >
194166
195- { countdownTo && (
196- < div className = { styles . countdownWrap } >
197- { countdownLabel && (
198- < p className = { `${ styles . countdownLabel } m-0` } > { countdownLabel } </ p >
199- ) }
200-
201- < ol className = { `list-unstyled ${ styles . countdownGrid } m-0` } >
202- { countdown . map ( ( value , index ) => (
203- < li
204- key = { `${ index } -${ countdownUnitLabels [ index ] } ` }
205- className = { `${ styles . countdownCell } d-flex flex-column justify-content-center align-items-center` }
206- >
207- < strong > { value } </ strong >
208- < span > { countdownUnitLabels [ index ] } </ span >
209- </ li >
210- ) ) }
211- </ ol >
212- </ div >
213- ) }
167+ < AgendaCountdown
168+ agendaItems = { agendaItems }
169+ endTime = { endTime }
170+ startTime = { startTime }
171+ units = { countdownUnits }
172+ />
214173
215174 < nav className = "d-flex flex-wrap gap-2 gap-md-3" aria-label = { subtitle } >
216175 < HeroLink action = { primaryAction } variant = "primary" />
0 commit comments