refactor(series): drop the TS rendering twin; library switch navigates SSR
web/src/series.ts carried a full TypeScript twin of the templ page — cards and paginator rendered via innerHTML from /api/series JSON, always hardcoded to page 1. Combined with the header restore dispatch (previous commit) it made every /series load stomp server-rendered pagination back to page 1, which is the paginator bug reported on prod (9 pages of series, Next kept landing on page 1, per-library only). Rendering ownership (AGENTS.md): this page now has NO client renderer. - grid and paginator are rendered only by templates/series.templ - a library switch is a plain SSR navigation to /series?library_id=...&page=1, keeping the URL the single source of truth for both library and page state - drops the duplicate /api/series fetch that ran on every page load rendering-allowlist.txt: series.ts baseline entry removed — the file no longer builds HTML anywhere.
This commit is contained in:
1 parent
202a090811
commit
3daa834a94
2 files changed
+12
-119
No files matched your search
@@ -20,7 +20,6 @@ web/src/dom.ts:1
|
|||||||
web/src/password_validation.ts:1
|
web/src/password_validation.ts:1
|
||||||
web/src/queue.ts:3
|
web/src/queue.ts:3
|
||||||
web/src/search.ts:4
|
web/src/search.ts:4
|
||||||
web/src/series.ts:1
|
|
||||||
web/src/setup.ts:1
|
web/src/setup.ts:1
|
||||||
web/src/stats.ts:9
|
web/src/stats.ts:9
|
||||||
web/src/toast.ts:2
|
web/src/toast.ts:2
|
||||||
|
|||||||
+12
-118
@@ -1,128 +1,22 @@
|
|||||||
import { Alpine } from "./alpine";
|
import { Alpine } from "./alpine";
|
||||||
import { showToast } from "./toast";
|
import { initLibrarySwitcher } from "./library-switcher";
|
||||||
import { initLibrarySwitcher, switchWithTransition } from "./library-switcher";
|
|
||||||
|
|
||||||
interface SeriesItem {
|
// Rendering ownership (AGENTS.md): the series grid and its paginator are
|
||||||
name: string;
|
// rendered by templates/series.templ. This page intentionally has NO
|
||||||
library_id: string;
|
// TypeScript renderer — the old one here duplicated the templ markup via
|
||||||
book_count: number;
|
// innerHTML and re-fetched at hardcoded page 1, stomping SSR pagination
|
||||||
total_in_series: number;
|
// whenever the header's library restore fired. A library switch is a plain
|
||||||
cover_paths: string[];
|
// SSR navigation so the URL stays the single source of truth for
|
||||||
last_entry_at: string;
|
// library_id and page state.
|
||||||
}
|
function navigateToSeries(libraryId: string): void {
|
||||||
|
const param = libraryId ? `library_id=${encodeURIComponent(libraryId)}&` : "";
|
||||||
function renderSeriesCard(series: SeriesItem): string {
|
window.location.href = `/series?${param}page=1`;
|
||||||
const href = `/series/detail?name=${encodeURIComponent(series.name)}&library_id=${encodeURIComponent(series.library_id ?? "")}`;
|
|
||||||
const coverCount = series.cover_paths.length;
|
|
||||||
const coverClass = `cover-count-${coverCount}`;
|
|
||||||
|
|
||||||
let coversHtml = "";
|
|
||||||
for (let i = 0; i < coverCount; i++) {
|
|
||||||
coversHtml += `<img src="${series.cover_paths[i]}" class="cover-img cover-${i}" alt="${series.name}" loading="lazy" onerror="this.src='/static/placeholder-book.svg'">`;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (coverCount === 0) {
|
|
||||||
coversHtml = `<div class="cover-img cover-0 flex items-center justify-center" style="background: var(--bg-primary);"><span class="text-3xl">📚</span></div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `
|
|
||||||
<a href="${href}" class="block">
|
|
||||||
<div class="series-card rounded-lg overflow-hidden cursor-pointer hover:shadow-lg transition-shadow" style="background-color: var(--bg-secondary);">
|
|
||||||
<div class="stacked-covers ${coverClass}">
|
|
||||||
${coversHtml}
|
|
||||||
</div>
|
|
||||||
<div class="series-card-info px-3 py-2">
|
|
||||||
<h3 class="font-semibold text-sm line-clamp-2" style="color: var(--text-primary)">${series.name}</h3>
|
|
||||||
<p class="text-xs mt-1" style="color: var(--text-secondary)">
|
|
||||||
${series.book_count} of ${series.total_in_series} books
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</a>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSeriesContent(
|
|
||||||
seriesList: SeriesItem[],
|
|
||||||
libraryId: string,
|
|
||||||
totalPages: number,
|
|
||||||
currentPage: number,
|
|
||||||
): string {
|
|
||||||
if (seriesList.length === 0) {
|
|
||||||
return `
|
|
||||||
<main class="w-full px-4 py-8">
|
|
||||||
<h1 class="text-3xl font-bold mb-6" style="color: var(--text-primary)">Series</h1>
|
|
||||||
<div class="text-center py-16" style="color: var(--text-secondary)">
|
|
||||||
<div class="text-6xl mb-4">📚</div>
|
|
||||||
<h3 class="text-xl font-semibold mb-2" style="color: var(--text-primary)">No Series Found</h3>
|
|
||||||
<p>Books with series metadata will appear here</p>
|
|
||||||
</div>
|
|
||||||
</main>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const cardsHtml = seriesList.map((s) => renderSeriesCard(s)).join("");
|
|
||||||
|
|
||||||
let paginationHtml = "";
|
|
||||||
if (totalPages > 1) {
|
|
||||||
const libParam = libraryId ? `library_id=${libraryId}&` : "";
|
|
||||||
const prevLink =
|
|
||||||
currentPage > 1
|
|
||||||
? `<a href="/series?${libParam}page=${currentPage - 1}" class="px-4 py-2 rounded-lg border" style="border-color: var(--border); color: var(--text-primary);">← Previous</a>`
|
|
||||||
: "";
|
|
||||||
const nextLink =
|
|
||||||
currentPage < totalPages
|
|
||||||
? `<a href="/series?${libParam}page=${currentPage + 1}" class="px-4 py-2 rounded-lg border" style="border-color: var(--border); color: var(--text-primary);">Next →</a>`
|
|
||||||
: "";
|
|
||||||
paginationHtml = `
|
|
||||||
<div class="flex justify-center items-center gap-4 mt-8">
|
|
||||||
${prevLink}
|
|
||||||
<span class="text-sm" style="color: var(--text-secondary)">Page ${currentPage} of ${totalPages}</span>
|
|
||||||
${nextLink}
|
|
||||||
</div>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return `
|
|
||||||
<main class="w-full px-4 py-8">
|
|
||||||
<h1 class="text-3xl font-bold mb-6" style="color: var(--text-primary)">Series</h1>
|
|
||||||
<div class="grid grid-cols-2 md:grid-cols-4 lg:grid-cols-6 gap-6">
|
|
||||||
${cardsHtml}
|
|
||||||
</div>
|
|
||||||
${paginationHtml}
|
|
||||||
</main>`;
|
|
||||||
}
|
|
||||||
|
|
||||||
async function switchLibrary(libraryId: string): Promise<void> {
|
|
||||||
await switchWithTransition("series-container", async () => {
|
|
||||||
const param = libraryId ? `library_id=${libraryId}&` : "";
|
|
||||||
const response = await fetch(
|
|
||||||
`/api/series?${param}limit=24&offset=0`,
|
|
||||||
{
|
|
||||||
headers: {
|
|
||||||
Authorization: `Bearer ${localStorage.getItem("token")}`,
|
|
||||||
"Content-Type": "application/json",
|
|
||||||
},
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error("Failed to load series");
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
|
||||||
const seriesList: SeriesItem[] = data.series || [];
|
|
||||||
const total: number = data.total || 0;
|
|
||||||
const totalPages = Math.max(1, Math.ceil(total / 24));
|
|
||||||
|
|
||||||
const container = document.getElementById("series-container");
|
|
||||||
if (container) {
|
|
||||||
container.innerHTML = renderSeriesContent(seriesList, libraryId, totalPages, 1);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Alpine.data("seriesPage", () => ({
|
Alpine.data("seriesPage", () => ({
|
||||||
initSeriesPage() {
|
initSeriesPage() {
|
||||||
initLibrarySwitcher({
|
initLibrarySwitcher({
|
||||||
onSwitch: switchLibrary,
|
onSwitch: navigateToSeries,
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
}));
|
}));
|
||||||
Reference in new issue
Block a user