@@ -11,8 +11,25 @@ import '@/app/calendar/override-calendar.css'
1111const localizer = momentLocalizer ( moment )
1212
1313// Color palette for events - using disabled variants from global styling
14- const eventColors = [ '#f9aeda' , '#bac0ff' , '#ffdfb1' , '#bac0ff' , '#ffdfb1' ]
15- const getEventColor = ( index : number ) => eventColors [ index % eventColors . length ]
14+ const colorMap = {
15+ pink : '#F9AEDA' ,
16+ blue : '#BAC0FF' ,
17+ yellow : '#F4B860' ,
18+ }
19+
20+ // Hash function to consistently map parent session ID to a color
21+ function hashIdToColor ( id : string | number ) : keyof typeof colorMap {
22+ const colors : Array < keyof typeof colorMap > = [ 'blue' , 'yellow' , 'pink' ]
23+
24+ let hash = 0
25+ const idStr = String ( id )
26+ for ( let i = 0 ; i < idStr . length ; i ++ ) {
27+ hash = ( ( hash << 5 ) - hash ) + idStr . charCodeAt ( i )
28+ hash = hash & hash
29+ }
30+
31+ return colors [ Math . abs ( hash ) % colors . length ]
32+ }
1633
1734interface StudentScheduleProps {
1835 studentId ?: string
@@ -33,17 +50,22 @@ export default function StudentSchedule({ studentId, initialView = 'day', classN
3350 // Always build events array (empty if error or no data)
3451 const events = error
3552 ? [ ]
36- : sessions . map ( ( s , idx ) => {
53+ : sessions . map ( ( s ) => {
3754 // Check if this is from studentHook (nested) or allHook (flat)
3855 const sessionData = studentHook ? ( s as any ) . session : s
56+ const parentId = sessionData . session_parent_id || sessionData . id
57+ const colorKey = hashIdToColor ( parentId )
58+ const backgroundColor = colorMap [ colorKey ]
59+
3960 return {
4061 id : sessionData . id ,
62+ parentId,
4163 title : sessionData . session_name ? sessionData . session_name : 'Session' ,
4264 start : new Date ( sessionData . start_datetime ) ,
4365 end : new Date ( sessionData . end_datetime ) ,
4466 allDay : false ,
4567 resource : {
46- color : getEventColor ( idx ) ,
68+ color : backgroundColor ,
4769 school : ( sessionData as any ) . school || 'School' ,
4870 } ,
4971 }
0 commit comments