refactor(web): one ConfirmModal asks before what can't be undone; no native dialogs (DRY B2, B3)
Deleting a playlist asked in the browser's own confirm() box and reported errors with alert(). Four other deletes each built Modal + Cancel + a destructive button by hand, two of them in bronze rather than the destructive oxblood. Suspect sources removed a file on a second click while Reports asks in a dialog for the same act. ConfirmModal is the web's twin of Android's ConfirmDestructiveDialog: title, a body saying what goes, Cancel, and a confirm button in the destructive action colour that can show a busy label. Reports (x2), Needs a file, Admin > Users, the playlist page and Suspect sources use it. The playlist page's errors go to toasts. A source guard keeps confirm() and alert() out of the app; it flags the old playlist page. The two web source guards share lib/testing/sourceGuard.ts. ListenBrainz status (Settings > Connections) and the recommendation metrics now offer Try again when they fail to load. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -22,6 +22,7 @@
|
||||
import { errCode, errMessage } from '#lib/api/errors.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
import Modal from '#lib/components/Modal.svelte';
|
||||
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
||||
import { Shield, ShieldOff, KeyRound, Trash2, Copy, Bug, BugOff } from 'lucide-svelte';
|
||||
|
||||
@@ -483,31 +484,15 @@
|
||||
</form>
|
||||
</Modal>
|
||||
|
||||
<Modal
|
||||
<ConfirmModal
|
||||
title={confirmDeleteTarget ? `Delete ${confirmDeleteTarget.username}?` : ''}
|
||||
open={confirmDeleteTarget !== null}
|
||||
onClose={() => { confirmDeleteTarget = null; }}
|
||||
confirmLabel="Delete"
|
||||
busyLabel="Deleting…"
|
||||
busy={saving}
|
||||
onCancel={() => { confirmDeleteTarget = null; }}
|
||||
onConfirm={onConfirmDelete}
|
||||
>
|
||||
<p class="-mt-2 text-sm text-text-secondary">
|
||||
This permanently deletes the account and cascades through plays, likes,
|
||||
sessions, and quarantine. The action cannot be undone.
|
||||
</p>
|
||||
<div class="mt-5 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving}
|
||||
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||
onclick={() => { confirmDeleteTarget = null; }}
|
||||
>
|
||||
Cancel
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
disabled={saving}
|
||||
class="inline-flex items-center gap-1 rounded-md bg-action-destructive px-3 py-1.5 text-sm text-action-fg disabled:cursor-not-allowed disabled:opacity-50"
|
||||
onclick={onConfirmDelete}
|
||||
>
|
||||
{saving ? 'Deleting…' : 'Delete'}
|
||||
</button>
|
||||
</div>
|
||||
</Modal>
|
||||
This permanently deletes the account and cascades through plays, likes,
|
||||
sessions, and quarantine. The action cannot be undone.
|
||||
</ConfirmModal>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
import { plural } from '#lib/utils/plural.js';
|
||||
import { pageTitle } from '#lib/branding.js';
|
||||
import { Copy, Download, FolderX, Trash2 } from 'lucide-svelte';
|
||||
import Modal from '#lib/components/Modal.svelte';
|
||||
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||
import { createMissingFilesQuery, forgetMissingTracks, MISSING_FILES_CSV_URL } from '#lib/api/admin.js';
|
||||
import { errMessage } from '#lib/api/errors.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
@@ -243,27 +243,18 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Modal title="Forget for good?" open={forgetting !== null} onClose={() => (forgetting = null)}>
|
||||
<ConfirmModal
|
||||
title="Forget for good?"
|
||||
open={forgetting !== null}
|
||||
confirmLabel="Forget"
|
||||
confirmAriaLabel="Confirm forget"
|
||||
icon={Trash2}
|
||||
busy={busy}
|
||||
onCancel={() => (forgetting = null)}
|
||||
onConfirm={() => confirmForget(forgetting!)}
|
||||
>
|
||||
{#if forgetting}
|
||||
<p class="-mt-2 text-sm text-text-secondary">
|
||||
Forget {forgetting.label}, with their likes, plays and playlist places. A copy added later
|
||||
comes in as a new track.
|
||||
</p>
|
||||
<div class="mt-5 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||
onclick={() => (forgetting = null)}>Cancel</button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Confirm forget"
|
||||
disabled={busy}
|
||||
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg disabled:opacity-50"
|
||||
onclick={() => confirmForget(forgetting!)}
|
||||
>
|
||||
<Trash2 size={14} strokeWidth={2} /> Forget
|
||||
</button>
|
||||
</div>
|
||||
Forget {forgetting.label}, with their likes, plays and playlist places. A copy added later
|
||||
comes in as a new track.
|
||||
{/if}
|
||||
</Modal>
|
||||
</ConfirmModal>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
||||
import TabStrip from '#lib/components/TabStrip.svelte';
|
||||
import Modal from '#lib/components/Modal.svelte';
|
||||
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||
import {
|
||||
createAdminQuarantineQuery,
|
||||
createAdminPlaybackErrorsQuery,
|
||||
@@ -282,55 +282,37 @@
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<Modal title="Remove the file?" open={removeFileRow !== null} onClose={() => (removeFileId = null)}>
|
||||
<ConfirmModal
|
||||
title="Remove the file?"
|
||||
open={removeFileRow !== null}
|
||||
confirmLabel="Remove the file"
|
||||
confirmAriaLabel="Confirm remove the file"
|
||||
icon={FileX}
|
||||
onCancel={() => (removeFileId = null)}
|
||||
onConfirm={() => confirmRemoveFile(removeFileRow!)}
|
||||
>
|
||||
{#if removeFileRow}
|
||||
<p class="-mt-2 text-sm text-text-secondary">
|
||||
Delete the file of <em class="font-medium text-text-primary">{removeFileRow.title}</em> and keep the track.
|
||||
It waits in Needs a file, with its likes and plays, and takes over a good copy when one is in the
|
||||
library. Its reports are cleared.
|
||||
</p>
|
||||
<div class="mt-5 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||
onclick={() => (removeFileId = null)}>Cancel</button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Confirm remove the file"
|
||||
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg"
|
||||
onclick={() => confirmRemoveFile(removeFileRow!)}
|
||||
>
|
||||
<FileX size={14} strokeWidth={2} /> Remove the file
|
||||
</button>
|
||||
</div>
|
||||
Delete the file of <em class="font-medium text-text-primary">{removeFileRow.title}</em> and keep the track.
|
||||
It waits in Needs a file, with its likes and plays, and takes over a good copy when one is in the
|
||||
library. Its reports are cleared.
|
||||
{/if}
|
||||
</Modal>
|
||||
</ConfirmModal>
|
||||
|
||||
<Modal title="Remove from library?" open={deleteFileRow !== null} onClose={() => (deleteFileId = null)}>
|
||||
<ConfirmModal
|
||||
title="Remove from library?"
|
||||
open={deleteFileRow !== null}
|
||||
confirmLabel="Remove from library"
|
||||
confirmAriaLabel="Confirm remove from library"
|
||||
icon={Trash2}
|
||||
onCancel={() => (deleteFileId = null)}
|
||||
onConfirm={() => confirmDeleteFile(deleteFileRow!)}
|
||||
>
|
||||
{#if deleteFileRow}
|
||||
<p class="-mt-2 text-sm text-text-secondary">
|
||||
Remove <em class="font-medium text-text-primary">{deleteFileRow.title}</em> and its file for good, with its
|
||||
likes, plays and playlist places. Its reports and playback errors go with it. To keep the track for a
|
||||
good copy, remove the file instead.
|
||||
</p>
|
||||
<div class="mt-5 flex justify-end gap-2">
|
||||
<button
|
||||
type="button"
|
||||
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary"
|
||||
onclick={() => (deleteFileId = null)}>Cancel</button
|
||||
>
|
||||
<button
|
||||
type="button"
|
||||
aria-label="Confirm remove from library"
|
||||
class="inline-flex items-center gap-1 rounded-md bg-action-secondary px-3 py-1.5 text-sm text-action-fg"
|
||||
onclick={() => confirmDeleteFile(deleteFileRow!)}
|
||||
>
|
||||
<Trash2 size={14} strokeWidth={2} /> Remove from library
|
||||
</button>
|
||||
</div>
|
||||
Remove <em class="font-medium text-text-primary">{deleteFileRow.title}</em> and its file for good, with its
|
||||
likes, plays and playlist places. Its reports and playback errors go with it. To keep the track for a
|
||||
good copy, remove the file instead.
|
||||
{/if}
|
||||
</Modal>
|
||||
</ConfirmModal>
|
||||
|
||||
<style>
|
||||
.pill {
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<script lang="ts">
|
||||
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||
import Cover from '#lib/components/Cover.svelte';
|
||||
import { plural } from '#lib/utils/plural.js';
|
||||
import { pageTitle } from '#lib/branding.js';
|
||||
import { FileCheck } from 'lucide-svelte';
|
||||
import { FileCheck, FileX } from 'lucide-svelte';
|
||||
import { createSuspectSourcesQuery, removeSuspectFile, setSuspectVerdict } from '#lib/api/admin.js';
|
||||
import { errMessage } from '#lib/api/errors.js';
|
||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||
@@ -64,15 +65,12 @@
|
||||
}
|
||||
|
||||
// Remove this file: the rip goes and its track waits in Needs a file for a
|
||||
// clean copy. Two clicks, as the file is deleted.
|
||||
let confirmingRemove = $state<string | null>(null);
|
||||
// clean copy. It asks first, as the file is deleted, in the dialog the
|
||||
// Reports page uses for the same act.
|
||||
let confirmingRemove = $state<AdminSuspectTrack | null>(null);
|
||||
let removed = $state<Record<string, boolean>>({});
|
||||
|
||||
async function onRemove(t: AdminSuspectTrack) {
|
||||
if (confirmingRemove !== t.track_id) {
|
||||
confirmingRemove = t.track_id;
|
||||
return;
|
||||
}
|
||||
confirmingRemove = null;
|
||||
saving = t.track_id;
|
||||
try {
|
||||
@@ -216,12 +214,12 @@
|
||||
{#if verdictOf(t) !== 'fine' && !removed[t.track_id]}
|
||||
<button
|
||||
type="button"
|
||||
onclick={() => onRemove(t)}
|
||||
onclick={() => (confirmingRemove = t)}
|
||||
disabled={saving === t.track_id}
|
||||
aria-label={confirmingRemove === t.track_id ? `Confirm remove the file of ${t.title}` : `Remove the file of ${t.title}`}
|
||||
aria-label={`Remove the file of ${t.title}`}
|
||||
class="shrink-0 rounded-md border border-border px-2.5 py-1 text-xs text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50"
|
||||
>
|
||||
{confirmingRemove === t.track_id ? 'Remove it?' : 'Remove this file'}
|
||||
Remove this file
|
||||
</button>
|
||||
{/if}
|
||||
</li>
|
||||
@@ -239,3 +237,18 @@
|
||||
/>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<ConfirmModal
|
||||
title="Remove the file?"
|
||||
open={confirmingRemove !== null}
|
||||
confirmLabel="Remove the file"
|
||||
confirmAriaLabel={confirmingRemove ? `Confirm remove the file of ${confirmingRemove.title}` : undefined}
|
||||
icon={FileX}
|
||||
onCancel={() => (confirmingRemove = null)}
|
||||
onConfirm={() => onRemove(confirmingRemove!)}
|
||||
>
|
||||
{#if confirmingRemove}
|
||||
Delete the file of <em class="font-medium text-text-primary">{confirmingRemove.title}</em> and keep the track.
|
||||
It waits in Needs a file, with its likes and plays, and takes over a clean copy when one is in the library.
|
||||
{/if}
|
||||
</ConfirmModal>
|
||||
|
||||
@@ -138,9 +138,9 @@ describe('Suspect sources page', () => {
|
||||
expect(screen.getByRole('button', { name: 'Hold back again' })).toBeInTheDocument();
|
||||
});
|
||||
|
||||
// A rip that is not fine has its file removed, on a second click; the track
|
||||
// waits for a clean copy.
|
||||
test('Remove this file asks once more, then removes the rip', async () => {
|
||||
// A rip that is not fine has its file removed once the dialog is confirmed;
|
||||
// the track waits for a clean copy.
|
||||
test('Remove this file asks in a dialog, then removes the rip', async () => {
|
||||
mocked.mockReturnValue(
|
||||
infinite([
|
||||
page(0, 1, [
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
|
||||
import { shuffled } from '#lib/utils/shuffle.js';
|
||||
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
|
||||
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||
import {
|
||||
createPlaylistQuery,
|
||||
updatePlaylist,
|
||||
@@ -66,7 +67,7 @@
|
||||
await reorderPlaylist(id, cur);
|
||||
} catch (e: unknown) {
|
||||
queryClient.setQueryData(qk.playlist(id), previous);
|
||||
alert(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
||||
}
|
||||
@@ -77,7 +78,7 @@
|
||||
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||
} catch (e: unknown) {
|
||||
alert(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -154,18 +155,24 @@
|
||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||
editing = false;
|
||||
} catch (e: unknown) {
|
||||
alert(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
}
|
||||
}
|
||||
|
||||
let confirmingDelete = $state(false);
|
||||
let deleting = $state(false);
|
||||
|
||||
async function submitDelete() {
|
||||
if (!confirm('Delete this playlist? This cannot be undone.')) return;
|
||||
deleting = true;
|
||||
try {
|
||||
await deletePlaylist(id);
|
||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||
confirmingDelete = false;
|
||||
goto('/playlists');
|
||||
} catch (e: unknown) {
|
||||
alert(errMessage(e));
|
||||
pushToast(errMessage(e), 'error');
|
||||
} finally {
|
||||
deleting = false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -322,7 +329,7 @@
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onclick={submitDelete}
|
||||
onclick={() => (confirmingDelete = true)}
|
||||
aria-label="Delete playlist"
|
||||
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-action-destructive"
|
||||
>
|
||||
@@ -395,3 +402,17 @@
|
||||
{/if}
|
||||
{/if}
|
||||
</PageColumn>
|
||||
|
||||
<ConfirmModal
|
||||
title="Delete this playlist?"
|
||||
open={confirmingDelete}
|
||||
confirmLabel="Delete"
|
||||
busyLabel="Deleting…"
|
||||
confirmAriaLabel="Confirm delete playlist"
|
||||
icon={Trash2}
|
||||
busy={deleting}
|
||||
onCancel={() => (confirmingDelete = false)}
|
||||
onConfirm={submitDelete}
|
||||
>
|
||||
Its songs stay in your library. This can't be undone.
|
||||
</ConfirmModal>
|
||||
|
||||
@@ -144,13 +144,14 @@ describe('Playlist detail page', () => {
|
||||
);
|
||||
});
|
||||
|
||||
test('Delete button confirms then deletes', async () => {
|
||||
test('Delete asks in a dialog, then deletes', async () => {
|
||||
mockedQuery.mockReturnValue(mockQuery({ data: ownDetail }));
|
||||
const confirmSpy = vi.spyOn(globalThis, 'confirm').mockReturnValue(true);
|
||||
render(PlaylistDetailPage);
|
||||
await fireEvent.click(screen.getByLabelText(/delete playlist/i));
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Delete playlist' }));
|
||||
expect(deletePlaylist).not.toHaveBeenCalled();
|
||||
expect(screen.getByRole('dialog', { name: 'Delete this playlist?' })).toBeTruthy();
|
||||
await fireEvent.click(screen.getByRole('button', { name: 'Confirm delete playlist' }));
|
||||
await waitFor(() => expect(deletePlaylist).toHaveBeenCalledWith('p1'));
|
||||
confirmSpy.mockRestore();
|
||||
});
|
||||
|
||||
test('renders Refresh button on a refreshable system playlist', () => {
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
<script lang="ts">
|
||||
import SettingsLoadStatus from '#lib/components/settings/SettingsLoadStatus.svelte';
|
||||
import SettingsColumns from '#lib/components/settings/SettingsColumns.svelte';
|
||||
import { onMount } from 'svelte';
|
||||
import { useQueryClient } from '@tanstack/svelte-query';
|
||||
@@ -174,10 +175,8 @@
|
||||
<SettingsColumns>
|
||||
{#snippet main()}
|
||||
<SettingsGroup title="ListenBrainz" hint="Sends what you play to your ListenBrainz profile.">
|
||||
{#if $status.isPending}
|
||||
<div class="px-4 py-3 text-sm text-text-secondary">Loading…</div>
|
||||
{:else if $status.isError}
|
||||
<div class="px-4 py-3 text-sm text-text-secondary">Couldn't load ListenBrainz status.</div>
|
||||
{#if $status.isPending || $status.isError}
|
||||
<SettingsLoadStatus failed={$status.isError} what="ListenBrainz status" retry={() => $status.refetch()} />
|
||||
{:else if $status.data}
|
||||
{@const s = $status.data}
|
||||
<SettingRow label="Status">
|
||||
|
||||
Reference in New Issue
Block a user