Chore: Port over Settings (Barely Works)

This commit is contained in:
Youwes09
2026-05-24 20:31:46 -05:00
parent ae5d9748c7
commit d9a9427e3b
87 changed files with 8821 additions and 615 deletions
+42 -2
View File
@@ -1,4 +1,6 @@
import type { Tracker } from '$lib/types'
import type { Tracker, TrackRecord } from '$lib/types'
import type { Chapter } from '$lib/types/chapter'
import type { MangaPrefs } from '$lib/types/settings'
export const trackingState = $state({
trackers: [] as Tracker[],
@@ -13,4 +15,42 @@ export const trackingState = $state({
searchResults: [] as unknown[],
searchLoading: false,
searchError: null as string | null,
})
})
export async function syncBackFromTracker(
records: TrackRecord[],
chapters: Chapter[],
opts: {
threshold: number | null
respectScanlatorFilter: boolean
chapterPrefs: Partial<MangaPrefs>
},
markChaptersRead: (ids: string[], read: boolean) => Promise<void>,
): Promise<Chapter[]> {
const marked: Chapter[] = []
const activeScanlators: string[] | null =
opts.respectScanlatorFilter && opts.chapterPrefs.scanlatorFilter?.length
? opts.chapterPrefs.scanlatorFilter
: null
for (const record of records) {
const lastRead = record.lastChapterRead ?? 0
if (lastRead <= 0) continue
const toMark = chapters.filter(ch => {
if (ch.read) return false
if (activeScanlators && ch.scanlator && !activeScanlators.includes(ch.scanlator)) return false
return opts.threshold !== null
? ch.chapterNumber <= lastRead && ch.chapterNumber >= lastRead - opts.threshold
: ch.chapterNumber <= lastRead
})
if (toMark.length === 0) continue
await markChaptersRead(toMark.map(ch => String(ch.id)), true)
marked.push(...toMark)
}
return marked
}