Skip to content

Conversation

robertky
Copy link
Member

Summary

Closes #36.

Adds two useful ways to order the already-loaded books and makes the rating data behind one of those choices visible on every relevant book card.

Changes

  • Extends the existing OpenLibrary subject search in src/api/openLibrary.ts with ratings_average and ratings_count; it still makes one request per selected subject and fetches the same number of books
  • Adds averageRating and ratingsCount to the normalized Book model in src/types.ts, with safe null fallbacks for missing or invalid values
  • Adds Author A-Z and Highest rated to src/utils/sortBooks.ts and the existing sort select
  • Orders authors by the first listed author and keeps books with no author after the books with author data
  • Orders ratings from highest to lowest; books with the same rating use the number of ratings as a tie-breaker, and books without a rating stay visible at the end
  • Shows Rating: X.X / 5 (N ratings) on each rated BookCard, independent of the selected sort option; books without a rating do not show an empty row

Tests

  • Updates the MSW fixture books with rating data without introducing real network calls in tests
  • Covers both new sort modes, equal ratings, and missing author/rating data in src/utils/sortBooks.test.ts
  • Covers changing sort options without a second request and restoring Highest rated from sessionStorage in src/App.test.tsx
  • Covers the visible rating and missing-rating state in src/components/BookCard.test.tsx
  • Deliberately updates the affected App and BookCard snapshots

Validation

  • npm run format:check
  • npm run lint
  • npm test — 56 tests passed
  • npm run build

Checklist

  • Author and rating sorting work entirely client-side
  • Ratings are explained to the user rather than only affecting order invisibly
  • Missing OpenLibrary fields are handled safely
  • Existing filtering, navigation, favorites, sessionStorage, and no-extra-request behavior remain covered

@robertky robertky requested a review from a team as a code owner September 16, 2026 11:41
@robertky robertky added this to the M4 — Quality milestone Sep 16, 2026
@robertky robertky added type: feature New functionality or requirement area: ui React components, presentation, navigation priority: high Required for first delivery status: in-review PR is open and awaiting review ai-assisted Substantial AI-generated code (documented per spec) labels Sep 16, 2026
@robertky robertky force-pushed the feat/36-author-rating-sorting branch from 82ac7df to 5d910ae Compare September 16, 2026 18:59
Copy link
Member

@rachelks rachelks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after the update with main. Sorting by author and rating works as expected, and all checks pass. Looks good to me! 😊

@rachelks rachelks merged commit 6b941e9 into main Sep 16, 2026
1 check passed
Sign in to join this conversation on GitHub.
Labels
ai-assisted Substantial AI-generated code (documented per spec) area: ui React components, presentation, navigation priority: high Required for first delivery status: in-review PR is open and awaiting review type: feature New functionality or requirement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: add author and rating sorting for library books
2 participants