@@ -7,7 +7,11 @@ import type {
77} from "react-big-calendar" ;
88import { Views } from "react-big-calendar" ;
99
10- import type { Event , CalendarEvent , GetCoursesResponse } from "../../util/types" ;
10+ import type {
11+ Event ,
12+ CalendarEvent ,
13+ GetCoursesResponse ,
14+ } from "../../util/types" ;
1115import {
1216 config ,
1317 flattenEventsToBlocks ,
@@ -30,6 +34,30 @@ interface CustomWeekViewProps {
3034
3135type Rect = { left : number ; width : number } ;
3236
37+ function useElementHeight < T extends HTMLElement > (
38+ elementRef : React . RefObject < T | null > ,
39+ ) {
40+ const [ height , setHeight ] = useState ( 0 ) ;
41+
42+ useLayoutEffect ( ( ) => {
43+ const el = elementRef . current ;
44+ if ( ! el ) return ;
45+
46+ const update = ( ) => {
47+ setHeight ( el . getBoundingClientRect ( ) . height ) ;
48+ } ;
49+
50+ update ( ) ;
51+
52+ const ro = new ResizeObserver ( update ) ;
53+ ro . observe ( el ) ;
54+
55+ return ( ) => ro . disconnect ( ) ;
56+ } , [ elementRef ] ) ;
57+
58+ return height ;
59+ }
60+
3361function useAnchorRect < T extends HTMLElement > (
3462 anchorRef : React . RefObject < T | null > ,
3563) {
@@ -103,10 +131,11 @@ function CustomWeekView({
103131 cevent . end . getMonth ( ) ,
104132 cevent . end . getDate ( ) ,
105133 ) ;
106- const differentDate = ( startDay . getFullYear ( ) !== endDay . getFullYear ( )
107- && startDay . getMonth ( ) !== endDay . getMonth ( )
108- && startDay . getDate ( ) !== endDay . getDate ( ) ) ;
109-
134+ const differentDate =
135+ startDay . getFullYear ( ) !== endDay . getFullYear ( ) &&
136+ startDay . getMonth ( ) !== endDay . getMonth ( ) &&
137+ startDay . getDate ( ) !== endDay . getDate ( ) ;
138+
110139 isAllDay = Boolean ( cevent . allDay ) || differentDate || sameMinute ;
111140 }
112141
@@ -166,7 +195,9 @@ function CustomWeekView({
166195 ) ;
167196
168197 const gridRef = useRef < HTMLDivElement > ( null ) ;
198+ const periodLayerRef = useRef < HTMLDivElement > ( null ) ;
169199 const { left, width } = useAnchorRect ( gridRef ) ;
200+ const periodBarHeight = useElementHeight ( periodLayerRef ) ;
170201
171202 return (
172203 < div className = { styles . weekView } >
@@ -179,6 +210,11 @@ function CustomWeekView({
179210 < div
180211 className = { styles . timetableLayer }
181212 data-tour-id = "week-tour-participating-events"
213+ style = {
214+ {
215+ "--period-bar-height" : `${ periodBarHeight } px` ,
216+ } as React . CSSProperties
217+ }
182218 >
183219 < WeekGrid
184220 ref = { gridRef }
@@ -191,6 +227,7 @@ function CustomWeekView({
191227 />
192228 </ div >
193229 < div
230+ ref = { periodLayerRef }
194231 className = { styles . periodLayer }
195232 style = { { left, width } }
196233 data-tour-id = "week-tour-recruiting-events"
0 commit comments