Skip to content

Commit 662dae5

Browse files
committed
Improve Filters
1 parent 8d851fa commit 662dae5

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/app/conf/2025/schedule/_components/filters.tsx

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export interface FilterCategoryConfig {
2121
property: keyof ScheduleSession
2222
label: string
2323
options: string[]
24+
enabledOptions?: Set<string>
2425
}
2526

2627
export const FilterCategoryConfig = {
@@ -33,7 +34,11 @@ export const FilterCategoryConfig = {
3334
property: field as keyof ScheduleSession,
3435
label,
3536
options: Array.from(
36-
new Set(scheduleData.map(session => session[field])),
37+
new Set(
38+
scheduleData.map(
39+
session => session[field as keyof ScheduleSession],
40+
),
41+
),
3742
).filter((x): x is string => !!x && typeof x === "string"),
3843
}),
3944
)
@@ -51,12 +56,14 @@ export const FilterStates = {
5156
type FiltersProps = {
5257
categories: FilterCategoryConfig[]
5358
filterState: Record<string, string[]>
59+
enabledOptions: Record<string, Set<string>>
5460
onFilterChange: (category: string, newSelectedOptions: string[]) => void
5561
}
5662

5763
export function Filters({
5864
categories,
5965
filterState,
66+
enabledOptions,
6067
onFilterChange,
6168
}: FiltersProps) {
6269
return (
@@ -66,6 +73,7 @@ export function Filters({
6673
key={category.property}
6774
label={category.label}
6875
options={category.options}
76+
enabledOptions={enabledOptions[category.property]}
6977
value={filterState[category.property] || []}
7078
onChange={newSelectedOptions => {
7179
onFilterChange(category.property, newSelectedOptions)
@@ -109,6 +117,7 @@ export function ResetFiltersButton({
109117
interface FiltersComboboxProps {
110118
label: string
111119
options: string[]
120+
enabledOptions: Set<string>
112121
value: string[]
113122
onChange: (newSelectedOptions: string[]) => void
114123
placeholder: string
@@ -117,6 +126,7 @@ interface FiltersComboboxProps {
117126
function FiltersCombobox({
118127
label,
119128
options,
129+
enabledOptions,
120130
value,
121131
onChange,
122132
placeholder,
@@ -182,7 +192,11 @@ function FiltersCombobox({
182192
)}
183193
>
184194
{filteredOptions.map(option => (
185-
<ComboboxOption key={option} value={option}>
195+
<ComboboxOption
196+
key={option}
197+
value={option}
198+
disabled={!enabledOptions.has(option)}
199+
>
186200
{({ active, selected }) => (
187201
<FilterComboboxOption
188202
active={active}
@@ -248,6 +262,7 @@ function FilterComboboxOption({
248262
className={clsx(
249263
"typography-body-sm relative flex cursor-default select-none items-center p-1 font-sans",
250264
active && "bg-neu-100 dark:bg-neu-50",
265+
"[[data-disabled]_&]:line-through [[data-disabled]_&]:opacity-40",
251266
)}
252267
>
253268
<CheckboxIcon

src/app/conf/2025/schedule/_components/schedule-list.tsx

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ function getSessionsByDay(
3232

3333
const states = Object.entries<FilterStates[keyof FilterStates]>(filterStates)
3434
const concurrentSessions: ConcurrentSessions = {}
35+
const flatFilteredSessions: ScheduleSession[] = []
3536

3637
filteredSortedSchedule.forEach(session => {
3738
for (const [property, filterState] of states) {
@@ -45,6 +46,8 @@ function getSessionsByDay(
4546
return
4647
}
4748
}
49+
50+
flatFilteredSessions.push(session)
4851
;(concurrentSessions[session.event_start] ||= []).push(session)
4952
})
5053

@@ -62,7 +65,19 @@ function getSessionsByDay(
6265
}
6366
})
6467

65-
return sessionsByDay
68+
return {
69+
sessionsByDay,
70+
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+
]),
79+
),
80+
}
6681
}
6782

6883
export interface ScheduleListProps {
@@ -86,7 +101,7 @@ export function ScheduleList({
86101
),
87102
)
88103

89-
const filteredSessions = useMemo(
104+
const { sessionsByDay: filteredSessions, enabledOptions } = useMemo(
90105
() => getSessionsByDay(scheduleData, filtersState),
91106
[scheduleData, filtersState],
92107
)
@@ -109,12 +124,14 @@ export function ScheduleList({
109124
),
110125
)
111126
}
127+
className="max-lg:mb-4 max-lg:w-fit max-lg:self-end"
112128
/>
113129
</div>
114130
{showFilter && (
115131
<Filters
116132
categories={filterCategories}
117133
filterState={filtersState}
134+
enabledOptions={enabledOptions}
118135
onFilterChange={(category, newSelectedOptions) => {
119136
setFiltersState(prev => ({
120137
...prev,

0 commit comments

Comments
 (0)