@@ -32,7 +32,6 @@ function getSessionsByDay(
3232
3333 const states = Object . entries < FilterStates [ keyof FilterStates ] > ( filterStates )
3434 const concurrentSessions : ConcurrentSessions = { }
35- const flatFilteredSessions : ScheduleSession [ ] = [ ]
3635
3736 filteredSortedSchedule . forEach ( session => {
3837 for ( const [ property , filterState ] of states ) {
@@ -47,7 +46,6 @@ function getSessionsByDay(
4746 }
4847 }
4948
50- flatFilteredSessions . push ( session )
5149 ; ( concurrentSessions [ session . event_start ] ||= [ ] ) . push ( session )
5250 } )
5351
@@ -68,14 +66,37 @@ function getSessionsByDay(
6866 return {
6967 sessionsByDay,
7068 enabledOptions : Object . fromEntries (
71- Object . keys ( filterStates ) . map ( field => [
72- field ,
73- new Set (
74- flatFilteredSessions . map ( session =>
75- String ( session [ field as keyof ScheduleSession ] ) ,
76- ) ,
77- ) ,
78- ] ) ,
69+ Object . keys ( filterStates ) . map ( currentField => {
70+ // Apply filters from ALL OTHER fields, not this one
71+ const otherFilters = Object . entries ( filterStates ) . filter (
72+ ( [ field ] ) => field !== currentField ,
73+ )
74+
75+ const filteredData = scheduleData . filter ( session => {
76+ // Check if session passes all OTHER filters
77+ for ( const [ property , filterState ] of otherFilters ) {
78+ const filters = filterState as string [ ]
79+ if (
80+ filters &&
81+ filters . length > 0 &&
82+ ! filters . includes (
83+ session [ property as keyof ScheduleSession ] as string ,
84+ )
85+ ) {
86+ return false
87+ }
88+ }
89+ return true
90+ } )
91+
92+ const enabledOptionsForField = new Set (
93+ filteredData
94+ . map ( session => session [ currentField as keyof ScheduleSession ] )
95+ . filter ( ( x ) : x is string => ! ! x && typeof x === "string" ) ,
96+ )
97+
98+ return [ currentField , enabledOptionsForField ]
99+ } ) ,
79100 ) ,
80101 }
81102}
0 commit comments