@@ -35,6 +35,26 @@ export function Calendar() {
3535 . flatMap ( ( event ) => event . eventInputs ) ;
3636 } , [ selectedActivities ] ) ;
3737
38+ const getBuildingNumber = ( room : string ) =>
39+ room . split ( "-" ) [ 0 ] . trim ( ) . replace ( / \+ $ / , "" ) ;
40+
41+ /**
42+ * Get the approximate distance (in feet) between two buildings on campus
43+ */
44+ const getDistance = ( building1 : string , building2 : string ) => {
45+ // Get coordinates of each building
46+ const location1 = state . locations . get ( building1 ) ;
47+ const location2 = state . locations . get ( building2 ) ;
48+
49+ if ( ! location1 || ! location2 ) {
50+ return undefined ;
51+ }
52+
53+ const dx = location1 . x - location2 . x ;
54+ const dy = location1 . y - location2 . y ;
55+ return Math . sqrt ( dx * dx + dy * dy ) ;
56+ } ;
57+
3858 /**
3959 * Check if event1 ends at the same time that some other event starts. If
4060 * this is the case and the commute distance between the two events' locations
@@ -55,26 +75,13 @@ export function Calendar() {
5575 continue ;
5676 }
5777
58- // Extract building numbers from room numbers
59- const building1 = room1 . split ( "-" ) [ 0 ] . trim ( ) ;
60- const building2 = event2 . room . split ( "-" ) [ 0 ] . trim ( ) ;
61-
62- // Get coordinates of each building
63- const location1 = state . locations . get ( building1 ) ;
64- const location2 = state . locations . get ( building2 ) ;
65-
66- if ( ! location1 || ! location2 ) {
67- continue ;
68- }
78+ const building1 = getBuildingNumber ( room1 ) ;
79+ const building2 = getBuildingNumber ( event2 . room ) ;
6980
70- // Approximate distance (in feet) between the two buildings using Pythagoras
71- const distance = ( ( ) => {
72- const dx = location1 . x - location2 . x ;
73- const dy = location1 . y - location2 . y ;
74- return Math . sqrt ( dx * dx + dy * dy ) ;
75- } ) ( ) ;
81+ // Approximate distance (in feet) between the two buildings
82+ const distance = getDistance ( building1 , building2 ) ;
7683
77- if ( distance < DISTANCE_WARNING_THRESHOLD ) {
84+ if ( distance === undefined || distance < DISTANCE_WARNING_THRESHOLD ) {
7885 continue ;
7986 }
8087
@@ -111,26 +118,39 @@ export function Calendar() {
111118 const distanceWarning = getDistanceWarning ( event ) ;
112119
113120 return (
114- < Box
115- color = { event . textColor }
116- p = { 0.5 }
117- lineHeight = { 1.3 }
118- cursor = "pointer"
119- height = "100%"
120- position = "relative"
121- >
122- { ! ( activity instanceof CustomActivity ) ? (
123- < Tooltip
124- content = { activity . name }
125- portalled
126- positioning = { { placement : "top" } }
127- >
128- { TitleText ( ) }
129- </ Tooltip >
130- ) : (
131- < TitleText />
132- ) }
133- < Text fontSize = "xs" > { room } </ Text >
121+ < >
122+ < Box
123+ color = { event . textColor }
124+ overflow = "hidden"
125+ p = { 0.5 }
126+ lineHeight = { 1.3 }
127+ cursor = "pointer"
128+ height = "100%"
129+ position = "relative"
130+ >
131+ { ! ( activity instanceof CustomActivity ) ? (
132+ < Tooltip
133+ content = { activity . name }
134+ portalled
135+ positioning = { { placement : "top" } }
136+ >
137+ { TitleText ( ) }
138+ </ Tooltip >
139+ ) : (
140+ < TitleText />
141+ ) }
142+ { event . extendedProps . roomClarification ? (
143+ < Tooltip
144+ content = { event . extendedProps . roomClarification as string }
145+ portalled
146+ positioning = { { placement : "top" } }
147+ >
148+ < Text fontSize = "xs" > { room } </ Text >
149+ </ Tooltip >
150+ ) : (
151+ < Text fontSize = "xs" > { room } </ Text >
152+ ) }
153+ </ Box >
134154 { distanceWarning ? (
135155 < Float placement = "bottom-end" >
136156 < Tooltip
@@ -149,7 +169,7 @@ export function Calendar() {
149169 </ Tooltip >
150170 </ Float >
151171 ) : null }
152- </ Box >
172+ </ >
153173 ) ;
154174 } ;
155175
0 commit comments