refactor(web): pushToast store + ToastHost; 8 sites migrated (W3)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
rejectRequest
|
||||
} from '$lib/api/admin';
|
||||
import { errMessage } from '$lib/api/errors';
|
||||
import { pushToast } from '$lib/stores/toast.svelte';
|
||||
import StatusPill from '$lib/components/StatusPill.svelte';
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
import type { LidarrRequest, LidarrRequestKind, LidarrRequestStatus } from '$lib/api/types';
|
||||
@@ -56,20 +57,6 @@
|
||||
let rejectOpen = $state<string | null>(null);
|
||||
let rejectNotes = $state<string>('');
|
||||
|
||||
// Toast surface — single line, fixed bottom-right, auto-clears after 5s.
|
||||
// No third-party lib for v1; this is enough to surface the lidarr-unreachable
|
||||
// error per spec §7 without dragging in a toast framework.
|
||||
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);
|
||||
}
|
||||
|
||||
function fallbackIcon(kind: LidarrRequestKind) {
|
||||
if (kind === 'artist') return Disc3;
|
||||
if (kind === 'album') return Album;
|
||||
@@ -115,7 +102,7 @@
|
||||
}
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
showToast(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -155,7 +142,7 @@
|
||||
await rejectRequest(r.id, notes ? notes : undefined);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
showToast(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -385,17 +372,6 @@
|
||||
</div>
|
||||
</Modal>
|
||||
|
||||
{#if toast}
|
||||
<div
|
||||
role="status"
|
||||
aria-live="polite"
|
||||
class="fixed bottom-4 right-4 z-50 max-w-sm rounded-md border border-border bg-surface px-4 py-3 text-sm text-text-primary shadow-lg"
|
||||
data-testid="toast"
|
||||
>
|
||||
{toast}
|
||||
</div>
|
||||
{/if}
|
||||
|
||||
<style>
|
||||
.kind-pill {
|
||||
display: inline-flex;
|
||||
|
||||
Reference in New Issue
Block a user