refactor(web): pushToast store + ToastHost; 8 sites migrated (W3)

This commit is contained in:
2026-05-08 05:45:34 -04:00
parent 970752a153
commit 617477b702
12 changed files with 229 additions and 223 deletions
+9 -26
View File
@@ -25,6 +25,7 @@
} from '$lib/api/admin';
import { qk } from '$lib/api/queries';
import { errCode, errMessage } from '$lib/api/errors';
import { pushToast } from '$lib/stores/toast.svelte';
import type {
AdminQuarantineRow,
LidarrRequest,
@@ -63,16 +64,6 @@
(quarantine.data ?? []).slice(0, PREVIEW_LIMIT)
);
// ---- Toast (shared) ----
let toast = $state<string | null>(null);
let toastTimer: ReturnType<typeof setTimeout> | null = null;
function showToast(msg: string) {
if (toastTimer) clearTimeout(toastTimer);
toast = msg;
toastTimer = setTimeout(() => { toast = null; }, 5000);
}
// ---- Two-click destructive confirm for quarantine actions ----
// Map key is `${trackId}:${actionKey}`. First click sets a key; second
// click within 3s fires the action; otherwise the key clears.
@@ -132,7 +123,7 @@
await approveRequest(r.id);
await invalidateRequests();
} catch (e) {
showToast(errMessage(e));
pushToast(errMessage(e), 'error');
}
}
async function onReject(r: LidarrRequest) {
@@ -140,7 +131,7 @@
await rejectRequest(r.id);
await invalidateRequests();
} catch (e) {
showToast(errMessage(e));
pushToast(errMessage(e), 'error');
}
}
@@ -156,7 +147,7 @@
await resolveQuarantine(row.track_id);
await invalidateQuarantine();
} catch (e) {
showToast(errMessage(e));
pushToast(errMessage(e), 'error');
}
}
async function onDeleteFile(row: AdminQuarantineRow) {
@@ -170,7 +161,7 @@
await deleteQuarantineFile(row.track_id);
await invalidateQuarantine();
} catch (e) {
showToast(errMessage(e));
pushToast(errMessage(e), 'error');
}
}
async function onDeleteLidarr(row: AdminQuarantineRow) {
@@ -184,7 +175,7 @@
await deleteQuarantineViaLidarr(row.track_id);
await invalidateQuarantine();
} catch (e) {
showToast(errMessage(e));
pushToast(errMessage(e), 'error');
}
}
@@ -286,7 +277,7 @@
await updateScanSchedule(patch);
await client.invalidateQueries({ queryKey: qk.scanSchedule() });
} catch (e) {
showToast(`Schedule save failed: ${errCode(e)}`);
pushToast(`Schedule save failed: ${errCode(e)}`, 'error');
} finally {
scheduleSaving = false;
}
@@ -323,9 +314,9 @@
researchSaving = true;
try {
await researchMissingArt();
showToast('All previously-failed art will be re-attempted on the next scan.');
pushToast('All previously-failed art will be re-attempted on the next scan.');
} catch (e) {
showToast(`Re-search failed: ${errCode(e)}`);
pushToast(`Re-search failed: ${errCode(e)}`, 'error');
} finally {
researchSaving = false;
}
@@ -728,11 +719,3 @@
</section>
</div>
{#if toast}
<div
role="alert"
class="fixed bottom-4 right-4 z-50 max-w-sm rounded-md border border-border bg-surface px-4 py-2 text-sm text-text-primary shadow"
>
{toast}
</div>
{/if}