CodingNic

Bookmarks, Highlights & Notes

Render, Favorite, Filter, and Delete Highlights

Bookmarks, Highlights & Notes 22 min read

Render, Favorite, Filter, and Delete Highlights

Render, Favorite, Filter, and Delete Highlights

Task

Connect the Highlights screen to real Highlight records and finish its interactions.

Load only the current user’s highlights, including:

  • Book
  • selected text
  • CFI range
  • created date
  • favorite state
  • optional note relation/data

For the favorite toggle, update the existing favorite field:

ts
await prisma.highlight.updateMany({
  where: {
    id: highlightId,
    userId: user.id,
  },
  data: {
    favorite: !favorite,
  },
});

Filter the visible collection by:

  • All
  • My Notes
  • Favorites
  • selected Book
  • search query

For a Book filter:

ts
const matchesBook =
  bookFilter === "all" || item.book.id === bookFilter;

Use the custom delete dialog instead of confirm().

Test

Verify:

  • search narrows results
  • Favorites shows only favorite Highlights
  • Book filtering changes the list
  • favorite toggles persist after reload
  • deleting removes the Highlight
  • another user’s Highlight cannot be changed

Checkpoint

Highlights is now a real annotation workspace with search, filters, favorites, navigation data, and safe deletion.