Chore: Port over SeriesDetail (WIP Panels)

This commit is contained in:
Youwes09
2026-05-28 23:05:02 -05:00
parent 584b917f98
commit 8c250021a0
53 changed files with 4570 additions and 885 deletions
+53 -43
View File
@@ -1,57 +1,67 @@
import { getAdapter } from '$lib/request-manager'
import { seriesState } from '$lib/state/series.svelte'
import { readerState } from '$lib/state/reader.svelte'
import { getAdapter } from "$lib/request-manager";
import { seriesState } from "$lib/state/series.svelte";
import { readerState } from "$lib/state/reader.svelte";
import type { Chapter } from "$lib/types";
export async function loadChapters(mangaId: string) {
seriesState.chaptersLoading = true
seriesState.chaptersError = null
try {
seriesState.chapters = await getAdapter().getChapters(mangaId)
} catch (e) {
seriesState.chaptersError = String(e)
} finally {
seriesState.chaptersLoading = false
}
export async function getChapters(mangaId: number, signal?: AbortSignal): Promise<Chapter[]> {
return getAdapter().getChapters(String(mangaId), signal);
}
export async function fetchChapters(mangaId: string) {
seriesState.chaptersLoading = true
seriesState.chaptersError = null
export async function fetchChapters(mangaId: number, signal?: AbortSignal): Promise<Chapter[]> {
return getAdapter().fetchChapters(String(mangaId), signal);
}
export async function loadChapters(mangaId: string) {
seriesState.chaptersLoading = true;
seriesState.chaptersError = null;
try {
seriesState.chapters = await getAdapter().fetchChapters(mangaId)
seriesState.chapters = await getAdapter().getChapters(mangaId);
} catch (e) {
seriesState.chaptersError = String(e)
seriesState.chaptersError = String(e);
} finally {
seriesState.chaptersLoading = false
seriesState.chaptersLoading = false;
}
}
export async function loadChapterPages(chapterId: string, signal?: AbortSignal) {
readerState.pagesLoading = true
readerState.pagesError = null
readerState.pagesLoading = true;
readerState.pagesError = null;
try {
readerState.pages = await getAdapter().getChapterPages(chapterId, signal)
readerState.pages = await getAdapter().getChapterPages(chapterId, signal);
} catch (e) {
if (e instanceof DOMException && e.name === 'AbortError') return
readerState.pagesError = String(e)
if (e instanceof DOMException && e.name === "AbortError") return;
readerState.pagesError = String(e);
} finally {
readerState.pagesLoading = false
readerState.pagesLoading = false;
}
}
export async function markChapterRead(id: number, read: boolean) {
await getAdapter().markChapterRead(String(id), read);
const chapter = seriesState.chapters.find(c => c.id === id);
if (chapter) chapter.read = read;
}
export async function markChaptersRead(ids: number[], read: boolean) {
await getAdapter().markChaptersRead(ids.map(String), read);
const idSet = new Set(ids);
for (const c of seriesState.chapters) {
if (idSet.has(c.id)) c.read = read;
}
}
export async function markRead(id: string, read: boolean) {
await getAdapter().markChapterRead(id, read)
// chapter.id is a number; route params arrive as strings — compare via Number()
const numId = Number(id)
const chapter = seriesState.chapters.find(c => c.id === numId)
if (chapter) chapter.read = read
await getAdapter().markChapterRead(id, read);
const numId = Number(id);
const chapter = seriesState.chapters.find(c => c.id === numId);
if (chapter) chapter.read = read;
}
export async function markManyRead(ids: string[], read: boolean) {
await getAdapter().markChaptersRead(ids, read)
const numIds = new Set(ids.map(Number))
await getAdapter().markChaptersRead(ids, read);
const numIds = new Set(ids.map(Number));
for (const c of seriesState.chapters) {
if (numIds.has(c.id)) c.read = read
if (numIds.has(c.id)) c.read = read;
}
}
@@ -59,20 +69,20 @@ export async function updateChaptersProgress(
ids: string[],
patch: { isRead?: boolean; isBookmarked?: boolean; lastPageRead?: number },
) {
await getAdapter().updateChaptersProgress(ids, patch)
const numIds = new Set(ids.map(Number))
await getAdapter().updateChaptersProgress(ids, patch);
const numIds = new Set(ids.map(Number));
for (const c of seriesState.chapters) {
if (!numIds.has(c.id)) continue
if (patch.isRead !== undefined) c.read = patch.isRead
if (patch.isBookmarked !== undefined) c.bookmarked = patch.isBookmarked
if (patch.lastPageRead !== undefined) c.lastPageRead = patch.lastPageRead
if (!numIds.has(c.id)) continue;
if (patch.isRead !== undefined) c.read = patch.isRead;
if (patch.isBookmarked !== undefined) c.bookmarked = patch.isBookmarked;
if (patch.lastPageRead !== undefined) c.lastPageRead = patch.lastPageRead;
}
}
export async function deleteDownloadedChapters(ids: string[]) {
await getAdapter().deleteDownloadedChapters(ids)
const numIds = new Set(ids.map(Number))
export async function deleteDownloadedChapters(ids: number[]) {
await getAdapter().deleteDownloadedChapters(ids.map(String));
const idSet = new Set(ids);
for (const c of seriesState.chapters) {
if (numIds.has(c.id)) c.downloaded = false
if (idSet.has(c.id)) c.downloaded = false;
}
}