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:
@@ -0,0 +1,58 @@
|
|||||||
|
<script lang="ts">
|
||||||
|
// Asks before something that can't be undone: deleting a playlist or an
|
||||||
|
// account, removing or forgetting a file. The body says what goes; the
|
||||||
|
// confirm button names the act and wears the destructive action colour
|
||||||
|
// (oxblood), which the design system keeps apart from the error colour: an
|
||||||
|
// error is a failure that already happened. Android's twin is
|
||||||
|
// ConfirmDestructiveDialog.
|
||||||
|
import type { Snippet } from 'svelte';
|
||||||
|
import Modal from './Modal.svelte';
|
||||||
|
import type { IconProp } from './TrackMenuItem.svelte';
|
||||||
|
|
||||||
|
let {
|
||||||
|
title,
|
||||||
|
open,
|
||||||
|
confirmLabel,
|
||||||
|
busyLabel,
|
||||||
|
confirmAriaLabel,
|
||||||
|
icon: Icon,
|
||||||
|
busy = false,
|
||||||
|
onCancel,
|
||||||
|
onConfirm,
|
||||||
|
children
|
||||||
|
}: {
|
||||||
|
title: string;
|
||||||
|
open: boolean;
|
||||||
|
confirmLabel: string;
|
||||||
|
/** Shown on the confirm button while the act runs ("Deleting…"). */
|
||||||
|
busyLabel?: string;
|
||||||
|
confirmAriaLabel?: string;
|
||||||
|
icon?: IconProp;
|
||||||
|
busy?: boolean;
|
||||||
|
onCancel: () => void;
|
||||||
|
onConfirm: () => void;
|
||||||
|
children: Snippet;
|
||||||
|
} = $props();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<Modal {title} {open} onClose={onCancel}>
|
||||||
|
<div class="-mt-2 text-sm text-text-secondary">{@render children()}</div>
|
||||||
|
<div class="mt-5 flex justify-end gap-2">
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
disabled={busy}
|
||||||
|
class="rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:text-text-primary disabled:opacity-50"
|
||||||
|
onclick={onCancel}>Cancel</button
|
||||||
|
>
|
||||||
|
<button
|
||||||
|
type="button"
|
||||||
|
aria-label={confirmAriaLabel}
|
||||||
|
disabled={busy}
|
||||||
|
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={onConfirm}
|
||||||
|
>
|
||||||
|
{#if Icon}<Icon size={14} strokeWidth={2} />{/if}
|
||||||
|
{busy && busyLabel ? busyLabel : confirmLabel}
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</Modal>
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
import { describe, expect, test, vi } from 'vitest';
|
||||||
|
import { render, screen, fireEvent } from '@testing-library/svelte';
|
||||||
|
import { createRawSnippet } from 'svelte';
|
||||||
|
import ConfirmModal from './ConfirmModal.svelte';
|
||||||
|
import { offendingSources } from '#lib/testing/sourceGuard.js';
|
||||||
|
|
||||||
|
const body = createRawSnippet(() => ({ render: () => `<span>Its songs stay in your library.</span>` }));
|
||||||
|
|
||||||
|
// The children Snippet isn't inferable through testing-library's render.
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
type AnyProps = any;
|
||||||
|
|
||||||
|
function show(extra: Record<string, unknown> = {}) {
|
||||||
|
const onCancel = vi.fn();
|
||||||
|
const onConfirm = vi.fn();
|
||||||
|
render(ConfirmModal, {
|
||||||
|
props: {
|
||||||
|
title: 'Delete this playlist?',
|
||||||
|
open: true,
|
||||||
|
confirmLabel: 'Delete',
|
||||||
|
onCancel,
|
||||||
|
onConfirm,
|
||||||
|
children: body,
|
||||||
|
...extra
|
||||||
|
} as AnyProps
|
||||||
|
});
|
||||||
|
return { onCancel, onConfirm };
|
||||||
|
}
|
||||||
|
|
||||||
|
describe('ConfirmModal', () => {
|
||||||
|
test('says what goes, and acts only on the confirm button', async () => {
|
||||||
|
const { onCancel, onConfirm } = show();
|
||||||
|
expect(screen.getByRole('dialog', { name: 'Delete this playlist?' })).toBeInTheDocument();
|
||||||
|
expect(screen.getByText('Its songs stay in your library.')).toBeInTheDocument();
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: 'Cancel' }));
|
||||||
|
expect(onCancel).toHaveBeenCalledOnce();
|
||||||
|
expect(onConfirm).not.toHaveBeenCalled();
|
||||||
|
await fireEvent.click(screen.getByRole('button', { name: 'Delete' }));
|
||||||
|
expect(onConfirm).toHaveBeenCalledOnce();
|
||||||
|
});
|
||||||
|
|
||||||
|
test('the confirm button wears the destructive action colour, not the error colour', () => {
|
||||||
|
show();
|
||||||
|
const confirm = screen.getByRole('button', { name: 'Delete' });
|
||||||
|
expect(confirm.className).toContain('bg-action-destructive');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('while the act runs, both buttons are off and the confirm says so', () => {
|
||||||
|
show({ busy: true, busyLabel: 'Deleting…' });
|
||||||
|
expect(screen.getByRole('button', { name: 'Deleting…' })).toBeDisabled();
|
||||||
|
expect(screen.getByRole('button', { name: 'Cancel' })).toBeDisabled();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Asking before an act that can't be undone goes through ConfirmModal, and an
|
||||||
|
// error goes to a toast. The browser's own confirm() and alert() boxes look
|
||||||
|
// like neither app and can't be styled or tested, so no page calls them.
|
||||||
|
const NATIVE = /(?<![\w.])(?:window\.)?(?:confirm|alert)\(/;
|
||||||
|
|
||||||
|
describe('native dialogs', () => {
|
||||||
|
test('no page calls the browser confirm() or alert()', () => {
|
||||||
|
expect(offendingSources([NATIVE])).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -83,7 +83,10 @@
|
|||||||
{#if $metrics.isPending}
|
{#if $metrics.isPending}
|
||||||
<p class="text-sm text-text-secondary">Loading…</p>
|
<p class="text-sm text-text-secondary">Loading…</p>
|
||||||
{:else if $metrics.isError}
|
{:else if $metrics.isError}
|
||||||
<p class="text-sm text-text-secondary">Couldn't load metrics.</p>
|
<p role="alert" class="text-sm text-error-fg">
|
||||||
|
Couldn't load metrics.
|
||||||
|
<button type="button" class="underline hover:no-underline" onclick={() => $metrics.refetch()}>Try again</button>
|
||||||
|
</p>
|
||||||
{:else if $metrics.data && ($metrics.data.groups.length > 0 || $metrics.data.baseline)}
|
{:else if $metrics.data && ($metrics.data.groups.length > 0 || $metrics.data.baseline)}
|
||||||
{@const baseline = $metrics.data.baseline}
|
{@const baseline = $metrics.data.baseline}
|
||||||
{#if baseline}
|
{#if baseline}
|
||||||
|
|||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Helpers for source guards: tests that read the web app's own source to
|
||||||
|
// assert a shape is absent (a hand-written count label, a native confirm()).
|
||||||
|
// Test-only; nothing in the app imports this.
|
||||||
|
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
||||||
|
import { dirname, join, relative } from 'node:path';
|
||||||
|
import { fileURLToPath } from 'node:url';
|
||||||
|
|
||||||
|
/** web/src. */
|
||||||
|
export const SRC = join(dirname(fileURLToPath(import.meta.url)), '../..');
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Comments describe the forbidden shape; strip them before asserting its
|
||||||
|
* absence, or the prose explaining a rule trips the check that enforces it.
|
||||||
|
*/
|
||||||
|
export const stripComments = (s: string): string =>
|
||||||
|
s.replace(/<!--[\s\S]*?-->/g, '').replace(/^\s*\/\/.*$/gm, '');
|
||||||
|
|
||||||
|
/** Every .svelte and .ts file under web/src, tests left out. */
|
||||||
|
export function appSources(dir: string = SRC): string[] {
|
||||||
|
return readdirSync(dir).flatMap((name) => {
|
||||||
|
const path = join(dir, name);
|
||||||
|
if (statSync(path).isDirectory()) return appSources(path);
|
||||||
|
return /\.(svelte|ts)$/.test(name) && !/\.test\.ts$/.test(name) ? [path] : [];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The app files, relative to web/src, whose source (comments stripped)
|
||||||
|
* matches any of patterns. Throws if the walk finds almost nothing, so a
|
||||||
|
* wrong root can't pass as "no offenders".
|
||||||
|
*/
|
||||||
|
export function offendingSources(patterns: RegExp[]): string[] {
|
||||||
|
const all = appSources();
|
||||||
|
if (all.length < 100) throw new Error(`source guard found only ${all.length} files under ${SRC}`);
|
||||||
|
return all
|
||||||
|
.filter((path) => {
|
||||||
|
const text = stripComments(readFileSync(path, 'utf8'));
|
||||||
|
return patterns.some((re) => re.test(text));
|
||||||
|
})
|
||||||
|
.map((path) => relative(SRC, path));
|
||||||
|
}
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
import { readFileSync, readdirSync, statSync } from 'node:fs';
|
|
||||||
import { dirname, join, relative } from 'node:path';
|
|
||||||
import { fileURLToPath } from 'node:url';
|
|
||||||
import { describe, expect, test } from 'vitest';
|
import { describe, expect, test } from 'vitest';
|
||||||
import { plural } from './plural.js';
|
import { plural } from './plural.js';
|
||||||
|
import { offendingSources } from '#lib/testing/sourceGuard.js';
|
||||||
|
|
||||||
describe('plural', () => {
|
describe('plural', () => {
|
||||||
test('says a count with the noun that agrees with it', () => {
|
test('says a count with the noun that agrees with it', () => {
|
||||||
@@ -21,8 +19,6 @@ describe('plural', () => {
|
|||||||
// - the suffix trick: `minute${n === 1 ? '' : 's'}`.
|
// - the suffix trick: `minute${n === 1 ? '' : 's'}`.
|
||||||
// A choice of words with no count in it ("it" / "they", "yesterday") is
|
// A choice of words with no count in it ("it" / "they", "yesterday") is
|
||||||
// not a count label and stays a ternary.
|
// not a count label and stays a ternary.
|
||||||
const SRC = join(dirname(fileURLToPath(import.meta.url)), '../..');
|
|
||||||
|
|
||||||
const HAND_ROLLED = [
|
const HAND_ROLLED = [
|
||||||
/=== 1 \? ['"`]1 /,
|
/=== 1 \? ['"`]1 /,
|
||||||
/\{([\w.]+)\}\s*\{\1 === 1 \?/,
|
/\{([\w.]+)\}\s*\{\1 === 1 \?/,
|
||||||
@@ -30,23 +26,8 @@ const HAND_ROLLED = [
|
|||||||
/=== 1 \? '' : 's'/
|
/=== 1 \? '' : 's'/
|
||||||
];
|
];
|
||||||
|
|
||||||
/** Comments describe the forbidden shape; strip them before asserting its absence. */
|
|
||||||
const stripComments = (s: string) => s.replace(/<!--[\s\S]*?-->/g, '').replace(/^\s*\/\/.*$/gm, '');
|
|
||||||
|
|
||||||
function sources(dir: string): string[] {
|
|
||||||
return readdirSync(dir).flatMap((name) => {
|
|
||||||
const path = join(dir, name);
|
|
||||||
if (statSync(path).isDirectory()) return sources(path);
|
|
||||||
return /\.(svelte|ts)$/.test(name) && !/\.test\.ts$/.test(name) ? [path] : [];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
describe('count labels', () => {
|
describe('count labels', () => {
|
||||||
test('every count in the web app is said by plural()', () => {
|
test('every count in the web app is said by plural()', () => {
|
||||||
const offenders = sources(SRC).flatMap((path) => {
|
expect(offendingSources(HAND_ROLLED)).toEqual([]);
|
||||||
const text = stripComments(readFileSync(path, 'utf8'));
|
|
||||||
return HAND_ROLLED.some((re) => re.test(text)) ? [relative(SRC, path)] : [];
|
|
||||||
});
|
|
||||||
expect(offenders).toEqual([]);
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,6 +22,7 @@
|
|||||||
import { errCode, errMessage } from '#lib/api/errors.js';
|
import { errCode, errMessage } from '#lib/api/errors.js';
|
||||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||||
import Modal from '#lib/components/Modal.svelte';
|
import Modal from '#lib/components/Modal.svelte';
|
||||||
|
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||||
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
||||||
import { Shield, ShieldOff, KeyRound, Trash2, Copy, Bug, BugOff } from 'lucide-svelte';
|
import { Shield, ShieldOff, KeyRound, Trash2, Copy, Bug, BugOff } from 'lucide-svelte';
|
||||||
|
|
||||||
@@ -483,31 +484,15 @@
|
|||||||
</form>
|
</form>
|
||||||
</Modal>
|
</Modal>
|
||||||
|
|
||||||
<Modal
|
<ConfirmModal
|
||||||
title={confirmDeleteTarget ? `Delete ${confirmDeleteTarget.username}?` : ''}
|
title={confirmDeleteTarget ? `Delete ${confirmDeleteTarget.username}?` : ''}
|
||||||
open={confirmDeleteTarget !== null}
|
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,
|
||||||
This permanently deletes the account and cascades through plays, likes,
|
sessions, and quarantine. The action cannot be undone.
|
||||||
sessions, and quarantine. The action cannot be undone.
|
</ConfirmModal>
|
||||||
</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>
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import { plural } from '#lib/utils/plural.js';
|
import { plural } from '#lib/utils/plural.js';
|
||||||
import { pageTitle } from '#lib/branding.js';
|
import { pageTitle } from '#lib/branding.js';
|
||||||
import { Copy, Download, FolderX, Trash2 } from 'lucide-svelte';
|
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 { createMissingFilesQuery, forgetMissingTracks, MISSING_FILES_CSV_URL } from '#lib/api/admin.js';
|
||||||
import { errMessage } from '#lib/api/errors.js';
|
import { errMessage } from '#lib/api/errors.js';
|
||||||
import { pushToast } from '#lib/stores/toast.svelte.js';
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
||||||
@@ -243,27 +243,18 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</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}
|
{#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
|
||||||
Forget {forgetting.label}, with their likes, plays and playlist places. A copy added later
|
comes in as a new track.
|
||||||
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>
|
|
||||||
{/if}
|
{/if}
|
||||||
</Modal>
|
</ConfirmModal>
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
import { useQueryClient } from '@tanstack/svelte-query';
|
import { useQueryClient } from '@tanstack/svelte-query';
|
||||||
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
import RowActionsMenu, { type RowAction } from '#lib/components/RowActionsMenu.svelte';
|
||||||
import TabStrip from '#lib/components/TabStrip.svelte';
|
import TabStrip from '#lib/components/TabStrip.svelte';
|
||||||
import Modal from '#lib/components/Modal.svelte';
|
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||||
import {
|
import {
|
||||||
createAdminQuarantineQuery,
|
createAdminQuarantineQuery,
|
||||||
createAdminPlaybackErrorsQuery,
|
createAdminPlaybackErrorsQuery,
|
||||||
@@ -282,55 +282,37 @@
|
|||||||
{/if}
|
{/if}
|
||||||
</div>
|
</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}
|
{#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.
|
||||||
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
|
||||||
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.
|
||||||
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>
|
|
||||||
{/if}
|
{/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}
|
{#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
|
||||||
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
|
||||||
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.
|
||||||
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>
|
|
||||||
{/if}
|
{/if}
|
||||||
</Modal>
|
</ConfirmModal>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
.pill {
|
.pill {
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||||
import Cover from '#lib/components/Cover.svelte';
|
import Cover from '#lib/components/Cover.svelte';
|
||||||
import { plural } from '#lib/utils/plural.js';
|
import { plural } from '#lib/utils/plural.js';
|
||||||
import { pageTitle } from '#lib/branding.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 { createSuspectSourcesQuery, removeSuspectFile, setSuspectVerdict } from '#lib/api/admin.js';
|
||||||
import { errMessage } from '#lib/api/errors.js';
|
import { errMessage } from '#lib/api/errors.js';
|
||||||
import { pushToast } from '#lib/stores/toast.svelte.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
|
// 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.
|
// clean copy. It asks first, as the file is deleted, in the dialog the
|
||||||
let confirmingRemove = $state<string | null>(null);
|
// Reports page uses for the same act.
|
||||||
|
let confirmingRemove = $state<AdminSuspectTrack | null>(null);
|
||||||
let removed = $state<Record<string, boolean>>({});
|
let removed = $state<Record<string, boolean>>({});
|
||||||
|
|
||||||
async function onRemove(t: AdminSuspectTrack) {
|
async function onRemove(t: AdminSuspectTrack) {
|
||||||
if (confirmingRemove !== t.track_id) {
|
|
||||||
confirmingRemove = t.track_id;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
confirmingRemove = null;
|
confirmingRemove = null;
|
||||||
saving = t.track_id;
|
saving = t.track_id;
|
||||||
try {
|
try {
|
||||||
@@ -216,12 +214,12 @@
|
|||||||
{#if verdictOf(t) !== 'fine' && !removed[t.track_id]}
|
{#if verdictOf(t) !== 'fine' && !removed[t.track_id]}
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={() => onRemove(t)}
|
onclick={() => (confirmingRemove = t)}
|
||||||
disabled={saving === t.track_id}
|
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"
|
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>
|
</button>
|
||||||
{/if}
|
{/if}
|
||||||
</li>
|
</li>
|
||||||
@@ -239,3 +237,18 @@
|
|||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</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();
|
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
|
// A rip that is not fine has its file removed once the dialog is confirmed;
|
||||||
// waits for a clean copy.
|
// the track waits for a clean copy.
|
||||||
test('Remove this file asks once more, then removes the rip', async () => {
|
test('Remove this file asks in a dialog, then removes the rip', async () => {
|
||||||
mocked.mockReturnValue(
|
mocked.mockReturnValue(
|
||||||
infinite([
|
infinite([
|
||||||
page(0, 1, [
|
page(0, 1, [
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
|
import { playlistTrackToRef } from '#lib/playlists/playlistTrackToRef.js';
|
||||||
import { shuffled } from '#lib/utils/shuffle.js';
|
import { shuffled } from '#lib/utils/shuffle.js';
|
||||||
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
|
import ApiErrorBanner from '#lib/components/ApiErrorBanner.svelte';
|
||||||
|
import ConfirmModal from '#lib/components/ConfirmModal.svelte';
|
||||||
import {
|
import {
|
||||||
createPlaylistQuery,
|
createPlaylistQuery,
|
||||||
updatePlaylist,
|
updatePlaylist,
|
||||||
@@ -66,7 +67,7 @@
|
|||||||
await reorderPlaylist(id, cur);
|
await reorderPlaylist(id, cur);
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
queryClient.setQueryData(qk.playlist(id), previous);
|
queryClient.setQueryData(qk.playlist(id), previous);
|
||||||
alert(errMessage(e));
|
pushToast(errMessage(e), 'error');
|
||||||
}
|
}
|
||||||
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@
|
|||||||
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
await queryClient.invalidateQueries({ queryKey: qk.playlist(id) });
|
||||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
alert(errMessage(e));
|
pushToast(errMessage(e), 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,18 +155,24 @@
|
|||||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||||
editing = false;
|
editing = false;
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
alert(errMessage(e));
|
pushToast(errMessage(e), 'error');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let confirmingDelete = $state(false);
|
||||||
|
let deleting = $state(false);
|
||||||
|
|
||||||
async function submitDelete() {
|
async function submitDelete() {
|
||||||
if (!confirm('Delete this playlist? This cannot be undone.')) return;
|
deleting = true;
|
||||||
try {
|
try {
|
||||||
await deletePlaylist(id);
|
await deletePlaylist(id);
|
||||||
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
await queryClient.invalidateQueries({ queryKey: qk.playlists() });
|
||||||
|
confirmingDelete = false;
|
||||||
goto('/playlists');
|
goto('/playlists');
|
||||||
} catch (e: unknown) {
|
} catch (e: unknown) {
|
||||||
alert(errMessage(e));
|
pushToast(errMessage(e), 'error');
|
||||||
|
} finally {
|
||||||
|
deleting = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -322,7 +329,7 @@
|
|||||||
</button>
|
</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
onclick={submitDelete}
|
onclick={() => (confirmingDelete = true)}
|
||||||
aria-label="Delete playlist"
|
aria-label="Delete playlist"
|
||||||
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-action-destructive"
|
class="rounded p-2 text-text-muted hover:bg-surface-hover hover:text-action-destructive"
|
||||||
>
|
>
|
||||||
@@ -395,3 +402,17 @@
|
|||||||
{/if}
|
{/if}
|
||||||
{/if}
|
{/if}
|
||||||
</PageColumn>
|
</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 }));
|
mockedQuery.mockReturnValue(mockQuery({ data: ownDetail }));
|
||||||
const confirmSpy = vi.spyOn(globalThis, 'confirm').mockReturnValue(true);
|
|
||||||
render(PlaylistDetailPage);
|
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'));
|
await waitFor(() => expect(deletePlaylist).toHaveBeenCalledWith('p1'));
|
||||||
confirmSpy.mockRestore();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('renders Refresh button on a refreshable system playlist', () => {
|
test('renders Refresh button on a refreshable system playlist', () => {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
|
import SettingsLoadStatus from '#lib/components/settings/SettingsLoadStatus.svelte';
|
||||||
import SettingsColumns from '#lib/components/settings/SettingsColumns.svelte';
|
import SettingsColumns from '#lib/components/settings/SettingsColumns.svelte';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { useQueryClient } from '@tanstack/svelte-query';
|
import { useQueryClient } from '@tanstack/svelte-query';
|
||||||
@@ -174,10 +175,8 @@
|
|||||||
<SettingsColumns>
|
<SettingsColumns>
|
||||||
{#snippet main()}
|
{#snippet main()}
|
||||||
<SettingsGroup title="ListenBrainz" hint="Sends what you play to your ListenBrainz profile.">
|
<SettingsGroup title="ListenBrainz" hint="Sends what you play to your ListenBrainz profile.">
|
||||||
{#if $status.isPending}
|
{#if $status.isPending || $status.isError}
|
||||||
<div class="px-4 py-3 text-sm text-text-secondary">Loading…</div>
|
<SettingsLoadStatus failed={$status.isError} what="ListenBrainz status" retry={() => $status.refetch()} />
|
||||||
{:else if $status.isError}
|
|
||||||
<div class="px-4 py-3 text-sm text-text-secondary">Couldn't load ListenBrainz status.</div>
|
|
||||||
{:else if $status.data}
|
{:else if $status.data}
|
||||||
{@const s = $status.data}
|
{@const s = $status.data}
|
||||||
<SettingRow label="Status">
|
<SettingRow label="Status">
|
||||||
|
|||||||
Reference in New Issue
Block a user