From b2e5977c6ae84ee822b5823db698ab6862a56a8f Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 11 Nov 2026 22:49:28 +0100 Subject: [PATCH 01/19] feat(ui): add new shadcn components --- frontend/app/components/ui/Accordion.tsx | 77 ++++++++++++ frontend/app/components/ui/Checkbox.tsx | 25 ++++ frontend/app/components/ui/RadioGroup.tsx | 35 ++++++ frontend/app/components/ui/Sheet.tsx | 135 ++++++++++++++++++++++ 4 files changed, 272 insertions(+) create mode 100644 frontend/app/components/ui/Accordion.tsx create mode 100644 frontend/app/components/ui/Checkbox.tsx create mode 100644 frontend/app/components/ui/RadioGroup.tsx create mode 100644 frontend/app/components/ui/Sheet.tsx diff --git a/frontend/app/components/ui/Accordion.tsx b/frontend/app/components/ui/Accordion.tsx new file mode 100644 index 00000000..3bf4d587 --- /dev/null +++ b/frontend/app/components/ui/Accordion.tsx @@ -0,0 +1,77 @@ +import { Accordion as AccordionPrimitive } from "@base-ui/react/accordion"; +import { cn } from "cn"; +import { ChevronDownIcon, ChevronUpIcon } from "lucide-react"; + +function Accordion({ className, ...props }: AccordionPrimitive.Root.Props) { + return ( + + ); +} + +function AccordionItem({ className, ...props }: AccordionPrimitive.Item.Props) { + return ( + + ); +} + +function AccordionTrigger({ + className, + children, + ...props +}: AccordionPrimitive.Trigger.Props) { + return ( + + + {children} + + + + + ); +} + +function AccordionContent({ + className, + children, + ...props +}: AccordionPrimitive.Panel.Props) { + return ( + +
+ {children} +
+
+ ); +} + +export { Accordion, AccordionItem, AccordionTrigger, AccordionContent }; diff --git a/frontend/app/components/ui/Checkbox.tsx b/frontend/app/components/ui/Checkbox.tsx new file mode 100644 index 00000000..776a1671 --- /dev/null +++ b/frontend/app/components/ui/Checkbox.tsx @@ -0,0 +1,25 @@ +import { Checkbox as CheckboxPrimitive } from "@base-ui/react/checkbox"; +import { cn } from "cn"; +import { CheckIcon } from "lucide-react"; + +function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) { + return ( + + + + + + ); +} + +export { Checkbox }; diff --git a/frontend/app/components/ui/RadioGroup.tsx b/frontend/app/components/ui/RadioGroup.tsx new file mode 100644 index 00000000..5a2c7291 --- /dev/null +++ b/frontend/app/components/ui/RadioGroup.tsx @@ -0,0 +1,35 @@ +import { Radio as RadioPrimitive } from "@base-ui/react/radio"; +import { RadioGroup as RadioGroupPrimitive } from "@base-ui/react/radio-group"; +import { cn } from "cn"; + +function RadioGroup({ className, ...props }: RadioGroupPrimitive.Props) { + return ( + + ); +} + +function RadioGroupItem({ className, ...props }: RadioPrimitive.Root.Props) { + return ( + + + + + + ); +} + +export { RadioGroup, RadioGroupItem }; diff --git a/frontend/app/components/ui/Sheet.tsx b/frontend/app/components/ui/Sheet.tsx new file mode 100644 index 00000000..b7c97175 --- /dev/null +++ b/frontend/app/components/ui/Sheet.tsx @@ -0,0 +1,135 @@ +import * as React from "react"; +import { Dialog as SheetPrimitive } from "@base-ui/react/dialog"; +import { cn } from "cn"; + +import { Button } from "~/components/ui/Button"; +import { XIcon } from "lucide-react"; + +function Sheet({ ...props }: SheetPrimitive.Root.Props) { + return ; +} + +function SheetTrigger({ ...props }: SheetPrimitive.Trigger.Props) { + return ; +} + +function SheetClose({ ...props }: SheetPrimitive.Close.Props) { + return ; +} + +function SheetPortal({ ...props }: SheetPrimitive.Portal.Props) { + return ; +} + +function SheetOverlay({ className, ...props }: SheetPrimitive.Backdrop.Props) { + return ( + + ); +} + +function SheetContent({ + className, + children, + side = "right", + showCloseButton = true, + ...props +}: SheetPrimitive.Popup.Props & { + side?: "top" | "right" | "bottom" | "left"; + showCloseButton?: boolean; +}) { + return ( + + + + {children} + {showCloseButton && ( + + } + > + + Close + + )} + + + ); +} + +function SheetHeader({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ); +} + +function SheetFooter({ className, ...props }: React.ComponentProps<"div">) { + return ( +
+ ); +} + +function SheetTitle({ className, ...props }: SheetPrimitive.Title.Props) { + return ( + + ); +} + +function SheetDescription({ + className, + ...props +}: SheetPrimitive.Description.Props) { + return ( + + ); +} + +export { + Sheet, + SheetTrigger, + SheetClose, + SheetContent, + SheetHeader, + SheetFooter, + SheetTitle, + SheetDescription, +}; From c28c74010eb4de9a7fd73c1b057149ccb3c64921 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Wed, 11 Nov 2026 23:36:22 +0100 Subject: [PATCH 02/19] refactor: move BookCard skeleton to own component --- frontend/app/components/BookCard/BookCard.tsx | 18 +++++++++++++++++- frontend/app/routes/profile.tsx | 13 +++---------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/frontend/app/components/BookCard/BookCard.tsx b/frontend/app/components/BookCard/BookCard.tsx index a453540a..b5a9468f 100644 --- a/frontend/app/components/BookCard/BookCard.tsx +++ b/frontend/app/components/BookCard/BookCard.tsx @@ -2,6 +2,7 @@ import { StarIcon } from "lucide-react"; import { BookCover } from "~/components/BookCover/BookCover"; import { FavoriteButton } from "~/components/FavoriteButton/FavoriteButton"; import { Card, CardContent, CardHeader, CardTitle } from "~/components/ui/Card"; +import { Skeleton } from "~/components/ui/Skeleton"; import { Link, useLocation, useSearchParams } from "react-router"; import type { SearchBook } from "~/hooks/useSearchBooks"; @@ -65,4 +66,19 @@ function BookCard({ book, searchListParams }: BookCardProps) { ); } -export { BookCard }; +// A placeholder with the same layout as BookCard, so the grid doesn't jump +// when the books load. Hidden from screen readers, so the page should +// announce the loading itself +function BookCardSkeleton() { + return ( + + ); +} + +export { BookCard, BookCardSkeleton }; diff --git a/frontend/app/routes/profile.tsx b/frontend/app/routes/profile.tsx index 438e7157..016df3c8 100644 --- a/frontend/app/routes/profile.tsx +++ b/frontend/app/routes/profile.tsx @@ -1,7 +1,7 @@ import { Link, Navigate, useSearchParams } from "react-router"; import { authClient } from "~/api/auth"; import { useFavoriteBooks } from "~/hooks/useFavoriteBooks"; -import { BookCard } from "~/components/BookCard/BookCard"; +import { BookCard, BookCardSkeleton } from "~/components/BookCard/BookCard"; import { BookPagination } from "~/components/BookPagination/BookPagination"; import { PageBreadcrumb } from "~/components/PageBreadcrumb/PageBreadcrumb"; import { Avatar, AvatarFallback } from "~/components/ui/Avatar"; @@ -137,16 +137,9 @@ export default function ProfilePage() { aria-hidden="true" className="grid gap-4 sm:grid-cols-2 lg:grid-cols-3 pb-10" > - {/* Mirrors BookCard's layout so the grid doesn't jump when books load */} {Array.from({ length: 3 }, (_, i) => ( -
  • - - - - +
  • +
  • ))} From 67ed88f790d9aa88995506352228836bb108821f Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 12 Nov 2026 00:27:43 +0100 Subject: [PATCH 03/19] feat: redesign filters Moves filters to own Sheet for mobile screens, and adds filters in a sidebar for desktop --- .../books/BookFilters/BookFilters.tsx | 242 ++++++++---------- .../books/GenreFilter/GenreFilter.tsx | 106 ++++++++ .../MinRatingsFilter/MinRatingsFilter.tsx | 54 ++-- .../books/PagesFilter/PagesFilter.tsx | 12 +- .../books/RadioFilter/RadioFilter.tsx | 116 +++++++++ .../components/books/SearchBar/SearchBar.tsx | 46 ++-- frontend/app/components/ui/Checkbox.tsx | 2 +- frontend/app/routes/books.tsx | 90 +++++-- 8 files changed, 461 insertions(+), 207 deletions(-) create mode 100644 frontend/app/components/books/GenreFilter/GenreFilter.tsx create mode 100644 frontend/app/components/books/RadioFilter/RadioFilter.tsx diff --git a/frontend/app/components/books/BookFilters/BookFilters.tsx b/frontend/app/components/books/BookFilters/BookFilters.tsx index 790a7bbc..d0d245a5 100644 --- a/frontend/app/components/books/BookFilters/BookFilters.tsx +++ b/frontend/app/components/books/BookFilters/BookFilters.tsx @@ -1,28 +1,73 @@ +import { useId, type ReactNode } from "react"; +import { + Accordion, + AccordionContent, + AccordionItem, + AccordionTrigger, +} from "~/components/ui/Accordion"; +import { Badge } from "~/components/ui/Badge"; import { Button } from "~/components/ui/Button"; import { useSearchParams } from "react-router"; import { FILTER_KEYS, useBookSearchParams } from "~/hooks/useBookSearchParams"; import { useBookFilters } from "~/hooks/useBookFilters"; -import { - Combobox, - ComboboxChip, - ComboboxChips, - ComboboxChipsInput, - ComboboxContent, - ComboboxEmpty, - ComboboxInput, - ComboboxItem, - ComboboxList, - ComboboxValue, - useComboboxAnchor, -} from "~/components/ui/Combobox"; import { MinRatingsFilter } from "~/components/books/MinRatingsFilter/MinRatingsFilter"; import { PagesFilter } from "~/components/books/PagesFilter/PagesFilter"; +import { GenreFilter } from "~/components/books/GenreFilter/GenreFilter"; +import { RadioFilter } from "~/components/books/RadioFilter/RadioFilter"; + +interface FilterSectionProps { + value: string; + title: string; + activeCount: number; + children: ReactNode; +} + +// One filter in the Accordion. The badge shows how many of its options are selected +function FilterSection({ + value, + title, + activeCount, + children, +}: FilterSectionProps) { + return ( + + + + {title} + {activeCount > 0 && ( + + {activeCount} + selected + + )} + + + + {children} + + + ); +} function BookFilters() { const [, setSearchParams] = useSearchParams(); const { filters } = useBookSearchParams(); - const { genres, languages, bookFormats } = useBookFilters(); - const genresAnchor = useComboboxAnchor(); + const { languages, bookFormats } = useBookFilters(); + + // The filters can be rendered twice (sidebar on desktop, sheet on mobile), + // so we need a unique id + const headingId = useId(); + + const genresCount = filters.genres?.length ?? 0; + + // Genres start open, and so do the other filters that are in use + const initSections = [ + "genres", + ...(filters.language ? ["language"] : []), + ...(filters.bookFormat ? ["bookFormat"] : []), + ...(filters.minRatings === undefined ? [] : ["minRatings"]), + ...(filters.pages ? ["pages"] : []), + ]; const hasActiveFilters = Object.values(filters).some(Boolean); @@ -39,9 +84,9 @@ function BookFilters() { }; return ( -
    +
    -

    +

    Filter Books

    -
      -
    • - - { - setSearchParams((searchParams) => { - searchParams.delete("genres"); - selected.forEach((genre) => - searchParams.append("genres", genre), - ); - searchParams.delete("page"); - return searchParams; - }); - }} - > - - - {(filters.genres ?? []).map((genre) => ( - {genre} - ))} - - - - - No genres found. - - {(genre: string) => ( - - {genre} - - )} - - - -
    • -
    • - - { - setSearchParams((searchParams) => { - if (language) { - searchParams.set("language", language); - } else { - searchParams.delete("language"); - } - searchParams.delete("page"); - return searchParams; - }); - }} - > - - - No languages found. - - {(language: string) => ( - - {language} - - )} - - - -
    • -
    • - - { - setSearchParams((searchParams) => { - if (bookFormat) { - searchParams.set("bookFormat", bookFormat); - } else { - searchParams.delete("bookFormat"); - } - searchParams.delete("page"); - return searchParams; - }); - }} - > - - - No book formats found. - - {(bookFormat: string) => ( - - {bookFormat} - - )} - - - -
    • -
    • + + + + + + + + + + + -
    • -
    • + + -
    • -
    + +
    ); } diff --git a/frontend/app/components/books/GenreFilter/GenreFilter.tsx b/frontend/app/components/books/GenreFilter/GenreFilter.tsx new file mode 100644 index 00000000..085f684a --- /dev/null +++ b/frontend/app/components/books/GenreFilter/GenreFilter.tsx @@ -0,0 +1,106 @@ +import { useId, useState } from "react"; +import { useSearchParams } from "react-router"; +import { Button } from "~/components/ui/Button"; +import { Checkbox } from "~/components/ui/Checkbox"; +import { + Field, + FieldGroup, + FieldLabel, + FieldLegend, + FieldSet, +} from "~/components/ui/Field"; +import { Input } from "~/components/ui/Input"; +import { useBookFilters } from "~/hooks/useBookFilters"; +import { useBookSearchParams } from "~/hooks/useBookSearchParams"; + +const TOP_GENRES_COUNT = 8; + +function GenreFilter() { + const [, setSearchParams] = useSearchParams(); + const { filters } = useBookSearchParams(); + const { genres } = useBookFilters(); + const [showAll, setShowAll] = useState(false); + const [search, setSearch] = useState(""); + + // The filters can be rendered twice (sidebar on desktop, sheet on mobile), + // so we need a unique id. Names can also have spaces, so we use the index + const baseId = useId(); + + const selected = filters.genres ?? []; + + const topGenres = genres.slice(0, TOP_GENRES_COUNT); + + // The most common genres keep their order, so checking one doesn't move the + // list. Selected genres outside them are added first, so they can be + // unchecked. "Show all" shows every genre that matches the search instead + const shownGenres = showAll + ? genres.filter((genre) => + genre.toLowerCase().includes(search.trim().toLowerCase()), + ) + : [...selected.filter((genre) => !topGenres.includes(genre)), ...topGenres]; + + function toggleGenre(genre: string, checked: boolean) { + setSearchParams((searchParams) => { + const newGenres = checked + ? [...selected, genre] + : selected.filter((selectedGenre) => selectedGenre !== genre); + + searchParams.delete("genres"); + newGenres.forEach((newGenre) => searchParams.append("genres", newGenre)); + searchParams.delete("page"); + return searchParams; + }); + } + + return ( +
    + + Genres + + + {showAll && ( + setSearch(e.target.value)} + /> + )} + + + {shownGenres.map((genre, index) => ( + + toggleGenre(genre, checked)} + /> + + {genre} + + + ))} + + + {showAll && shownGenres.length === 0 && ( +

    No genres found.

    + )} + + +
    + ); +} + +export { GenreFilter }; diff --git a/frontend/app/components/books/MinRatingsFilter/MinRatingsFilter.tsx b/frontend/app/components/books/MinRatingsFilter/MinRatingsFilter.tsx index 7f8a0592..d72c3b48 100644 --- a/frontend/app/components/books/MinRatingsFilter/MinRatingsFilter.tsx +++ b/frontend/app/components/books/MinRatingsFilter/MinRatingsFilter.tsx @@ -1,12 +1,13 @@ +import { useId } from "react"; import { useSearchParams } from "react-router"; import { useBookSearchParams } from "~/hooks/useBookSearchParams"; import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "~/components/ui/Select"; + Field, + FieldLabel, + FieldLegend, + FieldSet, +} from "~/components/ui/Field"; +import { RadioGroup, RadioGroupItem } from "~/components/ui/RadioGroup"; const items = [ { value: "any", label: "Any" }, @@ -20,18 +21,23 @@ function MinRatingsFilter() { const [, setSearchParams] = useSearchParams(); const { filters } = useBookSearchParams(); + // The filters can be rendered twice (sidebar on desktop, sheet on mobile), + // so we need a unique id + const baseId = useId(); + return ( - <> - - - + + + ))} + + ); } diff --git a/frontend/app/components/books/PagesFilter/PagesFilter.tsx b/frontend/app/components/books/PagesFilter/PagesFilter.tsx index 6f439992..c6dac8a1 100644 --- a/frontend/app/components/books/PagesFilter/PagesFilter.tsx +++ b/frontend/app/components/books/PagesFilter/PagesFilter.tsx @@ -1,4 +1,4 @@ -import { useState, type ComponentProps } from "react"; +import { useId, useState, type ComponentProps } from "react"; import { useSearchParams } from "react-router"; import { useBookSearchParams } from "~/hooks/useBookSearchParams"; import { Input } from "~/components/ui/Input"; @@ -16,6 +16,10 @@ function PagesFilter() { const [, setSearchParams] = useSearchParams(); const { filters } = useBookSearchParams(); + // The filters can be rendered twice (sidebar on desktop, sheet on mobile), + // so we need a unique id + const labelId = useId(); + const [draft, setDraft] = useState(null); const urlMin = filters.pages?.min ?? 0; @@ -58,12 +62,12 @@ function PagesFilter() { } return ( -
    - +
    + Book length (pages) + option.toLowerCase().includes(search.trim().toLowerCase()), + ) + : [ + ...(selected && !topOptions.includes(selected) ? [selected] : []), + ...topOptions, + ]; + + function selectOption(value: string) { + setSearchParams((searchParams) => { + if (value === "any") { + searchParams.delete(param); + } else { + searchParams.set(param, value); + } + searchParams.delete("page"); + return searchParams; + }); + } + + return ( +
    + + {legend} + + + {showAll && ( + setSearch(e.target.value)} + /> + )} + + selectOption(String(value))} + className="-m-1 p-1 gap-3 max-h-72 overflow-y-auto" + > + {["any", ...shownOptions].map((option, index) => ( + + + + {option === "any" ? "Any" : option} + + + ))} + + {showAll && shownOptions.length === 0 && ( +

    No {pluralName} found.

    + )} + + {options.length > TOP_OPTIONS_COUNT && ( + + )} +
    + ); +} + +export { RadioFilter }; diff --git a/frontend/app/components/books/SearchBar/SearchBar.tsx b/frontend/app/components/books/SearchBar/SearchBar.tsx index 6225530e..5dee98d0 100644 --- a/frontend/app/components/books/SearchBar/SearchBar.tsx +++ b/frontend/app/components/books/SearchBar/SearchBar.tsx @@ -11,10 +11,13 @@ import { import { Button } from "~/components/ui/Button"; import { Badge } from "~/components/ui/Badge"; import { - Popover, - PopoverContent, - PopoverTrigger, -} from "~/components/ui/Popover"; + Sheet, + SheetClose, + SheetContent, + SheetFooter, + SheetTitle, + SheetTrigger, +} from "~/components/ui/Sheet"; import { useSearchParams } from "react-router"; import { useDebounce } from "~/hooks/useDebounce"; import { useBookSearchParams } from "~/hooks/useBookSearchParams"; @@ -94,14 +97,16 @@ function SearchBar({ resultCount }: SearchBarProps) { )} - - + } @@ -115,15 +120,24 @@ function SearchBar({ resultCount }: SearchBarProps) { {filtersCount} )} - - - - - + + + {/* Names the sheet for screen readers. The filters show their own heading */} + Filter books + {/* Only the filters scroll, so the "Show books" button below is always visible. + The top padding leaves room for the close (X) button */} +
    + +
    + + }> + {resultCount === undefined + ? "Show books" + : `Show ${resultCount.toLocaleString("en")} ${resultCount === 1 ? "book" : "books"}`} + + +
    +
    ); } diff --git a/frontend/app/components/ui/Checkbox.tsx b/frontend/app/components/ui/Checkbox.tsx index 776a1671..afc3c91d 100644 --- a/frontend/app/components/ui/Checkbox.tsx +++ b/frontend/app/components/ui/Checkbox.tsx @@ -7,7 +7,7 @@ function Checkbox({ className, ...props }: CheckboxPrimitive.Root.Props) { +
      {books.map((book) => (
    • @@ -33,6 +38,50 @@ function BookList({ ); } +// Placeholder cards in the same grid as BookList, so the page keeps its shape +// while books load +function BookListSkeleton() { + return ( + <> +

      + Loading books... +

      + + + ); +} + +// Every state of the page uses the same layout, so the filter sidebar stays +// in place (and keeps its state) while new results are loading +function BooksLayout({ + resultCount, + children, +}: { + resultCount?: number; + children: ReactNode; +}) { + return ( +
      + +
      + + {children} +
      +
      + ); +} + export default function BooksPage() { const [searchParams] = useSearchParams(); const { query, page, filters, sort } = useBookSearchParams(); @@ -66,39 +115,34 @@ export default function BooksPage() { const suggestionParams = new URLSearchParams(searchParams); suggestionParams.set("origin", "suggestions"); - if (loading) { + // Only the first load shows skeletons. Later loads keep showing the + // previous books until the new ones arrive + if (loading && !books) { return ( -
      - -

      - Loading books... -

      -
      + + + + ); } if (error) { return ( -
      - +

      Sorry, there was an error loading the books. Please try again later.

      -
      + ); } if (!books || books.length === 0) { if (suggestions && suggestions.length > 0) { return ( -
      - +
      -
      + ); } return ( -
      - +

      No books found for this search

      -
      + ); } return ( -
      - + -
      + ); } From 2adf66899160db5b677bf39d8c363abff2d5b9b8 Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 12 Nov 2026 00:28:09 +0100 Subject: [PATCH 04/19] chore: remove unused Combobox component --- frontend/app/components/ui/Combobox.tsx | 300 ------------------------ 1 file changed, 300 deletions(-) delete mode 100644 frontend/app/components/ui/Combobox.tsx diff --git a/frontend/app/components/ui/Combobox.tsx b/frontend/app/components/ui/Combobox.tsx deleted file mode 100644 index 534a2525..00000000 --- a/frontend/app/components/ui/Combobox.tsx +++ /dev/null @@ -1,300 +0,0 @@ -"use client"; - -import * as React from "react"; -import { Combobox as ComboboxPrimitive } from "@base-ui/react"; -import { cn } from "cn"; - -import { Button } from "~/components/ui/Button"; -import { - InputGroup, - InputGroupAddon, - InputGroupButton, - InputGroupInput, -} from "~/components/ui/InputGroup"; -import { ChevronDownIcon, XIcon, CheckIcon } from "lucide-react"; - -const Combobox = ComboboxPrimitive.Root; - -function ComboboxValue({ ...props }: ComboboxPrimitive.Value.Props) { - return ; -} - -function ComboboxTrigger({ - className, - children, - ...props -}: ComboboxPrimitive.Trigger.Props) { - return ( - - {children} - - - ); -} - -function ComboboxClear({ className, ...props }: ComboboxPrimitive.Clear.Props) { - return ( - } - className={cn(className)} - {...props} - > - - - ); -} - -function ComboboxInput({ - className, - children, - disabled = false, - showTrigger = true, - showClear = false, - ...props -}: ComboboxPrimitive.Input.Props & { - showTrigger?: boolean; - showClear?: boolean; -}) { - return ( - - } - {...props} - /> - - {showTrigger && ( - } - data-slot="input-group-button" - className="group-has-data-[slot=combobox-clear]/input-group:hidden data-pressed:bg-transparent" - disabled={disabled} - /> - )} - {showClear && } - - {children} - - ); -} - -function ComboboxContent({ - className, - side = "bottom", - sideOffset = 6, - align = "start", - alignOffset = 0, - anchor, - ...props -}: ComboboxPrimitive.Popup.Props & - Pick< - ComboboxPrimitive.Positioner.Props, - "side" | "align" | "sideOffset" | "alignOffset" | "anchor" - >) { - return ( - - - - - - ); -} - -function ComboboxList({ className, ...props }: ComboboxPrimitive.List.Props) { - return ( - - ); -} - -function ComboboxItem({ - className, - children, - ...props -}: ComboboxPrimitive.Item.Props) { - return ( - - {children} - - } - > - - - - ); -} - -function ComboboxGroup({ className, ...props }: ComboboxPrimitive.Group.Props) { - return ( - - ); -} - -function ComboboxLabel({ - className, - ...props -}: ComboboxPrimitive.GroupLabel.Props) { - return ( - - ); -} - -function ComboboxCollection({ ...props }: ComboboxPrimitive.Collection.Props) { - return ( - - ); -} - -function ComboboxEmpty({ className, ...props }: ComboboxPrimitive.Empty.Props) { - return ( - - ); -} - -function ComboboxSeparator({ - className, - ...props -}: ComboboxPrimitive.Separator.Props) { - return ( - - ); -} - -function ComboboxChips({ - className, - ...props -}: React.ComponentPropsWithRef & - ComboboxPrimitive.Chips.Props) { - return ( - - ); -} - -function ComboboxChip({ - className, - children, - showRemove = true, - ...props -}: ComboboxPrimitive.Chip.Props & { - showRemove?: boolean; -}) { - return ( - - {children} - {showRemove && ( - } - className="-ml-1 opacity-50 hover:opacity-100" - data-slot="combobox-chip-remove" - > - - - )} - - ); -} - -function ComboboxChipsInput({ - className, - ...props -}: ComboboxPrimitive.Input.Props) { - return ( - - ); -} - -function useComboboxAnchor() { - return React.useRef(null); -} - -export { - Combobox, - ComboboxInput, - ComboboxContent, - ComboboxList, - ComboboxItem, - ComboboxGroup, - ComboboxLabel, - ComboboxCollection, - ComboboxEmpty, - ComboboxSeparator, - ComboboxChips, - ComboboxChip, - ComboboxChipsInput, - ComboboxTrigger, - ComboboxValue, - useComboboxAnchor, -}; From 86b975ef7b2e7d49b90a6ff9faa4f4aaa8ed9a8b Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 12 Nov 2026 00:28:37 +0100 Subject: [PATCH 05/19] feat(accessibility): higher contrast on RadioGroup border --- frontend/app/components/ui/RadioGroup.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/components/ui/RadioGroup.tsx b/frontend/app/components/ui/RadioGroup.tsx index 5a2c7291..edcab6f3 100644 --- a/frontend/app/components/ui/RadioGroup.tsx +++ b/frontend/app/components/ui/RadioGroup.tsx @@ -17,7 +17,7 @@ function RadioGroupItem({ className, ...props }: RadioPrimitive.Root.Props) { Date: Thu, 12 Nov 2026 00:29:19 +0100 Subject: [PATCH 06/19] fix: do not flash loading state when changing filters --- frontend/app/hooks/useSearchBooks.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/frontend/app/hooks/useSearchBooks.ts b/frontend/app/hooks/useSearchBooks.ts index 5802873f..73d31e4e 100644 --- a/frontend/app/hooks/useSearchBooks.ts +++ b/frontend/app/hooks/useSearchBooks.ts @@ -71,7 +71,7 @@ function useSearchBooks({ sort?: BookSortKey; enabled?: boolean; }) { - const { data, loading, error } = useQuery( + const { data, previousData, loading, error } = useQuery( SEARCH_BOOKS, enabled ? { @@ -93,7 +93,11 @@ function useSearchBooks({ : skipToken, ); - const books = data?.searchBooks.books.map((book) => { + // While new results load, keep the previous ones, so the page doesn't + // flash a loading state on every change. A skipped query has no results + const result = data ?? (enabled ? previousData : undefined); + + const books = result?.searchBooks.books.map((book) => { // Extract only the fields we modify, keep the rest in ...rest const { id, author, publishDate, ...rest } = book; @@ -107,7 +111,7 @@ function useSearchBooks({ return { books, - totalCount: data?.searchBooks.totalCount ?? 0, + totalCount: result?.searchBooks.totalCount ?? 0, loading, error, }; From c214d533ca9b2d3ab377906abc6aa074080ea13c Mon Sep 17 00:00:00 2001 From: Martin Alexander Kaminski Date: Thu, 12 Nov 2026 00:35:51 +0100 Subject: [PATCH 07/19] feat: give cursor-pointer to AccordionTrigger --- frontend/app/components/ui/Accordion.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/app/components/ui/Accordion.tsx b/frontend/app/components/ui/Accordion.tsx index 3bf4d587..e1d1b0a2 100644 --- a/frontend/app/components/ui/Accordion.tsx +++ b/frontend/app/components/ui/Accordion.tsx @@ -32,7 +32,7 @@ function AccordionTrigger({ Date: Thu, 12 Nov 2026 01:00:50 +0100 Subject: [PATCH 08/19] test: add tests for new filters --- .../books/BookFilters/BookFilters.test.tsx | 102 +++++++++++++--- .../books/BookFilters/BookFilters.tsx | 7 +- .../books/GenreFilter/GenreFilter.test.tsx | 108 +++++++++++++++++ .../books/GenreFilter/GenreFilter.tsx | 2 +- .../books/RadioFilter/RadioFilter.test.tsx | 113 ++++++++++++++++++ .../books/RadioFilter/RadioFilter.tsx | 2 +- frontend/app/routes/books.test.tsx | 37 +++++- frontend/e2e/accessibility.spec.ts | 14 ++- frontend/e2e/books.spec.ts | 20 ++-- frontend/e2e/fixtures.ts | 19 ++- frontend/e2e/home.spec.ts | 9 +- frontend/e2e/keyboard.spec.ts | 50 ++++---- 12 files changed, 423 insertions(+), 60 deletions(-) create mode 100644 frontend/app/components/books/GenreFilter/GenreFilter.test.tsx create mode 100644 frontend/app/components/books/RadioFilter/RadioFilter.test.tsx diff --git a/frontend/app/components/books/BookFilters/BookFilters.test.tsx b/frontend/app/components/books/BookFilters/BookFilters.test.tsx index afb84f0d..7aa0e24c 100644 --- a/frontend/app/components/books/BookFilters/BookFilters.test.tsx +++ b/frontend/app/components/books/BookFilters/BookFilters.test.tsx @@ -1,6 +1,6 @@ import { describe, expect, it, vi } from "vitest"; import { render, screen, waitFor } from "@testing-library/react"; -import userEvent from "@testing-library/user-event"; +import userEvent, { type UserEvent } from "@testing-library/user-event"; import { createRoutesStub, Link, useSearchParams } from "react-router"; import { BookFilters } from "~/components/books/BookFilters/BookFilters"; @@ -8,6 +8,7 @@ vi.mock("~/hooks/useBookFilters", () => ({ useBookFilters: () => ({ genres: ["Fantasy", "Romance", "Science Fiction"], languages: ["English", "French", "Spanish"], + bookFormats: ["Paperback", "Hardcover"], loading: false, error: undefined, }), @@ -41,22 +42,28 @@ const Stub = createRoutesStub([ }, ]); +// Each filter is in an accordion section that has to be opened first, +// unless the filter is already in use. +async function openSection(user: UserEvent, name: string) { + await user.click(screen.getByRole("button", { name })); +} + describe("FilterBooksSection", () => { it("shows the selected genres from the URL", () => { render(); - expect(screen.getByText("Fantasy")).toBeInTheDocument(); - expect(screen.getByText("Romance")).toBeInTheDocument(); + expect(screen.getByRole("checkbox", { name: "Fantasy" })).toBeChecked(); + expect(screen.getByRole("checkbox", { name: "Romance" })).toBeChecked(); + expect( + screen.getByRole("checkbox", { name: "Science Fiction" }), + ).not.toBeChecked(); }); it("adds a selected genre to the URL", async () => { const user = userEvent.setup(); render(); - await user.type(screen.getByLabelText("Genres"), "Sci"); - await user.click( - await screen.findByRole("option", { name: "Science Fiction" }), - ); + await user.click(screen.getByRole("checkbox", { name: "Science Fiction" })); await waitFor(() => expect(screen.getByTestId("genres")).toHaveTextContent( @@ -65,18 +72,52 @@ describe("FilterBooksSection", () => { ); }); + it("shows how many options of each filter are selected", () => { + render( + , + ); + + expect( + screen.getByRole("button", { name: "Genres 2 selected" }), + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "Language 1 selected" }), + ).toBeInTheDocument(); + expect( + screen.getByRole("button", { name: "Book format" }), + ).toBeInTheDocument(); + }); + + it("opens the genres and the filters that are in use", () => { + render(); + + expect(screen.getByRole("button", { name: "Genres" })).toHaveAttribute( + "aria-expanded", + "true", + ); + expect( + screen.getByRole("button", { name: "Language 1 selected" }), + ).toHaveAttribute("aria-expanded", "true"); + expect(screen.getByRole("button", { name: "Book format" })).toHaveAttribute( + "aria-expanded", + "false", + ); + }); + it("shows the selected language from the URL", () => { render(); - expect(screen.getByLabelText("Language")).toHaveValue("French"); + expect(screen.getByRole("radio", { name: "French" })).toBeChecked(); }); it("sets the selected language in the URL", async () => { const user = userEvent.setup(); render(); - await user.type(screen.getByLabelText("Language"), "Spa"); - await user.click(await screen.findByRole("option", { name: "Spanish" })); + await openSection(user, "Language"); + await user.click(screen.getByRole("radio", { name: "Spanish" })); await waitFor(() => expect(screen.getByTestId("language")).toHaveTextContent("Spanish"), @@ -87,16 +128,42 @@ describe("FilterBooksSection", () => { const user = userEvent.setup(); render(); - await user.click(screen.getByLabelText("Minimum ratings")); - await user.click( - await screen.findByRole("option", { name: "1,000+ ratings" }), - ); + await openSection(user, "Minimum ratings"); + await user.click(screen.getByRole("radio", { name: "1,000+ ratings" })); await waitFor(() => expect(screen.getByTestId("minRatings")).toHaveTextContent("1000"), ); }); + it("removes the minimum number of ratings when choosing any", async () => { + const user = userEvent.setup(); + render(); + + await user.click(screen.getByRole("radio", { name: "Any" })); + + await waitFor(() => + expect(screen.getByTestId("minRatings")).toBeEmptyDOMElement(), + ); + }); + + it("removes all filters on reset", async () => { + const user = userEvent.setup(); + render( + , + ); + + await user.click(screen.getByRole("button", { name: "Reset" })); + + await waitFor(() => { + expect(screen.getByTestId("genres")).toBeEmptyDOMElement(); + expect(screen.getByTestId("language")).toBeEmptyDOMElement(); + expect(screen.getByTestId("minRatings")).toBeEmptyDOMElement(); + }); + }); + it("shows the page range from the URL", () => { render(); @@ -104,8 +171,10 @@ describe("FilterBooksSection", () => { expect(screen.getByLabelText("Maximum pages")).toHaveValue(500); }); - it("defaults the page range to 0 and the slider end", () => { + it("defaults the page range to 0 and the slider end", async () => { + const user = userEvent.setup(); render(); + await openSection(user, "Book length (pages)"); expect(screen.getByLabelText("Minimum pages")).toHaveValue(0); expect(screen.getByLabelText("Maximum pages")).toHaveValue(2000); @@ -114,6 +183,7 @@ describe("FilterBooksSection", () => { it("writes a typed max to the URL on Enter", async () => { const user = userEvent.setup(); render(); + await openSection(user, "Book length (pages)"); const maxInput = screen.getByLabelText("Maximum pages"); await user.clear(maxInput); @@ -141,6 +211,7 @@ describe("FilterBooksSection", () => { it("keeps focus when tabbing from min to max", async () => { const user = userEvent.setup(); render(); + await openSection(user, "Book length (pages)"); await user.type(screen.getByLabelText("Minimum pages"), "{Backspace}100"); await user.tab(); @@ -194,6 +265,7 @@ describe("FilterBooksSection", () => { it("follows the URL again after a committed edit", async () => { const user = userEvent.setup(); render(); + await openSection(user, "Book length (pages)"); await user.type( screen.getByLabelText("Minimum pages"), diff --git a/frontend/app/components/books/BookFilters/BookFilters.tsx b/frontend/app/components/books/BookFilters/BookFilters.tsx index d0d245a5..240d1b98 100644 --- a/frontend/app/components/books/BookFilters/BookFilters.tsx +++ b/frontend/app/components/books/BookFilters/BookFilters.tsx @@ -33,11 +33,12 @@ function FilterSection({ - {title} + {/* The space keeps screen readers from reading "Genres2 selected" */} + {title}{" "} {activeCount > 0 && ( - {activeCount} - selected + + {`${activeCount} selected`} )} diff --git a/frontend/app/components/books/GenreFilter/GenreFilter.test.tsx b/frontend/app/components/books/GenreFilter/GenreFilter.test.tsx new file mode 100644 index 00000000..afd7c459 --- /dev/null +++ b/frontend/app/components/books/GenreFilter/GenreFilter.test.tsx @@ -0,0 +1,108 @@ +import { describe, expect, it, vi } from "vitest"; +import { render, screen, waitFor } from "@testing-library/react"; +import userEvent from "@testing-library/user-event"; +import { createRoutesStub, useSearchParams } from "react-router"; +import { GenreFilter } from "~/components/books/GenreFilter/GenreFilter"; + +// Sorted by book count, like the API returns them +const GENRES = [ + "Fiction", + "Fantasy", + "Romance", + "Young Adult", + "Classics", + "Mystery", + "Nonfiction", + "Historical", + "Science Fiction", + "Poetry", +]; + +vi.mock("~/hooks/useBookFilters", () => ({ + useBookFilters: () => ({ genres: GENRES }), +})); + +// Shows the genres in the URL so tests can assert what was written to it. +function SearchParamProbe() { + const [searchParams] = useSearchParams(); + return

      {searchParams.getAll("genres").join(",")}

      ; +} + +const Stub = createRoutesStub([ + { + path: "/", + Component: () => ( + <> + + + + ), + }, +]); + +// The labels of the shown checkboxes, in order +function shownGenres() { + return screen + .getAllByText(/./, { selector: "label" }) + .map((label) => label.textContent); +} + +describe("GenreFilter", () => { + it("shows the 8 most common genres", () => { + render(); + + expect(shownGenres()).toEqual(GENRES.slice(0, 8)); + expect( + screen.getByRole("button", { name: "Show all 10 genres" }), + ).toBeInTheDocument(); + }); + + it("keeps the order of the genres when one is checked", async () => { + const user = userEvent.setup(); + render(); + + await user.click(screen.getByRole("checkbox", { name: "Mystery" })); + + await waitFor(() => + expect(screen.getByTestId("genres")).toHaveTextContent("Mystery"), + ); + expect(shownGenres()).toEqual(GENRES.slice(0, 8)); + }); + + it("shows a selected genre that is not among the most common", async () => { + const user = userEvent.setup(); + render(); + + const poetry = screen.getByRole("checkbox", { name: "Poetry" }); + expect(poetry).toBeChecked(); + + await user.click(poetry); + + await waitFor(() => + expect(screen.getByTestId("genres")).toBeEmptyDOMElement(), + ); + }); + + it("searches all genres after clicking show all", async () => { + const user = userEvent.setup(); + render(); + + await user.click( + screen.getByRole("button", { name: "Show all 10 genres" }), + ); + await user.type( + screen.getByRole("searchbox", { name: "Search genres" }), + "fic", + ); + + expect(shownGenres()).toEqual(["Fiction", "Nonfiction", "Science Fiction"]); + + await user.type( + screen.getByRole("searchbox", { name: "Search genres" }), + "zzz", + ); + + expect(screen.queryAllByRole("checkbox")).toHaveLength(0); + expect(screen.getByText("No genres found.")).toBeInTheDocument(); + }); +}); diff --git a/frontend/app/components/books/GenreFilter/GenreFilter.tsx b/frontend/app/components/books/GenreFilter/GenreFilter.tsx index 085f684a..e1b97a83 100644 --- a/frontend/app/components/books/GenreFilter/GenreFilter.tsx +++ b/frontend/app/components/books/GenreFilter/GenreFilter.tsx @@ -90,7 +90,7 @@ function GenreFilter() {