@@ -8,8 +8,6 @@ import { I18nContext } from '../../models/Translation';
88import { LarkImage } from '../LarkImage' ;
99import styles from './HeroCarousel.module.less' ;
1010
11- export const HERO_CAROUSEL_ITEMS = 3 ;
12-
1311const timestampOf = ( value : unknown ) => {
1412 if ( typeof value === 'number' ) return value ;
1513 if ( typeof value === 'string' ) {
@@ -24,12 +22,12 @@ const timestampOf = (value: unknown) => {
2422const formatDateLabel = ( value : unknown , locale : string ) => {
2523 const timestamp = timestampOf ( value ) ;
2624
27- if ( ! timestamp ) return '' ;
28-
29- return new Intl . DateTimeFormat ( locale , {
30- month : 'short' ,
31- day : 'numeric' ,
32- } ) . format ( timestamp ) ;
25+ return ! timestamp
26+ ? ''
27+ : new Intl . DateTimeFormat ( locale , {
28+ month : 'short' ,
29+ day : 'numeric' ,
30+ } ) . format ( timestamp ) ;
3331} ;
3432
3533const locationTextOf = ( { city, location } : Activity ) =>
@@ -64,26 +62,20 @@ export const HeroCarousel: FC<{ activities: Activity[] }> = ({ activities }) =>
6462 } , [ ] ) ;
6563
6664 useEffect ( ( ) => {
67- const syncDescriptionRows = ( ) => {
68- setDescriptionRows ( window . innerWidth <= 767.98 ? 4 : 3 ) ;
69- } ;
70-
65+ const syncDescriptionRows = ( ) => setDescriptionRows ( window . innerWidth <= 767.98 ? 4 : 3 ) ;
7166 syncDescriptionRows ( ) ;
72- window . addEventListener ( 'resize' , syncDescriptionRows ) ;
7367
74- return ( ) => {
75- window . removeEventListener ( 'resize' , syncDescriptionRows ) ;
76- } ;
77- } , [ ] ) ;
68+ const observer = new ResizeObserver ( syncDescriptionRows ) ;
69+ observer . observe ( document . body ) ;
7870
79- if ( ! activities . length ) return null ;
71+ return ( ) => observer . disconnect ( ) ;
72+ } , [ ] ) ;
8073
8174 return (
8275 < Container
8376 as = "section"
8477 fluid
8578 className = { `${ styles . heroCarousel } position-relative` }
86- aria-label = { t ( 'home_hackathon_top_bar_aria_label' ) }
8779 style = { heroStyle }
8880 >
8981 < Carousel
@@ -96,16 +88,18 @@ export const HeroCarousel: FC<{ activities: Activity[] }> = ({ activities }) =>
9688 className = { `${ styles . carousel } h-100` }
9789 >
9890 { activities . map ( activity => {
91+ const { id, type, name, host, startTime, cardImage } = activity ;
92+
9993 const href = ActivityModel . getLink ( activity ) ;
100- const hosts = ( ( activity . host as string [ ] ) || [ ] ) . slice ( 0 , 2 ) ;
94+ const hosts = ( ( host as string [ ] ) || [ ] ) . slice ( 0 , 2 ) ;
10195 const locationText = locationTextOf ( activity ) ;
102- const dateText = formatDateLabel ( activity . startTime , currentLanguage ) ;
103- const title = ( activity . name as string ) || t ( 'activity' ) ;
96+ const dateText = formatDateLabel ( startTime , currentLanguage ) ;
97+ const title = ( name as string ) || t ( 'activity' ) ;
10498 const description = descriptionOf ( activity ) ;
105- const image = activity . cardImage || activity . image ;
99+ const image = cardImage || activity . image ;
106100
107101 return (
108- < Carousel . Item key = { activity . id as string } className = { `${ styles . item } h-100` } >
102+ < Carousel . Item key = { id as string } className = { `${ styles . item } h-100` } >
109103 < Card
110104 className = { `${ styles . slideCard } h-100 rounded-0 border-0 bg-transparent text-white` }
111105 >
@@ -122,20 +116,19 @@ export const HeroCarousel: FC<{ activities: Activity[] }> = ({ activities }) =>
122116 style = { infoBodyStyle }
123117 >
124118 < Stack direction = "horizontal" gap = { 2 } className = "flex-wrap mb-3 mb-md-4" >
125- { ( hosts . length
126- ? hosts
127- : [ ( activity . type as string ) || t ( 'hackathon' ) ]
128- ) . map ( item => (
129- < Badge
130- key = { item }
131- pill
132- bg = "info"
133- text = "dark"
134- className = "px-3 py-2 fw-semibold"
135- >
136- { item }
137- </ Badge >
138- ) ) }
119+ { ( hosts . length ? hosts : [ ( type as string ) || t ( 'hackathon' ) ] ) . map (
120+ item => (
121+ < Badge
122+ key = { item }
123+ pill
124+ bg = "info"
125+ text = "dark"
126+ className = "px-3 py-2 fw-semibold"
127+ >
128+ { item }
129+ </ Badge >
130+ ) ,
131+ ) }
139132 { ( dateText || t ( 'event_duration' ) ) && (
140133 < Badge pill bg = "light" text = "dark" className = "px-3 py-2 fw-semibold" >
141134 { dateText || t ( 'event_duration' ) }
@@ -171,7 +164,7 @@ export const HeroCarousel: FC<{ activities: Activity[] }> = ({ activities }) =>
171164 variant = "light"
172165 className = { `${ styles . actionButton } px-4 py-2 fw-semibold text-uppercase` }
173166 >
174- { t ( 'home_hackathon_top_bar_action ' ) }
167+ { t ( 'hackathon_register_now ' ) }
175168 </ Button >
176169 </ Stack >
177170 </ Card . Body >
0 commit comments