refactor(web): pushToast store + ToastHost; 8 sites migrated (W3)
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
} from '$lib/api/admin';
|
||||
import { qk } from '$lib/api/queries';
|
||||
import { errMessage } from '$lib/api/errors';
|
||||
import { pushToast } from '$lib/stores/toast.svelte';
|
||||
import { playRadio } from '$lib/player/store.svelte';
|
||||
import Modal from '$lib/components/Modal.svelte';
|
||||
import type { AdminQuarantineRow, LidarrQuarantineReason } from '$lib/api/types';
|
||||
@@ -68,19 +69,6 @@
|
||||
// feedback if Lidarr can't be reached or the album lookup fails.
|
||||
let deleteLidarrError = $state<string | null>(null);
|
||||
|
||||
// Toast surface — same pattern as /admin/requests for the lidarr-unreachable
|
||||
// and other error codes from /resolve and /delete-file.
|
||||
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);
|
||||
}
|
||||
|
||||
async function invalidate() {
|
||||
await client.invalidateQueries({ queryKey: qk.adminQuarantine() });
|
||||
}
|
||||
@@ -90,7 +78,7 @@
|
||||
await resolveQuarantine(r.track_id);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
showToast(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,7 +96,7 @@
|
||||
await deleteQuarantineFile(r.track_id);
|
||||
await invalidate();
|
||||
} catch (e) {
|
||||
showToast(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -139,7 +127,7 @@
|
||||
// alongside the album they were about to remove.
|
||||
deleteLidarrError = msg;
|
||||
// Also surface as toast so it's visible after dismissing the modal.
|
||||
showToast(msg);
|
||||
pushToast(msg, 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -409,17 +397,6 @@
|
||||
{/if}
|
||||
</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>
|
||||
.reason-pill {
|
||||
display: inline-flex;
|
||||
|
||||
Reference in New Issue
Block a user