forge
Explore
Log in

Don't you dare go Hollow

🔍 one Turkish-aware filter behind every search box

Browse files at this commit

52bbe313ef0317ed7a839068a30e129119f32d00Burak BoduroğluParent: ce4dc54
  • refactor
    • 🔍 one Turkish-aware filter behind every search box
Show full message
refactor: 🔍 one Turkish-aware filter behind every search box
- new src/lib/search-text.ts: fold case, Turkish letters, accents and
  punctuation for comparison, and match every typed term in any order, so
  "ogretmen" finds "Öğretmen", "9a" finds "9-A" and "ayse 9a" finds both
- replace the per-page toLocaleLowerCase().includes() filters with it across
  rosters, courses, exams, events, classes, messages, payments, whiteboards,
  the dashboard deadlines, the user table, the blueprint picker, the command
  palette and Çelebi's message search
- DataTableSearch: Escape empties the field (and only then stops the event,
  so Escape still closes the panel around it)
- SearchableSelect: the same folding filter instead of Kobalte's raw
  substring test, plus a "no results" line where the popover used to just
  close and read as broken
- UserSearchSelect: say it is loading while the debounce and request run,
  instead of showing an empty panel that reads as "nobody matches"
src/components/classes/blueprint-panel.tsxmodified+3 -2
@@ -11,6 +11,7 @@ import { Input } from "@/components/ui/input";
1111 import { Label } from "@/components/ui/label";
1212 import { SidePanel } from "@/components/ui/side-panel";
1313 import { courseKindLabel } from "@/lib/course-kind";
14+import { matchesSearch } from "@/lib/search-text";
1415 import { useT } from "@/stores/preferences-context";
1516
1617 export function BlueprintPanel(props: {
@@ -47,9 +48,9 @@ export function BlueprintPanel(props: {
4748 });
4849
4950 const visibleCourses = createMemo(() => {
50- const q = filter().trim().toLocaleLowerCase("tr-TR");
51+ const q = filter().trim();
5152 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));
5354 });
5455
5556 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";
2626 import { useModules } from "@/stores/modules-context";
2727 import { usePreferences, useT } from "@/stores/preferences-context";
2828 import { cn } from "@/lib/cn";
29+import { matchesSearch } from "@/lib/search-text";
2930
3031 export type CommandPaletteProps = {
3132 open: boolean;
@@ -289,7 +290,7 @@ export function CommandPalette(props: CommandPaletteProps) {
289290 });
290291
291292 const filteredItems = createMemo(() => {
292- const q = query().trim().toLocaleLowerCase(prefs.locale());
293+ const q = query().trim();
293294 if (!q) return items();
294295 const peopleLabel = t("command.group.people");
295296 const found: CommandItem[] = (people.latest?.items ?? []).map((person) => ({
@@ -302,9 +303,7 @@ export function CommandPalette(props: CommandPaletteProps) {
302303 onSelect: () => void navigate({ to: "/admin/users/$id", params: { id: person.id } }),
303304 }));
304305 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),
308307 )];
309308 });
310309
src/components/ui/data-table-search.tsxmodified+10 -2
@@ -18,8 +18,8 @@ export type DataTableSearchProps = {
1818 class?: string;
1919 };
2020
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. */
2323 export function DataTableSearch(props: DataTableSearchProps) {
2424 const t = useT();
2525 const [focused, setFocused] = createSignal(false);
@@ -34,6 +34,14 @@ export function DataTableSearch(props: DataTableSearchProps) {
3434 <Input
3535 value={props.value}
3636 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+ }}
3745 placeholder={props.placeholder ?? t("common.search")}
3846 aria-describedby={props.hint ? hintId : undefined}
3947 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";
22 import {
33 Combobox,
44 ComboboxContent,
@@ -9,13 +9,16 @@ import {
99 ComboboxItemLabel,
1010 ComboboxTrigger,
1111 } from "@/components/ui/combobox";
12+import { matchesSearch } from "@/lib/search-text";
13+import { useT } from "@/stores/preferences-context";
1214
1315 export type SearchableOption = { value: string; label: string };
1416
1517 /**
1618 * 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.
1922 */
2023 export function SearchableSelect(props: {
2124 id?: string;
@@ -28,12 +31,28 @@ export function SearchableSelect(props: {
2831 required?: boolean;
2932 class?: string;
3033 }) {
34+ const t = useT();
35+ const [query, setQuery] = createSignal("");
3136 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+
3246 return (
3347 <Combobox<SearchableOption>
3448 options={props.options}
3549 value={selected()}
3650 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
3756 optionValue="value"
3857 optionLabel="label"
3958 optionTextValue="label"
@@ -52,7 +71,11 @@ export function SearchableSelect(props: {
5271 <ComboboxTrigger />
5372 </ComboboxControl>
5473 <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>
5679 </Combobox>
5780 );
5881 }
src/components/users/user-search-select.tsxmodified+5 -0
@@ -171,6 +171,11 @@ export function UserSearchSelect(props: {
171171 <ComboboxTrigger />
172172 </ComboboxControl>
173173 <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>
174179 <Show when={emptyText()}>
175180 <p class="px-2 py-2 text-xs font-medium text-destructive">{emptyText()}</p>
176181 </Show>
src/components/users/user-table.tsxmodified+2 -4
@@ -10,6 +10,7 @@ import { DataTable } from "@/components/ui/data-table";
1010 import { TableRowActions } from "@/components/ui/table-row-actions";
1111 import { IconCheck, IconExternalLink, IconEye, IconUsers } from "@/components/ui/icons";
1212 import { ROLES } from "@/lib/roles";
13+import { matchesSearch } from "@/lib/search-text";
1314 import { useT } from "@/stores/preferences-context";
1415
1516 function displayName(user: User): string {
@@ -77,10 +78,7 @@ export function UserTable(props: {
7778 const t = useT();
7879 const navigate = useNavigate();
7980 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));
8482 const columns = createMemo<ColumnDef<User>[]>(() => [
8583 {
8684 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";
2323 import { ComingSoonBadge, ComingSoonValue } from "@/components/ui/coming-soon";
2424 import { UserSearchSelect } from "@/components/users/user-search-select";
2525 import { createFlash } from "@/lib/flash";
26+import { matchesSearch } from "@/lib/search-text";
2627 import { personLabel } from "@/lib/person";
2728 import { hasMinRole } from "@/lib/roles";
2829 import { useAuth } from "@/stores/auth-context";
@@ -79,10 +80,10 @@ function ClassesContent() {
7980 });
8081
8182 const searched = createMemo(() => {
82- const needle = query().trim().toLocaleLowerCase("tr");
83+ const needle = query().trim();
8384 if (!needle) return gradeFiltered();
8485 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),
8687 );
8788 });
8889
src/pages/courses-page.tsxmodified+3 -6
@@ -24,6 +24,7 @@ import { SidePanel } from "@/components/ui/side-panel";
2424 import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
2525 import { Textarea } from "@/components/ui/textarea";
2626 import { createFlash } from "@/lib/flash";
27+import { matchesSearch } from "@/lib/search-text";
2728 import { personLabel } from "@/lib/person";
2829 import { hasMinRole } from "@/lib/roles";
2930 import { useAuth } from "@/stores/auth-context";
@@ -79,17 +80,13 @@ function CoursesContent() {
7980 );
8081 const listData = () => list.latest ?? list();
8182 const filteredCourses = createMemo(() => {
82- const query = search().trim().toLocaleLowerCase();
83+ const query = search().trim();
8384 return (listData()?.items ?? []).filter((course) => {
8485 if (pageKind() && course.kind !== pageKind()) return false;
8586 if (taughtFilter() === "untaught" && course.class_course_count > 0) return false;
8687 if (taughtFilter() === "taught" && course.class_course_count === 0) return false;
8788 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));
9390 });
9491 });
9592 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";
4848 import { cn } from "@/lib/cn";
4949 import { formatDateTime } from "@/lib/format";
5050 import { formatTry } from "@/lib/meals";
51+import { matchesSearch } from "@/lib/search-text";
5152 import { personLabel } from "@/lib/person";
5253 import { packageLabel } from "@/lib/module-labels";
5354 import { hasMinRole } from "@/lib/roles";
@@ -632,7 +633,7 @@ function DashboardContent() {
632633 },
633634 ]);
634635
635- const deadlineSearch = (row: DeadlineRow, q: string) => row.title.toLowerCase().includes(q.toLowerCase());
636+ const deadlineSearch = (row: DeadlineRow, q: string) => matchesSearch(q, row.title);
636637 const openDeadline = (row: DeadlineRow) => {
637638 switch (row.kind) {
638639 case "exam":
src/pages/events-page.tsxmodified+9 -4
@@ -21,6 +21,7 @@ import { createNow } from "@/lib/create-now";
2121 import { createFlash } from "@/lib/flash";
2222 import { formatDateTime } from "@/lib/format";
2323 import { hasMinRole } from "@/lib/roles";
24+import { matchesSearch } from "@/lib/search-text";
2425 import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status";
2526 import { useAuth } from "@/stores/auth-context";
2627 import { usePreferences, useT } from "@/stores/preferences-context";
@@ -79,10 +80,14 @@ function EventsContent() {
7980 return t("events.audience.registration");
8081 };
8182 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+ );
8691 const columns = createMemo<ColumnDef<Event>[]>(() => [
8792 {
8893 accessorKey: "title",
src/pages/exams-page.tsxmodified+9 -4
@@ -29,6 +29,7 @@ import { examDisplayStatus, examStatusMessageKey, examStatusTone, type ExamDispl
2929 import { createFlash } from "@/lib/flash";
3030 import { formatDateTime } from "@/lib/format";
3131 import { hasMinRole } from "@/lib/roles";
32+import { matchesSearch } from "@/lib/search-text";
3233 import { scheduleStatusClass, scheduleStatusDotClass } from "@/lib/schedule-status";
3334 import { cn } from "@/lib/cn";
3435 import { useAuth } from "@/stores/auth-context";
@@ -118,10 +119,14 @@ function ExamsContent() {
118119 });
119120 };
120121 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+ );
125130
126131 const [list, { refetch: refetchExams }] = createResource(
127132 () => {
src/pages/messages-page.tsxmodified+3 -2
@@ -33,6 +33,7 @@ import type { Message, MessageFolder } from "@/api/client";
3333 import { formatApiError } from "@/api/client";
3434 import { useAuth } from "@/stores/auth-context";
3535 import { useT } from "@/stores/preferences-context";
36+import { matchesSearch } from "@/lib/search-text";
3637 import { personLabel } from "@/lib/person";
3738 import { createFlash } from "@/lib/flash";
3839 import { Badge } from "@/components/ui/badge";
@@ -72,13 +73,13 @@ export default function MessagesPage() {
7273 );
7374
7475 const filtered = createMemo(() => {
75- const q = query().trim().toLocaleLowerCase();
76+ const q = query().trim();
7677 if (!q) return messages();
7778 return messages().filter((m) => {
7879 const isSent = folder() === "sent" || m.sender.id === auth.user()?.id;
7980 const peer = isSent ? m.recipient : m.sender;
8081 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);
8283 });
8384 });
8485
src/pages/payments-page.tsxmodified+4 -4
@@ -46,6 +46,7 @@ import { createFlash } from "@/lib/flash";
4646 import { formatDate, formatDateTime } from "@/lib/format";
4747 import { formatTry } from "@/lib/meals";
4848 import { PAYMENT_METHOD_KEYS, sortStatementEntries, statementStatus } from "@/lib/payments";
49+import { matchesSearch } from "@/lib/search-text";
4950 import { personLabel } from "@/lib/person";
5051 import { usePreferences, useT } from "@/stores/preferences-context";
5152
@@ -133,14 +134,13 @@ function PaymentsContent() {
133134 // (already name-resolved) plan roster and filters/pages it client-side —
134135 // a plan's assignees are a small, bounded list on their own.
135136 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 }> => {
138139 if (plan) {
139140 const assignments = await getPlanAssignments(plan, { limit: 500 });
140- const needle = q.toLocaleLowerCase(loc);
141141 const all = assignments.items
142142 .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));
144144 const start = page * size;
145145 return { items: all.slice(start, start + size), total: all.length };
146146 }
src/pages/staff-work-page.tsxmodified+2 -1
@@ -28,6 +28,7 @@ import { PaginationControls } from "@/components/ui/pagination-controls";
2828 import { SidePanel } from "@/components/ui/side-panel";
2929 import { TableRowActions } from "@/components/ui/table-row-actions";
3030 import { formatDateTime, formatDurationMinutes } from "@/lib/format";
31+import { matchesSearch } from "@/lib/search-text";
3132 import { personLabel } from "@/lib/person";
3233 import { usePreferences, useT } from "@/stores/preferences-context";
3334
@@ -149,7 +150,7 @@ function StaffWorkContent() {
149150 const entryRows = () => entries().items;
150151 const peopleLoading = () => people.loading;
151152 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);
153154
154155 const filteredPeople = createMemo(() => {
155156 const q = staffSearch().trim();
src/pages/student-attendance-page.tsxmodified+2 -1
@@ -13,6 +13,7 @@ import { ErrorAlert } from "@/components/ui/error-alert";
1313 import { IconEye } from "@/components/ui/icons";
1414 import { SidePanel } from "@/components/ui/side-panel";
1515 import { TableRowActions } from "@/components/ui/table-row-actions";
16+import { matchesSearch } from "@/lib/search-text";
1617 import { personLabel } from "@/lib/person";
1718 import { useT } from "@/stores/preferences-context";
1819
@@ -64,7 +65,7 @@ function StudentAttendanceContent() {
6465 const rows = () => list();
6566 const listLoading = () => list.loading;
6667 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);
6869 const columns = createMemo<ColumnDef<PersonRef>[]>(() => [
6970 {
7071 accessorKey: "username",
src/pages/student-marks-page.tsxmodified+2 -1
@@ -14,6 +14,7 @@ import { ErrorAlert } from "@/components/ui/error-alert";
1414 import { IconEye } from "@/components/ui/icons";
1515 import { SidePanel } from "@/components/ui/side-panel";
1616 import { TableRowActions } from "@/components/ui/table-row-actions";
17+import { matchesSearch } from "@/lib/search-text";
1718 import { personLabel } from "@/lib/person";
1819 import { useT } from "@/stores/preferences-context";
1920
@@ -101,7 +102,7 @@ function StudentMarksContent() {
101102 };
102103 const listLoading = () => list.loading;
103104 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);
105106 const columns = createMemo<ColumnDef<PersonRef>[]>(() => [
106107 {
107108 accessorKey: "username",
src/pages/student-pomodoro-page.tsxmodified+2 -1
@@ -13,6 +13,7 @@ import { ErrorAlert } from "@/components/ui/error-alert";
1313 import { IconEye } from "@/components/ui/icons";
1414 import { SidePanel } from "@/components/ui/side-panel";
1515 import { TableRowActions } from "@/components/ui/table-row-actions";
16+import { matchesSearch } from "@/lib/search-text";
1617 import { personLabel } from "@/lib/person";
1718 import { useT } from "@/stores/preferences-context";
1819
@@ -64,7 +65,7 @@ function StudentPomodoroContent() {
6465 const rows = () => list();
6566 const listLoading = () => list.loading;
6667 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);
6869 const studentColumns = createMemo<ColumnDef<PersonRef>[]>(() => [
6970 {
7071 accessorKey: "username",
src/pages/whiteboards-page.tsxmodified+3 -2
@@ -19,6 +19,7 @@ import { SidePanel } from "@/components/ui/side-panel";
1919 import { TablePagination } from "@/components/ui/table-pagination";
2020 import { cn } from "@/lib/cn";
2121 import { formatDate } from "@/lib/format";
22+import { matchesSearch } from "@/lib/search-text";
2223 import { personLabel } from "@/lib/person";
2324 import { hasMinRole } from "@/lib/roles";
2425 import { useAuth } from "@/stores/auth-context";
@@ -51,9 +52,9 @@ function WhiteboardsContent() {
5152 // only the current page's real titles — a client-side search over real
5253 // data, not a promise of searching every board the caller has ever opened.
5354 const visibleBoards = createMemo(() => {
54- const q = query().trim().toLocaleLowerCase();
55+ const q = query().trim();
5556 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;
5758 });
5859
5960 const meId = () => auth.user()?.id ?? "";