Skip to content

fix: Apply active filters to chapter count display (Closes #1793) - #1797

Merged
CD-Z merged 2 commits into
lnreader:masterfrom
Definisi:fix/chapter-count-filter
Apr 13, 2026
Merged

fix: Apply active filters to chapter count display (Closes #1793)#1797
CD-Z merged 2 commits into
lnreader:masterfrom
Definisi:fix/chapter-count-filter

Conversation

@Definisi

Copy link
Copy Markdown
Contributor

Fixes #1793

When filtering chapters (e.g. showing only unread), the chapter count in the novel header kept showing the total instead of the filtered count.

Root cause:
getChapterCount in ChapterQueries.ts only accepted novelId and page, with no way to pass the active filter. Meanwhile getPageChaptersBatched (which fetches the actual chapter list) was correctly applying filters via chapterFilterToSQL.

What changed:

  • Added an optional filter parameter to getChapterCount and applied chapterFilterToSQL in the count query
  • Updated both call sites in useNovel.ts to pass the current settingsFilter

The reader's useChapter.ts also calls getChapterCount (to check if a next/prev page has chapters), but those calls intentionally stay unfiltered since the reader should still allow navigating across all chapters.

Testing:

  • All 31 existing tests pass
  • No new type errors introduced

)

getChapterCount was always returning the total count regardless of
the active filter. When filtering by unread/downloaded/bookmarked,
the count shown in the novel header stayed the same as the total.

Added an optional filter parameter to getChapterCount and pass the
current settingsFilter from useNovel so the displayed count matches
the filtered chapter list.
@CD-Z

CD-Z commented Mar 25, 2026

Copy link
Copy Markdown
Collaborator

Please fix the lint warnings in useNovel and tests for the filter behavior.

@CD-Z
CD-Z self-requested a review March 25, 2026 12:18
- Use settingsFilter instead of novelSettings.filter in useNovel
  to fix the react-hooks/exhaustive-deps warning
- Add tests for getChapterCount with filter parameter
- Update chapterFilterToSQL mock in test setup to actually apply
  filter conditions so filtered count tests work correctly
@Definisi

Copy link
Copy Markdown
Contributor Author

Fixed in e05a70b:

  • Lint: the react-hooks/exhaustive-deps warning on getChapters was because novelSettings.filter was used on line 274 instead of settingsFilter (same value, different reference). Swapped to settingsFilter so it matches the dep array.

  • Tests: added two test cases for getChapterCount with filters:

    • should return filtered count when filter is provided (verifies not-read and read filters return correct counts)
    • should return total count when no filter is provided (verifies undefined and [] both return total)

    Also updated chapterFilterToSQL mock in setup.ts to actually apply SQL conditions instead of always returning undefined, so the filter tests can work.

All 201 tests passing.

@CD-Z
CD-Z merged commit 01596c0 into lnreader:master Apr 13, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Chapter Count Not Updated After Filtering Unread Chapters

3 participants