🔍 one Turkish-aware filter behind every search box
Browse files at this commit52bbe313ef0317ed7a839068a30e129119f32d00Parent: ce4dc54- refactor
- 🔍 one Turkish-aware filter behind every search box
21 changed files +229 -45
- src/components/classes/blueprint-panel.tsx +3 -2
- src/components/layout/command-palette.tsx +3 -4
- src/components/ui/data-table-search.tsx +10 -2
- src/components/ui/searchable-select.test.tsx +45 -0
- src/components/ui/searchable-select.tsx +27 -4
- src/components/users/user-search-select.tsx +5 -0
- src/components/users/user-table.tsx +2 -4
- src/lib/search-text.test.ts +50 -0
- src/lib/search-text.ts +40 -0
- src/pages/classes-page.tsx +3 -2
- src/pages/courses-page.tsx +3 -6
- src/pages/dashboard-page.tsx +2 -1
- src/pages/events-page.tsx +9 -4
- src/pages/exams-page.tsx +9 -4
- src/pages/messages-page.tsx +3 -2
- src/pages/payments-page.tsx +4 -4
- src/pages/staff-work-page.tsx +2 -1
- src/pages/student-attendance-page.tsx +2 -1
- src/pages/student-marks-page.tsx +2 -1
- src/pages/student-pomodoro-page.tsx +2 -1
- src/pages/whiteboards-page.tsx +3 -2
src/components/classes/blueprint-panel.tsxmodified+3 -2
| @@ -11,6 +11,7 @@ import { Input } from "@/components/ui/input"; | ||
| 11 | 11 | import { Label } from "@/components/ui/label"; |
| 12 | 12 | import { SidePanel } from "@/components/ui/side-panel"; |
| 13 | 13 | import { courseKindLabel } from "@/lib/course-kind"; |
| 14 | +import { matchesSearch } from "@/lib/search-text"; | |
| 14 | 15 | import { useT } from "@/stores/preferences-context"; |
| 15 | 16 | |
| 16 | 17 | export function BlueprintPanel(props: { |
| @@ -47,9 +48,9 @@ export function BlueprintPanel(props: { | ||
| 47 | 48 | }); |
| 48 | 49 | |
| 49 | 50 | const visibleCourses = createMemo(() => { |
| 50 | - const q = filter().trim().toLocaleLowerCase("tr-TR"); | |
| 51 | + const q = filter().trim(); | |
| 51 | 52 | if (!q) return props.courses; |
| 52 | - return props.courses.filter((c) => c.title.toLocaleLowerCase("tr-TR").includes(q)); | |
| 53 | + return props.courses.filter((c) => matchesSearch(q, c.title)); | |
| 53 | 54 | }); |
| 54 | 55 | |
| 55 | 56 | const isSelected = (id: string) => selected().includes(id); |
src/components/layout/command-palette.tsxmodified+3 -4
| @@ -26,6 +26,7 @@ import { useAuth } from "@/stores/auth-context"; | ||
| 26 | 26 | import { useModules } from "@/stores/modules-context"; |
| 27 | 27 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 28 | 28 | import { cn } from "@/lib/cn"; |
| 29 | +import { matchesSearch } from "@/lib/search-text"; | |
| 29 | 30 | |
| 30 | 31 | export type CommandPaletteProps = { |
| 31 | 32 | open: boolean; |
| @@ -289,7 +290,7 @@ export function CommandPalette(props: CommandPaletteProps) { | ||
| 289 | 290 | }); |
| 290 | 291 | |
| 291 | 292 | const filteredItems = createMemo(() => { |
| 292 | - const q = query().trim().toLocaleLowerCase(prefs.locale()); | |
| 293 | + const q = query().trim(); | |
| 293 | 294 | if (!q) return items(); |
| 294 | 295 | const peopleLabel = t("command.group.people"); |
| 295 | 296 | const found: CommandItem[] = (people.latest?.items ?? []).map((person) => ({ |
| @@ -302,9 +303,7 @@ export function CommandPalette(props: CommandPaletteProps) { | ||
| 302 | 303 | onSelect: () => void navigate({ to: "/admin/users/$id", params: { id: person.id } }), |
| 303 | 304 | })); |
| 304 | 305 | return [...found, ...items().filter((item) => |
| 305 | - `${item.title} ${item.description ?? ""} ${item.keywords ?? ""} ${item.categoryLabel}` | |
| 306 | - .toLocaleLowerCase(prefs.locale()) | |
| 307 | - .includes(q), | |
| 306 | + matchesSearch(q, item.title, item.description, item.keywords, item.categoryLabel), | |
| 308 | 307 | )]; |
| 309 | 308 | }); |
| 310 | 309 |
src/components/ui/data-table-search.tsxmodified+10 -2
| @@ -18,8 +18,8 @@ export type DataTableSearchProps = { | ||
| 18 | 18 | class?: string; |
| 19 | 19 | }; |
| 20 | 20 | |
| 21 | -/** Rounded search field: leading icon, conditional clear (X) button, and an | |
| 22 | - * optional on-focus hint naming the fields it searches. */ | |
| 21 | +/** Rounded search field: leading icon, conditional clear (X) button, Escape to | |
| 22 | + * empty it, and an optional on-focus hint naming the fields it searches. */ | |
| 23 | 23 | export function DataTableSearch(props: DataTableSearchProps) { |
| 24 | 24 | const t = useT(); |
| 25 | 25 | const [focused, setFocused] = createSignal(false); |
| @@ -34,6 +34,14 @@ export function DataTableSearch(props: DataTableSearchProps) { | ||
| 34 | 34 | <Input |
| 35 | 35 | value={props.value} |
| 36 | 36 | onInput={(event) => props.onChange(event.currentTarget.value)} |
| 37 | + // Escape empties the box instead of only blurring it: a filter the | |
| 38 | + // keyboard cannot undo leaves the list silently narrowed. | |
| 39 | + onKeyDown={(event: KeyboardEvent) => { | |
| 40 | + if (event.key !== "Escape" || !props.value) return; | |
| 41 | + event.preventDefault(); | |
| 42 | + event.stopPropagation(); | |
| 43 | + props.onChange(""); | |
| 44 | + }} | |
| 37 | 45 | placeholder={props.placeholder ?? t("common.search")} |
| 38 | 46 | aria-describedby={props.hint ? hintId : undefined} |
| 39 | 47 | class={cn("h-8 rounded-lg bg-muted/40 text-[13px] md:text-[13px]", props.value ? "pl-9 pr-8" : "pl-9")} |
src/components/ui/searchable-select.test.tsxadded+45 -0
| @@ -0,0 +1,45 @@ | ||
| 1 | +import { cleanup, fireEvent, render, screen, waitFor } from "@solidjs/testing-library"; | |
| 2 | +import { afterEach, expect, it, vi } from "vitest"; | |
| 3 | +import { SearchableSelect } from "@/components/ui/searchable-select"; | |
| 4 | +import { PreferencesProvider } from "@/stores/preferences-context"; | |
| 5 | + | |
| 6 | +const OPTIONS = [ | |
| 7 | + { value: "m", label: "9-A · Matematik" }, | |
| 8 | + { value: "t", label: "10-B · Türkçe" }, | |
| 9 | +]; | |
| 10 | + | |
| 11 | +afterEach(cleanup); | |
| 12 | + | |
| 13 | +function renderSelect(onChange = vi.fn()) { | |
| 14 | + render(() => ( | |
| 15 | + <PreferencesProvider> | |
| 16 | + <SearchableSelect value="" onChange={onChange} options={OPTIONS} placeholder="Seç" /> | |
| 17 | + </PreferencesProvider> | |
| 18 | + )); | |
| 19 | + return { input: screen.getByRole("combobox"), onChange }; | |
| 20 | +} | |
| 21 | + | |
| 22 | +it("finds an option across a dash and word order", async () => { | |
| 23 | + const { input } = renderSelect(); | |
| 24 | + | |
| 25 | + fireEvent.input(input, { target: { value: "9a matematik" } }); | |
| 26 | + | |
| 27 | + await waitFor(() => expect(screen.getByRole("option", { name: "9-A · Matematik" })).toBeTruthy()); | |
| 28 | + expect(screen.queryByRole("option", { name: "10-B · Türkçe" })).toBeNull(); | |
| 29 | +}); | |
| 30 | + | |
| 31 | +it("finds an option typed without its Turkish diacritics", async () => { | |
| 32 | + const { input } = renderSelect(); | |
| 33 | + | |
| 34 | + fireEvent.input(input, { target: { value: "turkce" } }); | |
| 35 | + | |
| 36 | + await waitFor(() => expect(screen.getByRole("option", { name: "10-B · Türkçe" })).toBeTruthy()); | |
| 37 | +}); | |
| 38 | + | |
| 39 | +it("says so when the search matches nothing", async () => { | |
| 40 | + const { input } = renderSelect(); | |
| 41 | + | |
| 42 | + fireEvent.input(input, { target: { value: "fizik" } }); | |
| 43 | + | |
| 44 | + await waitFor(() => expect(screen.getByText("No results.")).toBeTruthy()); | |
| 45 | +}); |
src/components/ui/searchable-select.tsxmodified+27 -4
| @@ -1,4 +1,4 @@ | ||
| 1 | -import { createMemo } from "solid-js"; | |
| 1 | +import { Show, createMemo, createSignal } from "solid-js"; | |
| 2 | 2 | import { |
| 3 | 3 | Combobox, |
| 4 | 4 | ComboboxContent, |
| @@ -9,13 +9,16 @@ import { | ||
| 9 | 9 | ComboboxItemLabel, |
| 10 | 10 | ComboboxTrigger, |
| 11 | 11 | } from "@/components/ui/combobox"; |
| 12 | +import { matchesSearch } from "@/lib/search-text"; | |
| 13 | +import { useT } from "@/stores/preferences-context"; | |
| 12 | 14 | |
| 13 | 15 | export type SearchableOption = { value: string; label: string }; |
| 14 | 16 | |
| 15 | 17 | /** |
| 16 | 18 | * Type-to-filter dropdown over a preloaded option list. Kobalte handles |
| 17 | - * filtering, keyboard nav, ARIA and highlight. Drop-in for a native `<Select>` | |
| 18 | - * when the list is long enough to warrant search (> ~7 options). | |
| 19 | + * keyboard nav, ARIA and highlight; the filter is ours so that typing | |
| 20 | + * "9a matematik" finds "9-A · Matematik" — Kobalte's own "contains" is a raw | |
| 21 | + * substring test and misses both the dash and the word order. | |
| 19 | 22 | */ |
| 20 | 23 | export function SearchableSelect(props: { |
| 21 | 24 | id?: string; |
| @@ -28,12 +31,28 @@ export function SearchableSelect(props: { | ||
| 28 | 31 | required?: boolean; |
| 29 | 32 | class?: string; |
| 30 | 33 | }) { |
| 34 | + const t = useT(); | |
| 35 | + const [query, setQuery] = createSignal(""); | |
| 31 | 36 | const selected = createMemo(() => props.options.find((o) => o.value === props.value) ?? null); |
| 37 | + const filter = (option: SearchableOption, input: string) => matchesSearch(input, option.label); | |
| 38 | + // Kobalte renders nothing when its filter keeps no option, which reads as a | |
| 39 | + // broken dropdown; this says the search came up empty instead. | |
| 40 | + const empty = createMemo(() => { | |
| 41 | + const input = query().trim(); | |
| 42 | + if (!input || input === selected()?.label) return false; | |
| 43 | + return !props.options.some((option) => filter(option, input)); | |
| 44 | + }); | |
| 45 | + | |
| 32 | 46 | return ( |
| 33 | 47 | <Combobox<SearchableOption> |
| 34 | 48 | options={props.options} |
| 35 | 49 | value={selected()} |
| 36 | 50 | onChange={(option) => props.onChange(option?.value ?? "")} |
| 51 | + onInputChange={setQuery} | |
| 52 | + defaultFilter={filter} | |
| 53 | + // Without this Kobalte closes the popover when its filter keeps nothing, | |
| 54 | + // so the "no results" line below would never get a chance to render. | |
| 55 | + allowsEmptyCollection | |
| 37 | 56 | optionValue="value" |
| 38 | 57 | optionLabel="label" |
| 39 | 58 | optionTextValue="label" |
| @@ -52,7 +71,11 @@ export function SearchableSelect(props: { | ||
| 52 | 71 | <ComboboxTrigger /> |
| 53 | 72 | </ComboboxControl> |
| 54 | 73 | <ComboboxHiddenSelect /> |
| 55 | - <ComboboxContent /> | |
| 74 | + <ComboboxContent> | |
| 75 | + <Show when={empty()}> | |
| 76 | + <p class="px-2.5 py-2 text-xs text-muted-foreground">{t("common.noResults")}</p> | |
| 77 | + </Show> | |
| 78 | + </ComboboxContent> | |
| 56 | 79 | </Combobox> |
| 57 | 80 | ); |
| 58 | 81 | } |
src/components/users/user-search-select.tsxmodified+5 -0
| @@ -171,6 +171,11 @@ export function UserSearchSelect(props: { | ||
| 171 | 171 | <ComboboxTrigger /> |
| 172 | 172 | </ComboboxControl> |
| 173 | 173 | <ComboboxContent> |
| 174 | + {/* The debounce plus the request leave the panel blank for a moment, | |
| 175 | + which reads as "nothing matches" before the search even ran. */} | |
| 176 | + <Show when={loading() && options().length === 0}> | |
| 177 | + <p class="px-2 py-2 text-xs text-muted-foreground">{t("common.loading")}</p> | |
| 178 | + </Show> | |
| 174 | 179 | <Show when={emptyText()}> |
| 175 | 180 | <p class="px-2 py-2 text-xs font-medium text-destructive">{emptyText()}</p> |
| 176 | 181 | </Show> |
src/components/users/user-table.tsxmodified+2 -4
| @@ -10,6 +10,7 @@ import { DataTable } from "@/components/ui/data-table"; | ||
| 10 | 10 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 11 | 11 | import { IconCheck, IconExternalLink, IconEye, IconUsers } from "@/components/ui/icons"; |
| 12 | 12 | import { ROLES } from "@/lib/roles"; |
| 13 | +import { matchesSearch } from "@/lib/search-text"; | |
| 13 | 14 | import { useT } from "@/stores/preferences-context"; |
| 14 | 15 | |
| 15 | 16 | function displayName(user: User): string { |
| @@ -77,10 +78,7 @@ export function UserTable(props: { | ||
| 77 | 78 | const t = useT(); |
| 78 | 79 | const navigate = useNavigate(); |
| 79 | 80 | const searchUser = (user: User, query: string) => |
| 80 | - [user.username, displayName(user), user.email, user.id, t(`role.${user.role}` as MessageKey)] | |
| 81 | - .join(" ") | |
| 82 | - .toLocaleLowerCase() | |
| 83 | - .includes(query.toLocaleLowerCase()); | |
| 81 | + matchesSearch(query, user.username, displayName(user), user.email, t(`role.${user.role}` as MessageKey)); | |
| 84 | 82 | const columns = createMemo<ColumnDef<User>[]>(() => [ |
| 85 | 83 | { |
| 86 | 84 | accessorKey: "username", |
src/lib/search-text.test.tsadded+50 -0
| @@ -0,0 +1,50 @@ | ||
| 1 | +import { describe, expect, it } from "vitest"; | |
| 2 | +import { foldSearchText, matchesSearch } from "@/lib/search-text"; | |
| 3 | + | |
| 4 | +describe("foldSearchText", () => { | |
| 5 | + it("folds Turkish letters onto their ASCII shape", () => { | |
| 6 | + expect(foldSearchText("Öğretmen ŞİŞLİ çığ")).toBe("ogretmen sisli cig"); | |
| 7 | + }); | |
| 8 | + | |
| 9 | + it("folds the dotted capital I the way a Turkish reader expects", () => { | |
| 10 | + expect(foldSearchText("İSTANBUL")).toBe("istanbul"); | |
| 11 | + expect(foldSearchText("Iğdır")).toBe("igdir"); | |
| 12 | + }); | |
| 13 | + | |
| 14 | + it("drops combining marks it has no explicit rule for", () => { | |
| 15 | + expect(foldSearchText("José Núñez")).toBe("jose nunez"); | |
| 16 | + }); | |
| 17 | + | |
| 18 | + it("drops punctuation so a typed class matches the printed one", () => { | |
| 19 | + expect(foldSearchText("9-A")).toBe("9a"); | |
| 20 | + expect(foldSearchText("ali.veli_1")).toBe("aliveli1"); | |
| 21 | + }); | |
| 22 | + | |
| 23 | + it("treats empty input as an empty string", () => { | |
| 24 | + expect(foldSearchText(null)).toBe(""); | |
| 25 | + expect(foldSearchText(undefined)).toBe(""); | |
| 26 | + }); | |
| 27 | +}); | |
| 28 | + | |
| 29 | +describe("matchesSearch", () => { | |
| 30 | + it("matches across diacritics in both directions", () => { | |
| 31 | + expect(matchesSearch("ogretmen", "Öğretmen Ayşe")).toBe(true); | |
| 32 | + expect(matchesSearch("Öğretmen", "ogretmen ayse")).toBe(true); | |
| 33 | + }); | |
| 34 | + | |
| 35 | + it("requires every term but not their order", () => { | |
| 36 | + expect(matchesSearch("ayse 9a", "Ayşe Yılmaz", "9-A")).toBe(true); | |
| 37 | + expect(matchesSearch("9a ayse", "Ayşe Yılmaz", "9-A")).toBe(true); | |
| 38 | + expect(matchesSearch("ayse 10b", "Ayşe Yılmaz", "9-A")).toBe(false); | |
| 39 | + }); | |
| 40 | + | |
| 41 | + it("ignores stray whitespace and empty queries", () => { | |
| 42 | + expect(matchesSearch(" ", "anything")).toBe(true); | |
| 43 | + expect(matchesSearch(" ayse yilmaz ", "Ayşe Yılmaz")).toBe(true); | |
| 44 | + }); | |
| 45 | + | |
| 46 | + it("skips fields with no value instead of matching on them", () => { | |
| 47 | + expect(matchesSearch("ayse", null, undefined, "Ayşe")).toBe(true); | |
| 48 | + expect(matchesSearch("ayse", null, undefined)).toBe(false); | |
| 49 | + }); | |
| 50 | +}); |
src/lib/search-text.tsadded+40 -0
| @@ -0,0 +1,40 @@ | ||
| 1 | +// Turkish search folding. Every list filter in the app used | |
| 2 | +// `toLocaleLowerCase().includes(...)`, which made a search box feel broken the | |
| 3 | +// moment the typed text skipped a diacritic: "ogretmen" missed "Öğretmen", | |
| 4 | +// "sinav" missed "sınav", and an "İ" pasted from Word matched nothing. | |
| 5 | +const FOLD: Record<string, string> = { | |
| 6 | + ı: "i", İ: "i", ş: "s", Ş: "s", ğ: "g", Ğ: "g", | |
| 7 | + ü: "u", Ü: "u", ö: "o", Ö: "o", ç: "c", Ç: "c", | |
| 8 | + â: "a", Â: "a", î: "i", Î: "i", û: "u", Û: "u", | |
| 9 | +}; | |
| 10 | + | |
| 11 | +/** | |
| 12 | + * Case-, diacritic- and punctuation-insensitive form of a string, for | |
| 13 | + * comparison only. Punctuation goes because a class reads "9-A" on screen and | |
| 14 | + * nobody types the dash: folding both sides to "9a" is what makes the box feel | |
| 15 | + * like it works. | |
| 16 | + */ | |
| 17 | +export function foldSearchText(value: string | null | undefined): string { | |
| 18 | + if (!value) return ""; | |
| 19 | + let folded = ""; | |
| 20 | + for (const char of value) folded += FOLD[char] ?? char; | |
| 21 | + // Anything the table above misses (accented Latin pasted from elsewhere) | |
| 22 | + // loses its combining marks here. | |
| 23 | + return folded | |
| 24 | + .toLowerCase() | |
| 25 | + .normalize("NFD") | |
| 26 | + .replace(/\p{Diacritic}/gu, "") | |
| 27 | + .replace(/[^\p{L}\p{N}\s]+/gu, ""); | |
| 28 | +} | |
| 29 | + | |
| 30 | +/** | |
| 31 | + * Whether every term in `query` appears in one of `fields`, in any order — so | |
| 32 | + * "ali 9a" finds Ali in class 9-A, and a stray double space does not empty the | |
| 33 | + * list. An empty query matches everything, which is what a filter should do. | |
| 34 | + */ | |
| 35 | +export function matchesSearch(query: string, ...fields: (string | null | undefined)[]): boolean { | |
| 36 | + const terms = foldSearchText(query).split(/\s+/).filter(Boolean); | |
| 37 | + if (terms.length === 0) return true; | |
| 38 | + const haystack = fields.map(foldSearchText).join(" "); | |
| 39 | + return terms.every((term) => haystack.includes(term)); | |
| 40 | +} |
src/pages/classes-page.tsxmodified+3 -2
| @@ -23,6 +23,7 @@ import { BlueprintsTab } from "@/components/classes/blueprints-tab"; | ||
| 23 | 23 | import { ComingSoonBadge, ComingSoonValue } from "@/components/ui/coming-soon"; |
| 24 | 24 | import { UserSearchSelect } from "@/components/users/user-search-select"; |
| 25 | 25 | import { createFlash } from "@/lib/flash"; |
| 26 | +import { matchesSearch } from "@/lib/search-text"; | |
| 26 | 27 | import { personLabel } from "@/lib/person"; |
| 27 | 28 | import { hasMinRole } from "@/lib/roles"; |
| 28 | 29 | import { useAuth } from "@/stores/auth-context"; |
| @@ -79,10 +80,10 @@ function ClassesContent() { | ||
| 79 | 80 | }); |
| 80 | 81 | |
| 81 | 82 | const searched = createMemo(() => { |
| 82 | - const needle = query().trim().toLocaleLowerCase("tr"); | |
| 83 | + const needle = query().trim(); | |
| 83 | 84 | if (!needle) return gradeFiltered(); |
| 84 | 85 | return gradeFiltered().filter((cls) => |
| 85 | - [cls.name, cls.grade ?? "", cls.teacher ? personLabel(cls.teacher) : ""].join(" ").toLocaleLowerCase("tr").includes(needle), | |
| 86 | + matchesSearch(needle, cls.name, cls.grade, cls.teacher ? personLabel(cls.teacher) : null), | |
| 86 | 87 | ); |
| 87 | 88 | }); |
| 88 | 89 |
src/pages/courses-page.tsxmodified+3 -6
| @@ -24,6 +24,7 @@ import { SidePanel } from "@/components/ui/side-panel"; | ||
| 24 | 24 | import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; |
| 25 | 25 | import { Textarea } from "@/components/ui/textarea"; |
| 26 | 26 | import { createFlash } from "@/lib/flash"; |
| 27 | +import { matchesSearch } from "@/lib/search-text"; | |
| 27 | 28 | import { personLabel } from "@/lib/person"; |
| 28 | 29 | import { hasMinRole } from "@/lib/roles"; |
| 29 | 30 | import { useAuth } from "@/stores/auth-context"; |
| @@ -79,17 +80,13 @@ function CoursesContent() { | ||
| 79 | 80 | ); |
| 80 | 81 | const listData = () => list.latest ?? list(); |
| 81 | 82 | const filteredCourses = createMemo(() => { |
| 82 | - const query = search().trim().toLocaleLowerCase(); | |
| 83 | + const query = search().trim(); | |
| 83 | 84 | return (listData()?.items ?? []).filter((course) => { |
| 84 | 85 | if (pageKind() && course.kind !== pageKind()) return false; |
| 85 | 86 | if (taughtFilter() === "untaught" && course.class_course_count > 0) return false; |
| 86 | 87 | if (taughtFilter() === "taught" && course.class_course_count === 0) return false; |
| 87 | 88 | if (!query) return true; |
| 88 | - return [ | |
| 89 | - course.title, | |
| 90 | - course.description, | |
| 91 | - personLabel(course.creator), | |
| 92 | - ].join(" ").toLocaleLowerCase().includes(query); | |
| 89 | + return matchesSearch(query, course.title, course.description, personLabel(course.creator)); | |
| 93 | 90 | }); |
| 94 | 91 | }); |
| 95 | 92 | const totalPages = createMemo(() => Math.max(1, Math.ceil(filteredCourses().length / PAGE_SIZE))); |
src/pages/dashboard-page.tsxmodified+2 -1
| @@ -48,6 +48,7 @@ import type { MessageKey } from "@/i18n/messages"; | ||
| 48 | 48 | import { cn } from "@/lib/cn"; |
| 49 | 49 | import { formatDateTime } from "@/lib/format"; |
| 50 | 50 | import { formatTry } from "@/lib/meals"; |
| 51 | +import { matchesSearch } from "@/lib/search-text"; | |
| 51 | 52 | import { personLabel } from "@/lib/person"; |
| 52 | 53 | import { packageLabel } from "@/lib/module-labels"; |
| 53 | 54 | import { hasMinRole } from "@/lib/roles"; |
| @@ -632,7 +633,7 @@ function DashboardContent() { | ||
| 632 | 633 | }, |
| 633 | 634 | ]); |
| 634 | 635 | |
| 635 | - const deadlineSearch = (row: DeadlineRow, q: string) => row.title.toLowerCase().includes(q.toLowerCase()); | |
| 636 | + const deadlineSearch = (row: DeadlineRow, q: string) => matchesSearch(q, row.title); | |
| 636 | 637 | const openDeadline = (row: DeadlineRow) => { |
| 637 | 638 | switch (row.kind) { |
| 638 | 639 | case "exam": |
src/pages/events-page.tsxmodified+9 -4
| @@ -21,6 +21,7 @@ import { createNow } from "@/lib/create-now"; | ||
| 21 | 21 | import { createFlash } from "@/lib/flash"; |
| 22 | 22 | import { formatDateTime } from "@/lib/format"; |
| 23 | 23 | import { hasMinRole } from "@/lib/roles"; |
| 24 | +import { matchesSearch } from "@/lib/search-text"; | |
| 24 | 25 | import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status"; |
| 25 | 26 | import { useAuth } from "@/stores/auth-context"; |
| 26 | 27 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| @@ -79,10 +80,14 @@ function EventsContent() { | ||
| 79 | 80 | return t("events.audience.registration"); |
| 80 | 81 | }; |
| 81 | 82 | const searchEvent = (event: Event, query: string) => |
| 82 | - [event.title, event.description, audienceLabel(event.audience), formatDateTime(event.starts_at, locale()), formatDateTime(event.ends_at, locale())] | |
| 83 | - .join(" ") | |
| 84 | - .toLocaleLowerCase(locale()) | |
| 85 | - .includes(query.toLocaleLowerCase(locale())); | |
| 83 | + matchesSearch( | |
| 84 | + query, | |
| 85 | + event.title, | |
| 86 | + event.description, | |
| 87 | + audienceLabel(event.audience), | |
| 88 | + formatDateTime(event.starts_at, locale()), | |
| 89 | + formatDateTime(event.ends_at, locale()), | |
| 90 | + ); | |
| 86 | 91 | const columns = createMemo<ColumnDef<Event>[]>(() => [ |
| 87 | 92 | { |
| 88 | 93 | accessorKey: "title", |
src/pages/exams-page.tsxmodified+9 -4
| @@ -29,6 +29,7 @@ import { examDisplayStatus, examStatusMessageKey, examStatusTone, type ExamDispl | ||
| 29 | 29 | import { createFlash } from "@/lib/flash"; |
| 30 | 30 | import { formatDateTime } from "@/lib/format"; |
| 31 | 31 | import { hasMinRole } from "@/lib/roles"; |
| 32 | +import { matchesSearch } from "@/lib/search-text"; | |
| 32 | 33 | import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status"; |
| 33 | 34 | import { cn } from "@/lib/cn"; |
| 34 | 35 | import { useAuth } from "@/stores/auth-context"; |
| @@ -118,10 +119,14 @@ function ExamsContent() { | ||
| 118 | 119 | }); |
| 119 | 120 | }; |
| 120 | 121 | const searchExam = (exam: ExamRow, query: string) => |
| 121 | - [exam.title, exam.description, courseTitle(exam.class_course), examKindLabel(String(exam.kind), t), statusLabel(exam.displayStatus)] | |
| 122 | - .join(" ") | |
| 123 | - .toLocaleLowerCase(locale()) | |
| 124 | - .includes(query.toLocaleLowerCase(locale())); | |
| 122 | + matchesSearch( | |
| 123 | + query, | |
| 124 | + exam.title, | |
| 125 | + exam.description, | |
| 126 | + courseTitle(exam.class_course), | |
| 127 | + examKindLabel(String(exam.kind), t), | |
| 128 | + statusLabel(exam.displayStatus), | |
| 129 | + ); | |
| 125 | 130 | |
| 126 | 131 | const [list, { refetch: refetchExams }] = createResource( |
| 127 | 132 | () => { |
src/pages/messages-page.tsxmodified+3 -2
| @@ -33,6 +33,7 @@ import type { Message, MessageFolder } from "@/api/client"; | ||
| 33 | 33 | import { formatApiError } from "@/api/client"; |
| 34 | 34 | import { useAuth } from "@/stores/auth-context"; |
| 35 | 35 | import { useT } from "@/stores/preferences-context"; |
| 36 | +import { matchesSearch } from "@/lib/search-text"; | |
| 36 | 37 | import { personLabel } from "@/lib/person"; |
| 37 | 38 | import { createFlash } from "@/lib/flash"; |
| 38 | 39 | import { Badge } from "@/components/ui/badge"; |
| @@ -72,13 +73,13 @@ export default function MessagesPage() { | ||
| 72 | 73 | ); |
| 73 | 74 | |
| 74 | 75 | const filtered = createMemo(() => { |
| 75 | - const q = query().trim().toLocaleLowerCase(); | |
| 76 | + const q = query().trim(); | |
| 76 | 77 | if (!q) return messages(); |
| 77 | 78 | return messages().filter((m) => { |
| 78 | 79 | const isSent = folder() === "sent" || m.sender.id === auth.user()?.id; |
| 79 | 80 | const peer = isSent ? m.recipient : m.sender; |
| 80 | 81 | const other = personLabel(peer); |
| 81 | - return [other, m.subject, m.body, m.label || ""].join(" ").toLocaleLowerCase().includes(q); | |
| 82 | + return matchesSearch(q, other, m.subject, m.body, m.label); | |
| 82 | 83 | }); |
| 83 | 84 | }); |
| 84 | 85 |
src/pages/payments-page.tsxmodified+4 -4
| @@ -46,6 +46,7 @@ import { createFlash } from "@/lib/flash"; | ||
| 46 | 46 | import { formatDate, formatDateTime } from "@/lib/format"; |
| 47 | 47 | import { formatTry } from "@/lib/meals"; |
| 48 | 48 | import { PAYMENT_METHOD_KEYS, sortStatementEntries, statementStatus } from "@/lib/payments"; |
| 49 | +import { matchesSearch } from "@/lib/search-text"; | |
| 49 | 50 | import { personLabel } from "@/lib/person"; |
| 50 | 51 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 51 | 52 | |
| @@ -133,14 +134,13 @@ function PaymentsContent() { | ||
| 133 | 134 | // (already name-resolved) plan roster and filters/pages it client-side — |
| 134 | 135 | // a plan's assignees are a small, bounded list on their own. |
| 135 | 136 | const [studentsPage, { refetch: refetchStudents }] = createResource( |
| 136 | - () => ({ plan: planFilter(), q: debouncedQuery(), page: studentPage(), size: studentPageSize(), loc: locale() }), | |
| 137 | - async ({ plan, q, page, size, loc }): Promise<{ items: PersonRef[]; total: number }> => { | |
| 137 | + () => ({ plan: planFilter(), q: debouncedQuery(), page: studentPage(), size: studentPageSize() }), | |
| 138 | + async ({ plan, q, page, size }): Promise<{ items: PersonRef[]; total: number }> => { | |
| 138 | 139 | if (plan) { |
| 139 | 140 | const assignments = await getPlanAssignments(plan, { limit: 500 }); |
| 140 | - const needle = q.toLocaleLowerCase(loc); | |
| 141 | 141 | const all = assignments.items |
| 142 | 142 | .map((row) => row.student) |
| 143 | - .filter((user) => !needle || [personLabel(user), user.username, user.id].join(" ").toLocaleLowerCase(loc).includes(needle)); | |
| 143 | + .filter((user) => matchesSearch(q, personLabel(user), user.username)); | |
| 144 | 144 | const start = page * size; |
| 145 | 145 | return { items: all.slice(start, start + size), total: all.length }; |
| 146 | 146 | } |
src/pages/staff-work-page.tsxmodified+2 -1
| @@ -28,6 +28,7 @@ import { PaginationControls } from "@/components/ui/pagination-controls"; | ||
| 28 | 28 | import { SidePanel } from "@/components/ui/side-panel"; |
| 29 | 29 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 30 | 30 | import { formatDateTime, formatDurationMinutes } from "@/lib/format"; |
| 31 | +import { matchesSearch } from "@/lib/search-text"; | |
| 31 | 32 | import { personLabel } from "@/lib/person"; |
| 32 | 33 | import { usePreferences, useT } from "@/stores/preferences-context"; |
| 33 | 34 | |
| @@ -149,7 +150,7 @@ function StaffWorkContent() { | ||
| 149 | 150 | const entryRows = () => entries().items; |
| 150 | 151 | const peopleLoading = () => people.loading; |
| 151 | 152 | const searchPerson = (person: PersonRef, query: string) => |
| 152 | - [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); | |
| 153 | + matchesSearch(query, person.username, person.display_name); | |
| 153 | 154 | |
| 154 | 155 | const filteredPeople = createMemo(() => { |
| 155 | 156 | const q = staffSearch().trim(); |
src/pages/student-attendance-page.tsxmodified+2 -1
| @@ -13,6 +13,7 @@ import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 13 | 13 | import { IconEye } from "@/components/ui/icons"; |
| 14 | 14 | import { SidePanel } from "@/components/ui/side-panel"; |
| 15 | 15 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 16 | +import { matchesSearch } from "@/lib/search-text"; | |
| 16 | 17 | import { personLabel } from "@/lib/person"; |
| 17 | 18 | import { useT } from "@/stores/preferences-context"; |
| 18 | 19 | |
| @@ -64,7 +65,7 @@ function StudentAttendanceContent() { | ||
| 64 | 65 | const rows = () => list(); |
| 65 | 66 | const listLoading = () => list.loading; |
| 66 | 67 | const searchPerson = (person: PersonRef, query: string) => |
| 67 | - [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); | |
| 68 | + matchesSearch(query, person.username, person.display_name); | |
| 68 | 69 | const columns = createMemo<ColumnDef<PersonRef>[]>(() => [ |
| 69 | 70 | { |
| 70 | 71 | accessorKey: "username", |
src/pages/student-marks-page.tsxmodified+2 -1
| @@ -14,6 +14,7 @@ import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 14 | 14 | import { IconEye } from "@/components/ui/icons"; |
| 15 | 15 | import { SidePanel } from "@/components/ui/side-panel"; |
| 16 | 16 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 17 | +import { matchesSearch } from "@/lib/search-text"; | |
| 17 | 18 | import { personLabel } from "@/lib/person"; |
| 18 | 19 | import { useT } from "@/stores/preferences-context"; |
| 19 | 20 | |
| @@ -101,7 +102,7 @@ function StudentMarksContent() { | ||
| 101 | 102 | }; |
| 102 | 103 | const listLoading = () => list.loading; |
| 103 | 104 | const searchPerson = (person: PersonRef, query: string) => |
| 104 | - [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); | |
| 105 | + matchesSearch(query, person.username, person.display_name); | |
| 105 | 106 | const columns = createMemo<ColumnDef<PersonRef>[]>(() => [ |
| 106 | 107 | { |
| 107 | 108 | accessorKey: "username", |
src/pages/student-pomodoro-page.tsxmodified+2 -1
| @@ -13,6 +13,7 @@ import { ErrorAlert } from "@/components/ui/error-alert"; | ||
| 13 | 13 | import { IconEye } from "@/components/ui/icons"; |
| 14 | 14 | import { SidePanel } from "@/components/ui/side-panel"; |
| 15 | 15 | import { TableRowActions } from "@/components/ui/table-row-actions"; |
| 16 | +import { matchesSearch } from "@/lib/search-text"; | |
| 16 | 17 | import { personLabel } from "@/lib/person"; |
| 17 | 18 | import { useT } from "@/stores/preferences-context"; |
| 18 | 19 | |
| @@ -64,7 +65,7 @@ function StudentPomodoroContent() { | ||
| 64 | 65 | const rows = () => list(); |
| 65 | 66 | const listLoading = () => list.loading; |
| 66 | 67 | const searchPerson = (person: PersonRef, query: string) => |
| 67 | - [person.username, person.display_name, person.id].join(" ").toLocaleLowerCase().includes(query.toLocaleLowerCase()); | |
| 68 | + matchesSearch(query, person.username, person.display_name); | |
| 68 | 69 | const studentColumns = createMemo<ColumnDef<PersonRef>[]>(() => [ |
| 69 | 70 | { |
| 70 | 71 | accessorKey: "username", |
src/pages/whiteboards-page.tsxmodified+3 -2
| @@ -19,6 +19,7 @@ import { SidePanel } from "@/components/ui/side-panel"; | ||
| 19 | 19 | import { TablePagination } from "@/components/ui/table-pagination"; |
| 20 | 20 | import { cn } from "@/lib/cn"; |
| 21 | 21 | import { formatDate } from "@/lib/format"; |
| 22 | +import { matchesSearch } from "@/lib/search-text"; | |
| 22 | 23 | import { personLabel } from "@/lib/person"; |
| 23 | 24 | import { hasMinRole } from "@/lib/roles"; |
| 24 | 25 | import { useAuth } from "@/stores/auth-context"; |
| @@ -51,9 +52,9 @@ function WhiteboardsContent() { | ||
| 51 | 52 | // only the current page's real titles — a client-side search over real |
| 52 | 53 | // data, not a promise of searching every board the caller has ever opened. |
| 53 | 54 | const visibleBoards = createMemo(() => { |
| 54 | - const q = query().trim().toLocaleLowerCase(); | |
| 55 | + const q = query().trim(); | |
| 55 | 56 | const items = boards()?.items ?? []; |
| 56 | - return q ? items.filter((b) => b.title.toLocaleLowerCase().includes(q)) : items; | |
| 57 | + return q ? items.filter((b) => matchesSearch(q, b.title)) : items; | |
| 57 | 58 | }); |
| 58 | 59 | |
| 59 | 60 | const meId = () => auth.user()?.id ?? ""; |