fix(home): keep finished series off the Continue-reading shelf
A "Continue reading" shelf listing series the reader already finished (read to the last page, nothing new) is odd. Expose the last-read chapter's page_count on the read-progress list, and filter the shelf to drop entries that are caught up (on the last page of the latest chapter with no new chapters). Mid-chapter and has-new-chapters entries stay; the full history view is unaffected. Finished detection is a pure, unit-tested helper. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,9 @@ export type ReadProgressSummary = {
|
||||
chapter_id: string | null;
|
||||
/** `null` if the chapter was deleted after the progress was written. */
|
||||
chapter_number: number | null;
|
||||
/** Page count of the last-read chapter (`null` when unknown / deleted).
|
||||
* Lets the shelf tell a finished series from one still in progress. */
|
||||
chapter_page_count: number | null;
|
||||
page: number;
|
||||
updated_at: string;
|
||||
/** Chapters past the reader's last-read chapter — a personal "new
|
||||
|
||||
@@ -14,6 +14,7 @@ function entry(over: Partial<Entry> = {}): Entry {
|
||||
manga_cover_image_path: null,
|
||||
chapter_id: 'c1',
|
||||
chapter_number: 3,
|
||||
chapter_page_count: 20,
|
||||
page: 3,
|
||||
updated_at: '2026-01-01T00:00:00Z',
|
||||
new_chapters_count: 0,
|
||||
|
||||
@@ -12,6 +12,7 @@ function entry(over: Partial<ReadProgressSummary> = {}): ReadProgressSummary {
|
||||
manga_cover_image_path: null,
|
||||
chapter_id: 'c1',
|
||||
chapter_number: 5,
|
||||
chapter_page_count: 10,
|
||||
page: 1,
|
||||
updated_at: '2026-01-02T00:00:00Z',
|
||||
new_chapters_count: 0,
|
||||
|
||||
32
frontend/src/lib/continueReading.test.ts
Normal file
32
frontend/src/lib/continueReading.test.ts
Normal file
@@ -0,0 +1,32 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { isCaughtUp } from './continueReading';
|
||||
|
||||
const base = {
|
||||
chapter_number: 5 as number | null,
|
||||
chapter_page_count: 10 as number | null,
|
||||
page: 3,
|
||||
new_chapters_count: 0
|
||||
};
|
||||
|
||||
describe('isCaughtUp', () => {
|
||||
it('is true on the last page of the latest chapter with nothing new', () => {
|
||||
expect(isCaughtUp({ ...base, page: 10 })).toBe(true);
|
||||
});
|
||||
|
||||
it('is false mid-chapter (still something to continue)', () => {
|
||||
expect(isCaughtUp({ ...base, page: 3 })).toBe(false);
|
||||
});
|
||||
|
||||
it('is false when newer chapters exist', () => {
|
||||
expect(isCaughtUp({ ...base, page: 10, new_chapters_count: 2 })).toBe(false);
|
||||
});
|
||||
|
||||
it('is false when the last-read position is unknown', () => {
|
||||
expect(isCaughtUp({ ...base, page: 10, chapter_number: null })).toBe(false);
|
||||
});
|
||||
|
||||
it('is false when the chapter page count is unknown or zero', () => {
|
||||
expect(isCaughtUp({ ...base, page: 10, chapter_page_count: null })).toBe(false);
|
||||
expect(isCaughtUp({ ...base, page: 1, chapter_page_count: 0 })).toBe(false);
|
||||
});
|
||||
});
|
||||
20
frontend/src/lib/continueReading.ts
Normal file
20
frontend/src/lib/continueReading.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { ReadProgressSummary } from '$lib/api/read_progress';
|
||||
|
||||
// Whether a read-progress entry has nothing left to continue: the reader is
|
||||
// on the last page of the latest chapter and no newer chapters exist. Such
|
||||
// finished series are kept off the homepage "Continue reading" shelf (the
|
||||
// full history view still shows them).
|
||||
export function isCaughtUp(
|
||||
e: Pick<
|
||||
ReadProgressSummary,
|
||||
'new_chapters_count' | 'chapter_number' | 'chapter_page_count' | 'page'
|
||||
>
|
||||
): boolean {
|
||||
return (
|
||||
e.new_chapters_count === 0 &&
|
||||
e.chapter_number != null &&
|
||||
e.chapter_page_count != null &&
|
||||
e.chapter_page_count > 0 &&
|
||||
e.page >= e.chapter_page_count
|
||||
);
|
||||
}
|
||||
@@ -26,6 +26,7 @@
|
||||
listMyReadProgressOrEmpty,
|
||||
type ReadProgressSummary
|
||||
} from '$lib/api/read_progress';
|
||||
import { isCaughtUp } from '$lib/continueReading';
|
||||
import Chip from '$lib/components/Chip.svelte';
|
||||
import ContinueReadingShelf from '$lib/components/ContinueReadingShelf.svelte';
|
||||
import MangaCard from '$lib/components/MangaCard.svelte';
|
||||
@@ -312,7 +313,9 @@
|
||||
// empty for guests (401 swallowed), which hides the shelf.
|
||||
try {
|
||||
const progress = await listMyReadProgressOrEmpty();
|
||||
continueEntries = progress.items;
|
||||
// Drop finished series (read to the end, nothing new) — a
|
||||
// "Continue reading" shelf is for what's still in progress.
|
||||
continueEntries = progress.items.filter((e) => !isCaughtUp(e));
|
||||
} catch {
|
||||
// Never let a history hiccup break the catalogue — leave the
|
||||
// shelf hidden.
|
||||
|
||||
Reference in New Issue
Block a user