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:
2
backend/Cargo.lock
generated
2
backend/Cargo.lock
generated
@@ -1558,7 +1558,7 @@ checksum = "c41e0c4fef86961ac6d6f8a82609f55f31b05e4fce149ac5710e439df7619ba4"
|
|||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "mangalord"
|
name = "mangalord"
|
||||||
version = "0.103.0"
|
version = "0.104.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"argon2",
|
"argon2",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
[package]
|
[package]
|
||||||
name = "mangalord"
|
name = "mangalord"
|
||||||
version = "0.103.0"
|
version = "0.104.0"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
default-run = "mangalord"
|
default-run = "mangalord"
|
||||||
|
|
||||||
|
|||||||
@@ -24,6 +24,11 @@ pub struct ReadProgressSummary {
|
|||||||
/// `None` when the chapter was deleted after this row was written
|
/// `None` when the chapter was deleted after this row was written
|
||||||
/// (FK ON DELETE SET NULL on `chapter_id`).
|
/// (FK ON DELETE SET NULL on `chapter_id`).
|
||||||
pub chapter_number: Option<i32>,
|
pub chapter_number: Option<i32>,
|
||||||
|
/// Page count of the last-read chapter (`None` when unknown / deleted).
|
||||||
|
/// Lets a client distinguish a finished series (read to the last page,
|
||||||
|
/// nothing new) from one still in progress — e.g. to keep finished
|
||||||
|
/// series off a "Continue reading" shelf.
|
||||||
|
pub chapter_page_count: Option<i32>,
|
||||||
pub page: i32,
|
pub page: i32,
|
||||||
pub updated_at: DateTime<Utc>,
|
pub updated_at: DateTime<Utc>,
|
||||||
/// How many chapters sit past the reader's last-read chapter (by
|
/// How many chapters sit past the reader's last-read chapter (by
|
||||||
|
|||||||
@@ -141,6 +141,7 @@ pub async fn list_for_user(
|
|||||||
m.cover_image_path AS manga_cover_image_path,
|
m.cover_image_path AS manga_cover_image_path,
|
||||||
rp.chapter_id,
|
rp.chapter_id,
|
||||||
c.number AS chapter_number,
|
c.number AS chapter_number,
|
||||||
|
c.page_count AS chapter_page_count,
|
||||||
rp.page,
|
rp.page,
|
||||||
rp.updated_at,
|
rp.updated_at,
|
||||||
-- Personal "new since last read": how many distinct chapter
|
-- Personal "new since last read": how many distinct chapter
|
||||||
|
|||||||
@@ -191,6 +191,32 @@ async fn list_reports_new_chapters_since_last_read(pool: PgPool) {
|
|||||||
assert_eq!(body["items"][0]["new_chapters_count"], 2);
|
assert_eq!(body["items"][0]["new_chapters_count"], 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[sqlx::test(migrations = "./migrations")]
|
||||||
|
async fn list_reports_last_read_chapter_page_count(pool: PgPool) {
|
||||||
|
let h = common::harness(pool);
|
||||||
|
let (_, cookie) = common::register_user(&h.app).await;
|
||||||
|
let manga_id = common::seed_manga_via_api(&h.app, &cookie, "Berserk").await;
|
||||||
|
// seed_chapter uploads a single page, so page_count is 1.
|
||||||
|
let ch1 = seed_chapter(&h.app, &cookie, manga_id, 1).await;
|
||||||
|
let _ = upsert_progress(
|
||||||
|
&h.app,
|
||||||
|
&cookie,
|
||||||
|
json!({ "manga_id": manga_id.to_string(), "chapter_id": ch1, "page": 1 }),
|
||||||
|
)
|
||||||
|
.await;
|
||||||
|
|
||||||
|
let resp = h
|
||||||
|
.app
|
||||||
|
.clone()
|
||||||
|
.oneshot(common::get_with_cookie("/api/v1/me/read-progress", &cookie))
|
||||||
|
.await
|
||||||
|
.unwrap();
|
||||||
|
let body = common::body_json(resp).await;
|
||||||
|
// Exposes the last-read chapter's page count so a client can tell a
|
||||||
|
// finished series (on the last page) from one still in progress.
|
||||||
|
assert_eq!(body["items"][0]["chapter_page_count"], 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[sqlx::test(migrations = "./migrations")]
|
#[sqlx::test(migrations = "./migrations")]
|
||||||
async fn list_new_chapters_count_is_zero_at_latest_chapter(pool: PgPool) {
|
async fn list_new_chapters_count_is_zero_at_latest_chapter(pool: PgPool) {
|
||||||
let h = common::harness(pool);
|
let h = common::harness(pool);
|
||||||
|
|||||||
@@ -47,6 +47,7 @@ test('shows the continue-reading shelf with a new-chapter badge when signed in',
|
|||||||
manga_cover_image_path: null,
|
manga_cover_image_path: null,
|
||||||
chapter_id: 'c1',
|
chapter_id: 'c1',
|
||||||
chapter_number: 3,
|
chapter_number: 3,
|
||||||
|
chapter_page_count: 20,
|
||||||
page: 4,
|
page: 4,
|
||||||
updated_at: '2026-01-01T00:00:00Z',
|
updated_at: '2026-01-01T00:00:00Z',
|
||||||
new_chapters_count: 2
|
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');
|
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 }) => {
|
test('hides the continue-reading shelf for anonymous visitors', async ({ page }) => {
|
||||||
await mockCommon(page);
|
await mockCommon(page);
|
||||||
await page.route('**/api/v1/auth/me', (route) =>
|
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",
|
"name": "mangalord-frontend",
|
||||||
"version": "0.103.0",
|
"version": "0.104.0",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
"": {
|
"": {
|
||||||
"name": "mangalord-frontend",
|
"name": "mangalord-frontend",
|
||||||
"version": "0.103.0",
|
"version": "0.104.0",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@lucide/svelte": "^1.16.0",
|
"@lucide/svelte": "^1.16.0",
|
||||||
"@playwright/test": "^1.48.0",
|
"@playwright/test": "^1.48.0",
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "mangalord-frontend",
|
"name": "mangalord-frontend",
|
||||||
"version": "0.103.0",
|
"version": "0.104.0",
|
||||||
"private": true,
|
"private": true,
|
||||||
"type": "module",
|
"type": "module",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ export type ReadProgressSummary = {
|
|||||||
chapter_id: string | null;
|
chapter_id: string | null;
|
||||||
/** `null` if the chapter was deleted after the progress was written. */
|
/** `null` if the chapter was deleted after the progress was written. */
|
||||||
chapter_number: number | null;
|
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;
|
page: number;
|
||||||
updated_at: string;
|
updated_at: string;
|
||||||
/** Chapters past the reader's last-read chapter — a personal "new
|
/** 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,
|
manga_cover_image_path: null,
|
||||||
chapter_id: 'c1',
|
chapter_id: 'c1',
|
||||||
chapter_number: 3,
|
chapter_number: 3,
|
||||||
|
chapter_page_count: 20,
|
||||||
page: 3,
|
page: 3,
|
||||||
updated_at: '2026-01-01T00:00:00Z',
|
updated_at: '2026-01-01T00:00:00Z',
|
||||||
new_chapters_count: 0,
|
new_chapters_count: 0,
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ function entry(over: Partial<ReadProgressSummary> = {}): ReadProgressSummary {
|
|||||||
manga_cover_image_path: null,
|
manga_cover_image_path: null,
|
||||||
chapter_id: 'c1',
|
chapter_id: 'c1',
|
||||||
chapter_number: 5,
|
chapter_number: 5,
|
||||||
|
chapter_page_count: 10,
|
||||||
page: 1,
|
page: 1,
|
||||||
updated_at: '2026-01-02T00:00:00Z',
|
updated_at: '2026-01-02T00:00:00Z',
|
||||||
new_chapters_count: 0,
|
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,
|
listMyReadProgressOrEmpty,
|
||||||
type ReadProgressSummary
|
type ReadProgressSummary
|
||||||
} from '$lib/api/read_progress';
|
} from '$lib/api/read_progress';
|
||||||
|
import { isCaughtUp } from '$lib/continueReading';
|
||||||
import Chip from '$lib/components/Chip.svelte';
|
import Chip from '$lib/components/Chip.svelte';
|
||||||
import ContinueReadingShelf from '$lib/components/ContinueReadingShelf.svelte';
|
import ContinueReadingShelf from '$lib/components/ContinueReadingShelf.svelte';
|
||||||
import MangaCard from '$lib/components/MangaCard.svelte';
|
import MangaCard from '$lib/components/MangaCard.svelte';
|
||||||
@@ -312,7 +313,9 @@
|
|||||||
// empty for guests (401 swallowed), which hides the shelf.
|
// empty for guests (401 swallowed), which hides the shelf.
|
||||||
try {
|
try {
|
||||||
const progress = await listMyReadProgressOrEmpty();
|
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 {
|
} catch {
|
||||||
// Never let a history hiccup break the catalogue — leave the
|
// Never let a history hiccup break the catalogue — leave the
|
||||||
// shelf hidden.
|
// shelf hidden.
|
||||||
|
|||||||
Reference in New Issue
Block a user