mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 09:19:56 -05:00
Feat: Shift from Stable to Preview (WIP)
This commit is contained in:
@@ -114,6 +114,7 @@ export function removeRecord(
|
||||
}
|
||||
|
||||
export interface SyncBackOptions {
|
||||
threshold: number | null;
|
||||
respectScanlatorFilter: boolean;
|
||||
chapterPrefs: ChapterDisplayPrefs;
|
||||
}
|
||||
@@ -123,36 +124,30 @@ export async function syncBackFromTracker(
|
||||
chapters: Chapter[],
|
||||
opts: SyncBackOptions,
|
||||
gqlFn: (query: string, vars: Record<string, unknown>) => Promise<unknown>,
|
||||
): Promise<{ markedRead: number[]; markedUnread: number[] }> {
|
||||
const eligible = buildChapterList(
|
||||
opts.respectScanlatorFilter ? buildChapterList(chapters, opts.chapterPrefs) : chapters,
|
||||
{ ...opts.chapterPrefs, sortDir: "asc" },
|
||||
);
|
||||
): Promise<number[]> {
|
||||
const base = opts.respectScanlatorFilter
|
||||
? buildChapterList(chapters, opts.chapterPrefs)
|
||||
: chapters;
|
||||
const eligible = buildChapterList(base, { ...opts.chapterPrefs, sortDir: "asc" });
|
||||
|
||||
const toMarkRead: number[] = [];
|
||||
const toMarkUnread: number[] = [];
|
||||
const toMarkRead: number[] = [];
|
||||
|
||||
for (const record of records) {
|
||||
const remote = record.lastChapterRead;
|
||||
if (!remote || remote <= 0) continue;
|
||||
|
||||
const position = Math.round(remote);
|
||||
const below = eligible.slice(0, position);
|
||||
const above = eligible.slice(position);
|
||||
|
||||
toMarkRead.push(...below.filter(c => !c.isRead).map(c => c.id));
|
||||
toMarkUnread.push(...above.filter(c => c.isRead).map(c => c.id));
|
||||
for (const chapter of eligible) {
|
||||
if (chapter.isRead) continue;
|
||||
const diff = Math.abs(chapter.chapterNumber - remote);
|
||||
if (opts.threshold !== null && diff > opts.threshold) continue;
|
||||
if (chapter.chapterNumber <= remote) toMarkRead.push(chapter.id);
|
||||
}
|
||||
}
|
||||
|
||||
const readIds = [...new Set(toMarkRead)];
|
||||
const unreadIds = [...new Set(toMarkUnread)];
|
||||
|
||||
if (readIds.length > 0) {
|
||||
await gqlFn(MARK_CHAPTERS_READ, { ids: readIds, isRead: true });
|
||||
}
|
||||
if (unreadIds.length > 0) {
|
||||
await gqlFn(MARK_CHAPTERS_READ, { ids: unreadIds, isRead: false });
|
||||
const ids = [...new Set(toMarkRead)];
|
||||
if (ids.length > 0) {
|
||||
await gqlFn(MARK_CHAPTERS_READ, { ids, isRead: true });
|
||||
}
|
||||
|
||||
return { markedRead: readIds, markedUnread: unreadIds };
|
||||
return ids;
|
||||
}
|
||||
@@ -2,7 +2,6 @@ import { gql } from "@api/client";
|
||||
import { GET_MANGA_TRACK_RECORDS, GET_ALL_TRACKER_RECORDS } from "@api/queries/tracking";
|
||||
import { GET_CHAPTERS } from "@api/queries/chapters";
|
||||
import { UPDATE_TRACK, FETCH_TRACK, UNBIND_TRACK } from "@api/mutations/tracking";
|
||||
import { MARK_CHAPTERS_READ } from "@api/mutations/chapters";
|
||||
import { buildChapterList, type ChapterDisplayPrefs } from "@features/series/lib/chapterList";
|
||||
import { syncBackFromTracker } from "@features/tracking/lib/trackingSync";
|
||||
import { store } from "@store/state.svelte";
|
||||
@@ -82,7 +81,7 @@ class TrackingState {
|
||||
for (const tracker of res.trackers.nodes.filter(t => t.isLoggedIn)) {
|
||||
for (const record of tracker.trackRecords.nodes) {
|
||||
if (!record.manga?.id) continue;
|
||||
const mangaId = record.manga.id;
|
||||
const mangaId = record.manga.id;
|
||||
const existing = this.byManga.get(mangaId) ?? [];
|
||||
const merged = [...existing.filter(r => r.id !== record.id), record];
|
||||
this.setFor(mangaId, merged);
|
||||
@@ -140,21 +139,22 @@ class TrackingState {
|
||||
const fresh = res.fetchTrack.trackRecord;
|
||||
this.patchFor(mangaId, fresh);
|
||||
|
||||
const { markedRead } = await this._applyRemoteProgress(fresh, chapters, prefs);
|
||||
return { fresh, markedIds: markedRead };
|
||||
const markedIds = await this._applyRemoteProgress(fresh, chapters, prefs);
|
||||
return { fresh, markedIds };
|
||||
}
|
||||
|
||||
private async _applyRemoteProgress(
|
||||
record: TrackRecord,
|
||||
chapters: Chapter[],
|
||||
prefs: ChapterDisplayPrefs,
|
||||
): Promise<{ markedRead: number[]; markedUnread: number[] }> {
|
||||
if (!store.settings.trackerSyncBack) return { markedRead: [], markedUnread: [] };
|
||||
): Promise<number[]> {
|
||||
if (!store.settings.trackerSyncBack) return [];
|
||||
|
||||
return syncBackFromTracker(
|
||||
[record],
|
||||
chapters,
|
||||
{
|
||||
threshold: store.settings.trackerSyncBackThreshold ?? null,
|
||||
respectScanlatorFilter: store.settings.trackerRespectScanlatorFilter ?? true,
|
||||
chapterPrefs: prefs,
|
||||
},
|
||||
@@ -290,6 +290,7 @@ class TrackingState {
|
||||
freshRecords,
|
||||
chapters,
|
||||
{
|
||||
threshold: store.settings.trackerSyncBackThreshold ?? null,
|
||||
respectScanlatorFilter: store.settings.trackerRespectScanlatorFilter ?? true,
|
||||
chapterPrefs: prefs,
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user