mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-14 01:39:56 -05:00
Chore: Port over SeriesDetail (WIP Panels)
This commit is contained in:
@@ -1,13 +1,25 @@
|
||||
import { appState } from '$lib/state/app.svelte'
|
||||
import { settingsState, updateSettings } from '$lib/state/settings.svelte'
|
||||
import type { Manga } from '$lib/types'
|
||||
|
||||
export function autoLinkLibrary(focal: Manga, allManga: Manga[]): Promise<number> {
|
||||
function linkManga(focalId: number, targetId: number) {
|
||||
const existing = settingsState.settings.mangaLinks?.[focalId] ?? []
|
||||
if (existing.includes(targetId)) return
|
||||
updateSettings({
|
||||
mangaLinks: {
|
||||
...settingsState.settings.mangaLinks,
|
||||
[focalId]: [...existing, targetId],
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function autoLinkLibrary(focal: Manga | null | undefined, allManga: Manga[]): Promise<number> {
|
||||
if (!focal) return Promise.resolve(0)
|
||||
return new Promise(resolve => {
|
||||
const worker = new Worker(new URL('./autoLinkWorker.ts', import.meta.url), { type: 'module' })
|
||||
|
||||
worker.onmessage = (e: MessageEvent<number[]>) => {
|
||||
const matches = e.data
|
||||
for (const id of matches) appState.linkManga(focal.id, id)
|
||||
for (const id of matches) linkManga(focal.id, id)
|
||||
worker.terminate()
|
||||
resolve(matches.length)
|
||||
}
|
||||
@@ -18,7 +30,7 @@ export function autoLinkLibrary(focal: Manga, allManga: Manga[]): Promise<number
|
||||
focalTitle: focal.title,
|
||||
focalId: focal.id,
|
||||
allManga: allManga.map(m => ({ id: m.id, title: m.title })),
|
||||
linkedIds: appState.settings.mangaLinks?.[focal.id] ?? [],
|
||||
linkedIds: settingsState.settings.mangaLinks?.[focal.id] ?? [],
|
||||
})
|
||||
})
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { appState } from '$lib/state/app.svelte'
|
||||
import { settingsState } from '$lib/state/settings.svelte'
|
||||
import { seriesState } from '$lib/state/series.svelte'
|
||||
import { searchWithScore } from '$lib/core/algorithms/search'
|
||||
import { getHash, areDuplicates } from '$lib/core/cover/coverHash'
|
||||
|
||||
@@ -24,7 +25,7 @@ function normalizeUrl(url: string): string {
|
||||
}
|
||||
|
||||
export function resolvedCover(mangaId: number, ownUrl: string): string {
|
||||
return appState.settings.mangaPrefs?.[mangaId]?.coverUrl ?? ownUrl
|
||||
return settingsState.settings.mangaPrefs?.[mangaId]?.coverUrl ?? ownUrl
|
||||
}
|
||||
|
||||
function fuzzyMatchIds(
|
||||
@@ -47,9 +48,9 @@ export function coverCandidatesSync(
|
||||
ownUrl: string,
|
||||
mangaById: Map<number, CoverManga & { title: string }>,
|
||||
): CoverCandidate[] {
|
||||
const linkedIds = appState.getLinkedMangaIds(mangaId)
|
||||
const linkedIds = seriesState.settings.mangaLinks?.[mangaId] ?? []
|
||||
const fuzzyIds = fuzzyMatchIds(mangaId, title, mangaById)
|
||||
const current = appState.settings.mangaPrefs?.[mangaId]?.coverUrl ?? ownUrl
|
||||
const current = settingsState.settings.mangaPrefs?.[mangaId]?.coverUrl ?? ownUrl
|
||||
const allIds = Array.from(new Set([...linkedIds, ...fuzzyIds]))
|
||||
|
||||
const raw: { mangaId: number; url: string; label: string }[] = [
|
||||
|
||||
Reference in New Issue
Block a user