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:
@@ -47,6 +47,7 @@ test('shows the continue-reading shelf with a new-chapter badge when signed in',
|
||||
manga_cover_image_path: null,
|
||||
chapter_id: 'c1',
|
||||
chapter_number: 3,
|
||||
chapter_page_count: 20,
|
||||
page: 4,
|
||||
updated_at: '2026-01-01T00:00:00Z',
|
||||
new_chapters_count: 2
|
||||
@@ -65,6 +66,40 @@ test('shows the continue-reading shelf with a new-chapter badge when signed in',
|
||||
await expect(page.getByTestId('continue-new-badge-m1')).toContainText('2');
|
||||
});
|
||||
|
||||
test('keeps finished series off the shelf but shows in-progress ones', async ({ page }) => {
|
||||
await mockCommon(page);
|
||||
await page.route('**/api/v1/auth/me', (route) =>
|
||||
route.fulfill({ status: 200, contentType: 'application/json', body: JSON.stringify({ user: { id: 'u1', username: 'reader', is_admin: false } }) })
|
||||
);
|
||||
await page.route('**/api/v1/me/read-progress*', (route) =>
|
||||
route.fulfill({
|
||||
status: 200,
|
||||
contentType: 'application/json',
|
||||
body: JSON.stringify({
|
||||
items: [
|
||||
// Finished: last page of the latest chapter, nothing new.
|
||||
{
|
||||
manga_id: 'done', manga_title: 'Finished', manga_cover_image_path: null,
|
||||
chapter_id: 'dc', chapter_number: 5, chapter_page_count: 10, page: 10,
|
||||
updated_at: '2026-01-02T00:00:00Z', new_chapters_count: 0
|
||||
},
|
||||
// In progress: mid-chapter.
|
||||
{
|
||||
manga_id: 'wip', manga_title: 'Ongoing', manga_cover_image_path: null,
|
||||
chapter_id: 'wc', chapter_number: 2, chapter_page_count: 10, page: 3,
|
||||
updated_at: '2026-01-01T00:00:00Z', new_chapters_count: 0
|
||||
}
|
||||
],
|
||||
page: { limit: 50, offset: 0, total: 2 }
|
||||
})
|
||||
})
|
||||
);
|
||||
|
||||
await page.goto('/');
|
||||
await expect(page.getByTestId('continue-card-wip')).toBeVisible();
|
||||
await expect(page.getByTestId('continue-card-done')).toHaveCount(0);
|
||||
});
|
||||
|
||||
test('hides the continue-reading shelf for anonymous visitors', async ({ page }) => {
|
||||
await mockCommon(page);
|
||||
await page.route('**/api/v1/auth/me', (route) =>
|
||||
|
||||
4
frontend/package-lock.json
generated
4
frontend/package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "mangalord-frontend",
|
||||
"version": "0.103.0",
|
||||
"version": "0.104.0",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "mangalord-frontend",
|
||||
"version": "0.103.0",
|
||||
"version": "0.104.0",
|
||||
"devDependencies": {
|
||||
"@lucide/svelte": "^1.16.0",
|
||||
"@playwright/test": "^1.48.0",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "mangalord-frontend",
|
||||
"version": "0.103.0",
|
||||
"version": "0.104.0",
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
|
||||
@@ -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