Rewrites the web app's comments to rule 32. Task, milestone, rule and spec ids are gone; regression stories are restated as the trap they guard (public auth routes, the menu's stopPropagation, universal loads under adapter-static, metric deltas with their margin). Flutter and Tauri mentions now name the Android app or a native shell, operator quotes and dates are dropped, and one library's counts no longer appear outside test fixtures. Verified with a TypeScript-scanner token comparison (template literals and regex literals re-scanned): only comment text changed. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
155 lines
5.7 KiB
Svelte
155 lines
5.7 KiB
Svelte
<script lang="ts">
|
|
import { onMount } from 'svelte';
|
|
import {
|
|
getLibraryFolders,
|
|
updateLibraryFolders,
|
|
type LibraryFolders
|
|
} from '#lib/api/admin.js';
|
|
import { errMessage } from '#lib/api/errors.js';
|
|
import { pushToast } from '#lib/stores/toast.svelte.js';
|
|
import { plural } from '#lib/utils/plural.js';
|
|
import SettingRow from '#lib/components/settings/SettingRow.svelte';
|
|
|
|
// The library's folders, set here rather than only by
|
|
// MINSTREL_LIBRARY_SCAN_PATHS. Editing a folder's path says its files moved
|
|
// there: the server rewrites its tracks' paths, so plays, likes and
|
|
// playlists stay with them. A folder removed is no longer read.
|
|
|
|
let { onSaved }: { onSaved?: () => void } = $props();
|
|
|
|
let current = $state<LibraryFolders | null>(null);
|
|
let loadError = $state(false);
|
|
let editing = $state(false);
|
|
let saving = $state(false);
|
|
// was: the folder a row started as ('' for one added), so the server can
|
|
// tell a move from an addition.
|
|
let rows = $state<{ path: string; was: string }[]>([]);
|
|
|
|
const removed = $derived(
|
|
editing && current ? current.folders.filter((f) => !rows.some((r) => r.was === f.path)) : []
|
|
);
|
|
const moved = $derived(rows.filter((r) => r.was && r.path.trim() && r.path.trim() !== r.was));
|
|
const blank = $derived(rows.some((r) => !r.path.trim()));
|
|
const valid = $derived(rows.length > 0 && !blank);
|
|
|
|
async function load() {
|
|
try {
|
|
current = await getLibraryFolders();
|
|
loadError = false;
|
|
} catch {
|
|
loadError = true;
|
|
}
|
|
}
|
|
|
|
onMount(load);
|
|
|
|
function edit() {
|
|
if (!current) return;
|
|
rows = current.folders.map((f) => ({ path: f.path, was: f.path }));
|
|
if (rows.length === 0) rows = [{ path: '', was: '' }];
|
|
editing = true;
|
|
}
|
|
|
|
async function save() {
|
|
if (!valid) return;
|
|
saving = true;
|
|
try {
|
|
current = await updateLibraryFolders(rows.map((r) => ({ path: r.path.trim(), was: r.was })));
|
|
editing = false;
|
|
const n = current.moved ?? 0;
|
|
pushToast(
|
|
n > 0
|
|
? `Library folders saved. ${plural(n, 'track', 'tracks')} moved with their folder; a scan has started.`
|
|
: 'Library folders saved; a scan has started.'
|
|
);
|
|
onSaved?.();
|
|
} catch (e) {
|
|
pushToast(errMessage(e), 'error');
|
|
} finally {
|
|
saving = false;
|
|
}
|
|
}
|
|
|
|
const button =
|
|
'rounded-md border border-border px-3 py-1.5 text-sm text-text-secondary hover:bg-surface-hover hover:text-text-primary disabled:opacity-50';
|
|
const field = 'w-64 max-w-full rounded-md border border-border bg-background px-2 py-1.5 font-mono text-xs';
|
|
</script>
|
|
|
|
{#if loadError}
|
|
<p class="px-4 py-3 text-sm text-error-fg">
|
|
Couldn't load the library folders.
|
|
<button type="button" class="underline hover:no-underline" onclick={load}>Try again</button>
|
|
</p>
|
|
{:else if current === null}
|
|
<p class="px-4 py-3 text-sm text-text-secondary">Loading…</p>
|
|
{:else if !editing}
|
|
<SettingRow
|
|
label="Folders"
|
|
hint={current.saved ? 'Where Minstrel looks for music.' : 'Set by MINSTREL_LIBRARY_SCAN_PATHS until changed here.'}
|
|
>
|
|
<span class="flex flex-col items-end font-mono text-xs text-text-secondary" data-testid="library-folders">
|
|
{#each current.folders as f (f.path)}<span>{f.path}</span>{:else}<span>—</span>{/each}
|
|
</span>
|
|
<button type="button" class={button} onclick={edit}>Change</button>
|
|
</SettingRow>
|
|
{#each current.folders.filter((f) => !f.present) as f (f.path)}
|
|
<p class="px-4 pb-3 text-xs text-error-fg" data-testid="folder-missing">
|
|
The server can't see {f.path}{f.tracks > 0 ? `, which holds ${plural(f.tracks, 'track', 'tracks')}` : ''}.
|
|
If its files are now somewhere else, change the folder to where they are.
|
|
</p>
|
|
{/each}
|
|
{:else}
|
|
<div class="flex flex-col gap-2 px-4 py-3" data-testid="library-folders-form">
|
|
<span class="text-sm text-text-primary">Folders</span>
|
|
<p class="text-xs text-text-secondary">
|
|
Change a folder's path when its files have moved; the tracks move with it and keep their plays, likes and
|
|
playlists. Each path is as the server sees it, inside its container.
|
|
</p>
|
|
{#each rows as row, i (i)}
|
|
<div class="flex items-center gap-2">
|
|
<input
|
|
type="text"
|
|
aria-label="Folder {i + 1}"
|
|
placeholder="/data/music"
|
|
bind:value={row.path}
|
|
class={field}
|
|
/>
|
|
<button
|
|
type="button"
|
|
class={button}
|
|
aria-label="Remove folder {i + 1}"
|
|
onclick={() => (rows = rows.filter((_, j) => j !== i))}
|
|
>
|
|
Remove
|
|
</button>
|
|
</div>
|
|
{/each}
|
|
<div>
|
|
<button type="button" class={button} onclick={() => (rows = [...rows, { path: '', was: '' }])}>Add folder</button>
|
|
</div>
|
|
<div class="text-xs text-text-secondary" data-testid="folder-changes">
|
|
{#each moved as m (m.was)}
|
|
<p>{m.was} → {m.path.trim()}: its tracks move with it.</p>
|
|
{/each}
|
|
{#each removed as f (f.path)}
|
|
<p class="text-error-fg">
|
|
{f.path} will no longer be read{f.tracks > 0
|
|
? `; its ${plural(f.tracks, 'track is', 'tracks are')} marked missing at the next scan`
|
|
: ''}.
|
|
</p>
|
|
{/each}
|
|
</div>
|
|
<div class="flex flex-wrap items-center justify-end gap-2">
|
|
{#if blank}
|
|
<p class="mr-auto text-xs text-error-fg">Fill in or remove the empty folder.</p>
|
|
{:else if rows.length === 0}
|
|
<p class="mr-auto text-xs text-error-fg">The library needs at least one folder.</p>
|
|
{/if}
|
|
<button type="button" class={button} disabled={saving} onclick={() => (editing = false)}>Cancel</button>
|
|
<button type="button" class={button} disabled={!valid || saving} onclick={save}>
|
|
{saving ? 'Saving…' : 'Save'}
|
|
</button>
|
|
</div>
|
|
</div>
|
|
{/if}
|