mirror of
https://github.com/moku-project/Moku.git
synced 2026-06-13 01:09:56 -05:00
Fix updates page data flow
This commit is contained in:
@@ -33,11 +33,15 @@
|
|||||||
ctrl?.abort();
|
ctrl?.abort();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
function fetchedAtMs(item: Pick<RecentUpdate, "fetchedAt">): number {
|
||||||
|
const ts = item.fetchedAt ? new Date(item.fetchedAt).getTime() : Date.now();
|
||||||
|
return Number.isFinite(ts) ? ts : Date.now();
|
||||||
|
}
|
||||||
|
|
||||||
const groups = $derived.by(() => {
|
const groups = $derived.by(() => {
|
||||||
const map = new Map<string, RecentUpdate[]>();
|
const map = new Map<string, RecentUpdate[]>();
|
||||||
for (const item of updates) {
|
for (const item of updates) {
|
||||||
const ts = item.fetchedAt ? new Date(item.fetchedAt).getTime() : 0;
|
const label = dayLabel(fetchedAtMs(item));
|
||||||
const label = dayLabel(Number.isFinite(ts) ? ts : 0);
|
|
||||||
if (!map.has(label)) map.set(label, []);
|
if (!map.has(label)) map.set(label, []);
|
||||||
map.get(label)!.push(item);
|
map.get(label)!.push(item);
|
||||||
}
|
}
|
||||||
@@ -61,23 +65,24 @@
|
|||||||
|
|
||||||
async function loadUpdates() {
|
async function loadUpdates() {
|
||||||
ctrl?.abort();
|
ctrl?.abort();
|
||||||
ctrl = new AbortController();
|
const nextCtrl = new AbortController();
|
||||||
|
ctrl = nextCtrl;
|
||||||
loading = true;
|
loading = true;
|
||||||
error = null;
|
error = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await gql<{ chapters: { nodes: RecentUpdate[] } }>(GET_RECENTLY_UPDATED, {}, ctrl.signal);
|
const res = await gql<{ chapters: { nodes: RecentUpdate[] } }>(GET_RECENTLY_UPDATED, {}, nextCtrl.signal);
|
||||||
if (ctrl.signal.aborted) return;
|
if (nextCtrl.signal.aborted) return;
|
||||||
|
|
||||||
updates = res.chapters.nodes
|
updates = res.chapters.nodes
|
||||||
.filter(item => item.manga?.inLibrary)
|
.filter(item => item.manga?.inLibrary)
|
||||||
.sort((a, b) => new Date(b.fetchedAt ?? 0).getTime() - new Date(a.fetchedAt ?? 0).getTime());
|
.sort((a, b) => fetchedAtMs(b) - fetchedAtMs(a));
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
if (ctrl.signal.aborted) return;
|
if (nextCtrl.signal.aborted) return;
|
||||||
error = e?.message ?? "Failed to load updates";
|
error = e?.message ?? "Failed to load updates";
|
||||||
updates = [];
|
updates = [];
|
||||||
} finally {
|
} finally {
|
||||||
if (!ctrl.signal.aborted) loading = false;
|
if (!nextCtrl.signal.aborted) loading = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +174,7 @@
|
|||||||
<span class="chapter-title">{chapterLabel(item)}</span>
|
<span class="chapter-title">{chapterLabel(item)}</span>
|
||||||
|
|
||||||
<div class="meta-row">
|
<div class="meta-row">
|
||||||
<span>{timeAgo(new Date(item.fetchedAt ?? 0).getTime())}</span>
|
<span>{timeAgo(fetchedAtMs(item))}</span>
|
||||||
{#if (item.lastPageRead ?? 0) > 0 && !item.isRead}
|
{#if (item.lastPageRead ?? 0) > 0 && !item.isRead}
|
||||||
<span>· Resume p.{item.lastPageRead}</span>
|
<span>· Resume p.{item.lastPageRead}</span>
|
||||||
{/if}
|
{/if}
|
||||||
|
|||||||
Reference in New Issue
Block a user