Merge remote-tracking branch 'origin/main' into feat/duplicates-web

# Conflicts:
#	README.md
This commit is contained in:
tgiachi 2026-11-12 17:20:34 +01:00
commit b638ef249d
12 changed files with 924 additions and 22 deletions

View file

@ -340,7 +340,7 @@ npm install
SONDA_URL=http://127.0.0.1:8080 npm run dev # open http://localhost:5173, /api is proxied to Sonda SONDA_URL=http://127.0.0.1:8080 npm run dev # open http://localhost:5173, /api is proxied to Sonda
``` ```
What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys, a volume slider with mute (remembered in the browser) and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. Discover suggests artists from the ones you pick, or from your listening only after you allow it (a dialog says that their names go to Last.fm), explains each score, and keeps your wishlist and the artists you are not interested in. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it, and to manage accounts: add one by email, give or take away the admin role, reset a password (which ends that person's sessions) and delete an account. The last admin cannot be changed, and your own account has no buttons there. Providers have a card each that says what the provider is sent: turning one on asks first, the API key is write-only (never shown, and gone from the page once saved), and there are a test of the key, the contact or address, removing what a provider gave, and, for Lidarr, the profiles and root folder to use when an artist is added. The bulk jobs (album covers, artist pictures, artist descriptions) each have a card that says what the job sends and to whom: starting one asks first and says it goes through the whole library, reading everything again is a separate choice, a job whose providers are off cannot be started, and the page follows its progress and can stop it. The Duplicates section lists the songs that are in more than one file, with a row for each copy (album, format, bitrate, size) and whether the files are byte for byte the same once the check has read them. The copy Sonda would keep is already chosen and you can choose another; "Delete the others" (one song) and "Clean all suggestions" (every song shown) ask first, list every file that stays and every file that goes with the space freed, and go song by song, stopping at the first refusal and saying why. With `library.allow_delete` off, which is the default, everything is shown and the delete buttons are disabled, and the page says how to turn it on. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings. What it does today: sign in (and create the first account of a new server), browse artists, albums and songs, search, and play with a queue, shuffle, repeat, media keys, a volume slider with mute (remembered in the browser) and a full-screen player. Artist pages show the Wikipedia text, similar artists and tags when those providers are on, each with its credit, and the photo credit next to the photo. It reports one listen per play. Playlists have a page of their own: make one, put a song in it with the button next to any song (or make a new playlist right there), play it, rename it, delete it, move a song up or down and take one out; a song whose files are gone is shown as not available and skipped when the playlist plays. Discover suggests artists from the ones you pick, or from your listening only after you allow it (a dialog says that their names go to Last.fm), explains each score, and keeps your wishlist and the artists you are not interested in. An admin who set up the `lidarr` provider gets a "Request on Lidarr" button on an artist's page and on the Discover cards: it asks first, then sends that one artist to their own Lidarr, which does the downloading (the web app downloads nothing; the page of an artist reads what Lidarr has, the cards ask nothing until you send). An admin also gets an Admin area to add, rename, move and remove libraries and to start a scan (of one library or all, optionally reading every file again) and follow it, and to manage accounts: add one by email, give or take away the admin role, reset a password (which ends that person's sessions) and delete an account. The last admin cannot be changed, and your own account has no buttons there. Providers have a card each that says what the provider is sent: turning one on asks first, the API key is write-only (never shown, and gone from the page once saved), and there are a test of the key, the contact or address, removing what a provider gave, and, for Lidarr, the profiles and root folder to use when an artist is added. The bulk jobs (album covers, artist pictures, artist descriptions) each have a card that says what the job sends and to whom: starting one asks first and says it goes through the whole library, reading everything again is a separate choice, a job whose providers are off cannot be started, and the page follows its progress and can stop it. The Duplicates section lists the songs that are in more than one file, with a row for each copy (album, format, bitrate, size) and whether the files are byte for byte the same once the check has read them. The copy Sonda would keep is already chosen and you can choose another; "Delete the others" (one song) and "Clean all suggestions" (every song shown) ask first, list every file that stays and every file that goes with the space freed, and go song by song, stopping at the first refusal and saying why. With `library.allow_delete` off, which is the default, everything is shown and the delete buttons are disabled, and the page says how to turn it on. There are six themes (Sonda, Tokyo Night, Gruvbox dark, Gruvbox light, Dracula and Neon) and two languages (English and Italian), both chosen in Settings.
More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). `npm run build` writes to `internal/webui/dist` (git-ignored), not to `web/dist`. More commands, all run in `web/`: `npm test`, `npm run build`, and `npm run gen:api`, which rebuilds `src/api/schema.d.ts` from the OpenAPI spec (it fetches the generator with `npx`, so it needs the network once). `npm run build` writes to `internal/webui/dist` (git-ignored), not to `web/dist`.

86
web/src/api/playlists.ts Normal file
View file

@ -0,0 +1,86 @@
import { useMutation, useQuery, useQueryClient, type QueryClient } from '@tanstack/react-query'
import { api } from './client'
import { usePagedList, type ListOptions } from './catalog'
import type { components } from './schema'
export type Playlist = components['schemas']['Playlist']
export type PlaylistItem = components['schemas']['PlaylistItem']
/** The most the server gives in one page: a playlist is read whole, a few pages at most. */
export const ITEMS_PAGE = 200
/** Your playlists, the one changed last first. */
export function usePlaylists(opts: ListOptions = {}) {
return usePagedList<Playlist>('/playlists', {}, opts)
}
export function usePlaylist(id: number) {
return useQuery({ queryKey: ['playlist', id], queryFn: () => api.get<Playlist>(`/playlists/${id}`) })
}
/** The songs of a playlist in order, a page after the other. */
export function usePlaylistItems(id: number) {
return usePagedList<PlaylistItem>(`/playlists/${id}/tracks`, {}, { pageSize: ITEMS_PAGE })
}
/** Every list and page of playlists is read again: a change moves a playlist to the top and changes its size. */
function refresh(client: QueryClient) {
return client.invalidateQueries({
predicate: (query) => {
const key = query.queryKey[0]
return typeof key === 'string' ? key.startsWith('/playlists') : key === 'playlist'
},
})
}
export function useCreatePlaylist() {
const client = useQueryClient()
return useMutation({
mutationFn: (body: { name: string; description?: string }) => api.post<Playlist>('/playlists', body),
onSuccess: () => refresh(client),
})
}
export function useUpdatePlaylist() {
const client = useQueryClient()
return useMutation({
mutationFn: ({ id, ...body }: { id: number; name?: string; description?: string }) => api.patch<Playlist>(`/playlists/${id}`, body),
onSuccess: () => refresh(client),
})
}
export function useDeletePlaylist() {
const client = useQueryClient()
return useMutation({
mutationFn: (id: number) => api.del(`/playlists/${id}`),
onSuccess: () => refresh(client),
})
}
/** Puts songs at the end of a playlist, or at `position`. */
export function useAddTracks() {
const client = useQueryClient()
return useMutation({
mutationFn: ({ id, ...body }: { id: number; track_ids: number[]; position?: number }) =>
api.post<Playlist>(`/playlists/${id}/tracks`, body),
onSuccess: () => refresh(client),
})
}
/** `item` is the id of the place in the playlist, not the id of the song. */
export function useMoveItem() {
const client = useQueryClient()
return useMutation({
mutationFn: ({ id, item, position }: { id: number; item: number; position: number }) =>
api.patch(`/playlists/${id}/tracks/${item}`, { position }),
onSuccess: () => refresh(client),
})
}
export function useRemoveItem() {
const client = useQueryClient()
return useMutation({
mutationFn: ({ id, item }: { id: number; item: number }) => api.del(`/playlists/${id}/tracks/${item}`),
onSuccess: () => refresh(client),
})
}

View file

@ -0,0 +1,110 @@
import { ListPlus } from 'lucide-react'
import { useState, type FormEvent } from 'react'
import { useTranslation } from 'react-i18next'
import type { Track } from '@/api/catalog'
import { ApiError } from '@/api/client'
import { useAddTracks, useCreatePlaylist, usePlaylists } from '@/api/playlists'
import LoadMore from '@/components/LoadMore'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { errorMessageKey } from '@/i18n'
/** The button at the end of a song: opens a window to put the song in a playlist. */
export default function AddToPlaylist({ track }: { track: Track }) {
const { t } = useTranslation()
const [open, setOpen] = useState(false)
return (
<>
<Button variant="ghost" size="icon" className="mr-2 size-10" aria-label={t('playlists.add')} onClick={() => setOpen(true)}>
<ListPlus />
</Button>
{open && <AddDialog track={track} onClose={() => setOpen(false)} />}
</>
)
}
function AddDialog({ track, onClose }: { track: Track; onClose: () => void }) {
const { t } = useTranslation()
const playlists = usePlaylists()
const add = useAddTracks()
const create = useCreatePlaylist()
const [name, setName] = useState('')
const [done, setDone] = useState<string | null>(null)
const items = playlists.data?.items ?? []
const busy = add.isPending || create.isPending
const error = add.error ?? create.error
function addTo(id: number, playlistName: string) {
setDone(null)
add.mutate({ id, track_ids: [track.id] }, { onSuccess: () => setDone(playlistName) })
}
async function createAndAdd(event: FormEvent) {
event.preventDefault()
const clean = name.trim()
if (clean === '' || busy) return
setDone(null)
try {
const made = await create.mutateAsync({ name: clean })
await add.mutateAsync({ id: made.id, track_ids: [track.id] })
setDone(made.name)
setName('')
} catch {
// The mutations keep the error, and it is shown below.
}
}
return (
<Dialog open onOpenChange={(isOpen) => !isOpen && onClose()}>
<DialogContent>
<DialogHeader>
<DialogTitle>{t('playlists.addTitle', { title: track.title })}</DialogTitle>
<DialogDescription>{t('playlists.addBody')}</DialogDescription>
</DialogHeader>
{playlists.isPending ? (
<p role="status" className="text-muted-foreground">
{t('common.loading')}
</p>
) : items.length === 0 ? (
<p className="text-muted-foreground">{t('playlists.noneYet')}</p>
) : (
<ul className="flex max-h-64 flex-col gap-1 overflow-y-auto">
{items.map((p) => (
<li key={p.id}>
<Button variant="ghost" className="h-10 w-full justify-between" disabled={busy} onClick={() => addTo(p.id, p.name)}>
<span className="truncate">{p.name}</span>
<span className="text-muted-foreground">{t('playlists.size', { count: p.track_count })}</span>
</Button>
</li>
))}
</ul>
)}
<LoadMore query={playlists} />
<form onSubmit={createAndAdd} className="flex flex-col gap-2">
<Label htmlFor="add-new-playlist">{t('playlists.newName')}</Label>
<div className="flex gap-2">
<Input id="add-new-playlist" value={name} maxLength={200} autoComplete="off" onChange={(e) => setName(e.target.value)} />
<Button type="submit" disabled={name.trim() === '' || busy}>
{t('playlists.createAndAdd')}
</Button>
</div>
</form>
{done && (
<p role="status" className="text-sm font-semibold">
{t('playlists.added', { name: done })}
</p>
)}
{error && (
<p role="alert" className="text-sm text-destructive">
{t(errorMessageKey(error instanceof ApiError ? error.code : 'unknown'))}
</p>
)}
</DialogContent>
</Dialog>
)
}

View file

@ -1,5 +1,6 @@
import type { Track } from '@/api/catalog' import type { Track } from '@/api/catalog'
import { currentTrack, usePlayer } from '@/player/store' import { currentTrack, usePlayer } from '@/player/store'
import AddToPlaylist from './AddToPlaylist'
import TrackRow from './TrackRow' import TrackRow from './TrackRow'
/** The songs of a list. Clicking one plays the whole list from that song. */ /** The songs of a list. Clicking one plays the whole list from that song. */
@ -15,6 +16,7 @@ export default function TrackList({ tracks }: { tracks: Track[] }) {
index={i} index={i}
active={track.id === playingId} active={track.id === playingId}
onPlay={() => playTracks(tracks, i)} onPlay={() => playTracks(tracks, i)}
trailing={<AddToPlaylist track={track} />}
/> />
))} ))}
</div> </div>

View file

@ -1,3 +1,4 @@
import type { ReactNode } from 'react'
import type { Track } from '@/api/catalog' import type { Track } from '@/api/catalog'
import { formatTime } from '@/lib/time' import { formatTime } from '@/lib/time'
import { cn } from '@/lib/utils' import { cn } from '@/lib/utils'
@ -9,29 +10,40 @@ interface TrackRowProps {
onPlay(): void onPlay(): void
/** The track that is playing now. */ /** The track that is playing now. */
active?: boolean active?: boolean
/** The song cannot be played now: it is shown, and clicking it does nothing. */
disabled?: boolean
/** A short note under the title, for a song that needs one ("Not available"). */
note?: string
/** Buttons at the end of the row. They are not part of the button that plays the song. */
trailing?: ReactNode
} }
/** One song in a list: number, title, artists and length. Clicking it plays it. */ /** One song in a list: number, title, artists and length. Clicking it plays it. */
export default function TrackRow({ track, index, onPlay, active = false }: TrackRowProps) { export default function TrackRow({ track, index, onPlay, active = false, disabled = false, note, trailing }: TrackRowProps) {
const artists = track.artists.map((a) => a.name).join(', ') || '—' const artists = track.artists.map((a) => a.name).join(', ') || '—'
return ( return (
<button <div className={cn('flex items-center rounded-lg hover:bg-secondary', active && 'bg-secondary')}>
type="button" <button
onClick={onPlay} type="button"
aria-current={active ? 'true' : undefined} onClick={onPlay}
className={cn( disabled={disabled}
'grid min-h-13 w-full grid-cols-[2.5rem_minmax(0,1fr)_4.5rem] items-center gap-3 rounded-lg px-4 text-left hover:bg-secondary', aria-current={active ? 'true' : undefined}
active && 'bg-secondary', className={cn(
)} 'grid min-h-13 min-w-0 flex-1 grid-cols-[2.5rem_minmax(0,1fr)_4.5rem] items-center gap-3 rounded-lg px-4 text-left',
> disabled && 'opacity-60',
<span className={cn('tabular-nums', active ? 'font-bold text-primary' : 'text-muted-foreground')}> )}
{track.track_no > 0 ? track.track_no : index + 1} >
</span> <span className={cn('tabular-nums', active ? 'font-bold text-primary' : 'text-muted-foreground')}>
<span className="min-w-0"> {track.track_no > 0 ? track.track_no : index + 1}
<span className={cn('block truncate font-semibold', active && 'text-primary')}>{track.title}</span> </span>
<span className="block truncate text-sm text-muted-foreground">{artists}</span> <span className="min-w-0">
</span> <span className={cn('block truncate font-semibold', active && 'text-primary')}>{track.title}</span>
<span className="text-right text-sm tabular-nums text-muted-foreground">{formatTime(track.duration_ms)}</span> <span className="block truncate text-sm text-muted-foreground">{artists}</span>
</button> {note && <span className="block truncate text-sm text-destructive">{note}</span>}
</span>
<span className="text-right text-sm tabular-nums text-muted-foreground">{formatTime(track.duration_ms)}</span>
</button>
{trailing}
</div>
) )
} }

View file

@ -10,6 +10,7 @@ const LINKS = [
{ to: '/artists', key: 'nav.artists', end: false, adminOnly: false }, { to: '/artists', key: 'nav.artists', end: false, adminOnly: false },
{ to: '/albums', key: 'nav.albums', end: false, adminOnly: false }, { to: '/albums', key: 'nav.albums', end: false, adminOnly: false },
{ to: '/songs', key: 'nav.songs', end: false, adminOnly: false }, { to: '/songs', key: 'nav.songs', end: false, adminOnly: false },
{ to: '/playlists', key: 'nav.playlists', end: false, adminOnly: false },
{ to: '/admin', key: 'nav.admin', end: false, adminOnly: true }, { to: '/admin', key: 'nav.admin', end: false, adminOnly: true },
{ to: '/settings', key: 'nav.settings', end: false, adminOnly: false }, { to: '/settings', key: 'nav.settings', end: false, adminOnly: false },
] ]

View file

@ -11,6 +11,7 @@
"artists": "Artists", "artists": "Artists",
"albums": "Albums", "albums": "Albums",
"songs": "Songs", "songs": "Songs",
"playlists": "Playlists",
"admin": "Admin", "admin": "Admin",
"settings": "Settings" "settings": "Settings"
}, },
@ -582,6 +583,41 @@
"invalid_input": "Check what you typed and try again.", "invalid_input": "Check what you typed and try again.",
"unauthorized": "Your session has ended. Sign in again.", "unauthorized": "Your session has ended. Sign in again.",
"network": "Cannot reach the server. Check your connection and try again.", "network": "Cannot reach the server. Check your connection and try again.",
"unknown": "Something went wrong. Try again." "unknown": "Something went wrong. Try again.",
"playlist_not_found": "This playlist does not exist.",
"limit_reached": "Limit reached: a user can have 1000 playlists, and a playlist up to 10000 songs.",
"track_not_found": "This song no longer exists.",
"invalid_position": "That place no longer exists. Reload the playlist."
},
"playlists": {
"empty": "You have no playlists yet. Make one below, or put a song in a new one with the playlist button next to it.",
"newLabel": "Name of the new playlist",
"create": "Create playlist",
"meta_one": "{{count}} song · {{duration}}",
"meta_other": "{{count}} songs · {{duration}}",
"size_one": "{{count}} song",
"size_other": "{{count}} songs",
"notFound": "This playlist does not exist.",
"emptyPlaylist": "This playlist is empty. Put songs in it with the playlist button next to any song.",
"unavailable": "Not available",
"rename": "Rename",
"renameTitle": "Rename playlist",
"nameField": "Name",
"descriptionField": "Description",
"save": "Save",
"delete": "Delete playlist",
"deleteTitle": "Delete {{name}}?",
"deleteBody": "The playlist is deleted. The songs stay in your library.",
"deleteConfirm": "Delete",
"moveUp": "Move up",
"moveDown": "Move down",
"remove": "Remove from playlist",
"add": "Add to playlist",
"addTitle": "Add “{{title}}” to a playlist",
"addBody": "Choose a playlist, or make a new one.",
"noneYet": "You have no playlists yet.",
"newName": "New playlist name",
"createAndAdd": "Create and add",
"added": "Added to {{name}}."
} }
} }

View file

@ -11,6 +11,7 @@
"artists": "Artisti", "artists": "Artisti",
"albums": "Album", "albums": "Album",
"songs": "Brani", "songs": "Brani",
"playlists": "Playlist",
"admin": "Admin", "admin": "Admin",
"settings": "Impostazioni" "settings": "Impostazioni"
}, },
@ -582,6 +583,41 @@
"invalid_input": "Controlla quello che hai scritto e riprova.", "invalid_input": "Controlla quello che hai scritto e riprova.",
"unauthorized": "La sessione è terminata. Accedi di nuovo.", "unauthorized": "La sessione è terminata. Accedi di nuovo.",
"network": "Il server non risponde. Controlla la connessione e riprova.", "network": "Il server non risponde. Controlla la connessione e riprova.",
"unknown": "Qualcosa è andato storto. Riprova." "unknown": "Qualcosa è andato storto. Riprova.",
"playlist_not_found": "Questa playlist non esiste.",
"limit_reached": "Limite raggiunto: un utente può avere 1000 playlist e una playlist fino a 10000 brani.",
"track_not_found": "Questo brano non esiste più.",
"invalid_position": "Quel posto non esiste più. Ricarica la playlist."
},
"playlists": {
"empty": "Non hai ancora nessuna playlist. Creane una qui sotto, oppure metti un brano in una nuova con il pulsante accanto al brano.",
"newLabel": "Nome della nuova playlist",
"create": "Crea playlist",
"meta_one": "{{count}} brano · {{duration}}",
"meta_other": "{{count}} brani · {{duration}}",
"size_one": "{{count}} brano",
"size_other": "{{count}} brani",
"notFound": "Questa playlist non esiste.",
"emptyPlaylist": "Questa playlist è vuota. Mettici dei brani con il pulsante accanto a ogni brano.",
"unavailable": "Non disponibile",
"rename": "Rinomina",
"renameTitle": "Rinomina la playlist",
"nameField": "Nome",
"descriptionField": "Descrizione",
"save": "Salva",
"delete": "Elimina playlist",
"deleteTitle": "Eliminare {{name}}?",
"deleteBody": "La playlist viene eliminata. I brani restano nella tua libreria.",
"deleteConfirm": "Elimina",
"moveUp": "Sposta su",
"moveDown": "Sposta giù",
"remove": "Togli dalla playlist",
"add": "Aggiungi a una playlist",
"addTitle": "Aggiungi «{{title}}» a una playlist",
"addBody": "Scegli una playlist, oppure creane una nuova.",
"noneYet": "Non hai ancora nessuna playlist.",
"newName": "Nome della nuova playlist",
"createAndAdd": "Crea e aggiungi",
"added": "Aggiunto a {{name}}."
} }
} }

View file

@ -0,0 +1,211 @@
import { ArrowDown, ArrowUp, Pencil, Play, Trash2, X } from 'lucide-react'
import { useEffect, useState, type FormEvent } from 'react'
import { useTranslation } from 'react-i18next'
import { useNavigate, useParams } from 'react-router-dom'
import { ApiError } from '@/api/client'
import {
useDeletePlaylist,
useMoveItem,
usePlaylist,
usePlaylistItems,
useRemoveItem,
useUpdatePlaylist,
type Playlist,
type PlaylistItem,
} from '@/api/playlists'
import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status'
import TrackRow from '@/components/TrackRow'
import { Button } from '@/components/ui/button'
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from '@/components/ui/dialog'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { errorMessageKey } from '@/i18n'
import { formatTime } from '@/lib/time'
import { currentTrack, usePlayer } from '@/player/store'
import Confirm from '@/pages/admin/Confirm'
export default function PlaylistPage() {
const { t } = useTranslation()
const id = Number(useParams().id)
if (!Number.isInteger(id) || id < 1) return <EmptyMessage>{t('playlists.notFound')}</EmptyMessage>
return <PlaylistView id={id} />
}
function errorLine(t: (key: string) => string, error: unknown) {
return t(errorMessageKey(error instanceof ApiError ? error.code : 'unknown'))
}
function PlaylistView({ id }: { id: number }) {
const { t } = useTranslation()
const navigate = useNavigate()
const playlist = usePlaylist(id)
const query = usePlaylistItems(id)
const move = useMoveItem()
const remove = useRemoveItem()
const del = useDeletePlaylist()
const playTracks = usePlayer((s) => s.playTracks)
const playingId = usePlayer((s) => currentTrack(s)?.id)
const [renaming, setRenaming] = useState(false)
const [deleting, setDeleting] = useState(false)
const [started, setStarted] = useState<number | null>(null)
// A playlist is read whole: Play and the order need every song, and a playlist is not huge.
// It also runs when more songs arrive: a quick answer may never show as "fetching".
const { hasNextPage, isFetchingNextPage, fetchNextPage } = query
const loaded = query.data?.items.length
useEffect(() => {
if (hasNextPage && !isFetchingNextPage) void fetchNextPage()
}, [hasNextPage, isFetchingNextPage, fetchNextPage, loaded])
if (playlist.isError) {
if (playlist.error instanceof ApiError && playlist.error.status === 404) return <EmptyMessage>{t('playlists.notFound')}</EmptyMessage>
return <ErrorMessage error={playlist.error} onRetry={() => playlist.refetch()} />
}
if (!playlist.data) return <Loading />
const p = playlist.data
const rows = query.data?.items ?? []
const playable = rows.filter((r) => r.available)
const playableIds = playable.map((r) => r.track.id)
const busy = move.isPending || remove.isPending
function play(row: PlaylistItem | null) {
const from = row ? playable.findIndex((r) => r.id === row.id) : 0
if (from < 0) return
setStarted(row ? row.id : (playable[0]?.id ?? null))
playTracks(playable.map((r) => r.track), from)
}
// The row that plays: the one that was started if it is still the song that plays, else the first with that song.
const sameSong = rows.filter((r) => r.available && r.track.id === playingId)
const activeId = (sameSong.find((r) => r.id === started) ?? sameSong[0])?.id
return (
<div className="flex flex-col gap-8">
<header className="flex flex-col gap-3">
<h1 className="text-4xl font-extrabold tracking-tight md:text-6xl">{p.name}</h1>
{p.description && <p className="max-w-2xl text-muted-foreground">{p.description}</p>}
<p className="text-muted-foreground">{t('playlists.meta', { count: p.track_count, duration: formatTime(p.duration_ms) })}</p>
<div className="flex flex-wrap gap-2">
<Button className="h-12 gap-2 rounded-md px-6" disabled={playableIds.length === 0} onClick={() => play(null)}>
<Play />
{t('player.play')}
</Button>
<Button variant="outline" className="h-12 gap-2" onClick={() => setRenaming(true)}>
<Pencil />
{t('playlists.rename')}
</Button>
<Button variant="outline" className="h-12 gap-2" onClick={() => setDeleting(true)}>
<Trash2 />
{t('playlists.delete')}
</Button>
</div>
</header>
{(move.isError || remove.isError || del.isError) && (
<p role="alert" className="text-sm text-destructive">
{errorLine(t, move.error ?? remove.error ?? del.error)}
</p>
)}
{query.isError ? (
<ErrorMessage error={query.error} onRetry={() => query.refetch()} />
) : query.isPending ? (
<Loading />
) : rows.length === 0 ? (
<EmptyMessage>{t('playlists.emptyPlaylist')}</EmptyMessage>
) : (
<div className="flex flex-col">
{rows.map((row, i) => (
<TrackRow
key={row.id}
track={row.track}
index={i}
active={row.id === activeId}
disabled={!row.available}
note={row.available ? undefined : t('playlists.unavailable')}
onPlay={() => play(row)}
trailing={
<div className="flex flex-none items-center pr-2">
<Button variant="ghost" size="icon" aria-label={t('playlists.moveUp')} disabled={busy || i === 0}
onClick={() => move.mutate({ id, item: row.id, position: i - 1 })}>
<ArrowUp />
</Button>
<Button variant="ghost" size="icon" aria-label={t('playlists.moveDown')} disabled={busy || i === rows.length - 1}
onClick={() => move.mutate({ id, item: row.id, position: i + 1 })}>
<ArrowDown />
</Button>
<Button variant="ghost" size="icon" aria-label={t('playlists.remove')} disabled={busy}
onClick={() => remove.mutate({ id, item: row.id })}>
<X />
</Button>
</div>
}
/>
))}
</div>
)}
{renaming && <RenameDialog playlist={p} onClose={() => setRenaming(false)} />}
{deleting && (
<Confirm
title={t('playlists.deleteTitle', { name: p.name })}
body={t('playlists.deleteBody')}
confirm={t('playlists.deleteConfirm')}
onClose={() => setDeleting(false)}
onConfirm={() => {
setDeleting(false)
del.mutate(id, { onSuccess: () => navigate('/playlists') })
}}
/>
)}
</div>
)
}
function RenameDialog({ playlist, onClose }: { playlist: Playlist; onClose: () => void }) {
const { t } = useTranslation()
const update = useUpdatePlaylist()
const [name, setName] = useState(playlist.name)
const [description, setDescription] = useState(playlist.description)
const ready = name.trim() !== ''
function submit(event: FormEvent) {
event.preventDefault()
if (!ready || update.isPending) return
update.mutate({ id: playlist.id, name: name.trim(), description: description.trim() }, { onSuccess: onClose })
}
return (
<Dialog open onOpenChange={(open) => !open && onClose()}>
<DialogContent>
<form onSubmit={submit} className="flex flex-col gap-4">
<DialogHeader>
<DialogTitle>{t('playlists.renameTitle')}</DialogTitle>
</DialogHeader>
<div className="flex flex-col gap-2">
<Label htmlFor="playlist-name">{t('playlists.nameField')}</Label>
<Input id="playlist-name" value={name} maxLength={200} autoComplete="off" onChange={(e) => setName(e.target.value)} />
</div>
<div className="flex flex-col gap-2">
<Label htmlFor="playlist-description">{t('playlists.descriptionField')}</Label>
<Input id="playlist-description" value={description} maxLength={2000} autoComplete="off" onChange={(e) => setDescription(e.target.value)} />
</div>
{update.isError && (
<p role="alert" className="text-sm text-destructive">
{errorLine(t, update.error)}
</p>
)}
<DialogFooter>
<Button type="button" variant="outline" onClick={onClose}>
{t('admin.cancel')}
</Button>
<Button type="submit" disabled={!ready || update.isPending}>
{t('playlists.save')}
</Button>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}

View file

@ -0,0 +1,73 @@
import { useState, type FormEvent } from 'react'
import { useTranslation } from 'react-i18next'
import { Link } from 'react-router-dom'
import { ApiError } from '@/api/client'
import { useCreatePlaylist, usePlaylists } from '@/api/playlists'
import LoadMore from '@/components/LoadMore'
import { EmptyMessage, ErrorMessage, Loading } from '@/components/Status'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { errorMessageKey } from '@/i18n'
import { formatTime } from '@/lib/time'
/** Your playlists, and a form to make another. */
export default function PlaylistsPage() {
const { t } = useTranslation()
const query = usePlaylists()
const create = useCreatePlaylist()
const [name, setName] = useState('')
const items = query.data?.items ?? []
const ready = name.trim() !== ''
function submit(event: FormEvent) {
event.preventDefault()
if (!ready || create.isPending) return
create.mutate({ name: name.trim() }, { onSuccess: () => setName('') })
}
return (
<div className="flex flex-col gap-6">
<h1 className="text-3xl font-extrabold tracking-tight">{t('nav.playlists')}</h1>
{query.isError ? (
<ErrorMessage error={query.error} onRetry={() => query.refetch()} />
) : query.isPending ? (
<Loading />
) : items.length === 0 ? (
<EmptyMessage>{t('playlists.empty')}</EmptyMessage>
) : (
<>
<ul className="flex flex-col">
{items.map((p) => (
<li key={p.id}>
<Link to={`/playlists/${p.id}`} className="flex min-h-14 items-center justify-between gap-4 rounded-lg px-4 hover:bg-secondary">
<span className="truncate font-semibold">{p.name}</span>
<span className="flex-none text-sm text-muted-foreground">
{t('playlists.meta', { count: p.track_count, duration: formatTime(p.duration_ms) })}
</span>
</Link>
</li>
))}
</ul>
<LoadMore query={query} />
</>
)}
<form onSubmit={submit} className="flex max-w-xl flex-col gap-2">
<Label htmlFor="new-playlist">{t('playlists.newLabel')}</Label>
<div className="flex gap-2">
<Input id="new-playlist" value={name} maxLength={200} autoComplete="off" onChange={(e) => setName(e.target.value)} />
<Button type="submit" disabled={!ready || create.isPending}>
{t('playlists.create')}
</Button>
</div>
{create.isError && (
<p role="alert" className="text-sm text-destructive">
{t(errorMessageKey(create.error instanceof ApiError ? create.error.code : 'unknown'))}
</p>
)}
</form>
</div>
)
}

View file

@ -0,0 +1,331 @@
import { QueryClient, QueryClientProvider } from '@tanstack/react-query'
import { render, screen, waitFor, within } from '@testing-library/react'
import userEvent from '@testing-library/user-event'
import type { ReactElement } from 'react'
import { MemoryRouter, Route, Routes } from 'react-router-dom'
import { beforeEach, expect, test, vi } from 'vitest'
import { sessionStore } from '@/auth/session'
import { initI18n } from '@/i18n'
import { usePlayer } from '@/player/store'
import { apiError, mockFetch, type MockRoutes } from '@/test/mockFetch'
import PlaylistPage from './PlaylistPage'
import PlaylistsPage from './PlaylistsPage'
import SongsPage from './SongsPage'
// --- fixtures ---------------------------------------------------------------------------------
const artistRef = { id: 5, name: 'Radiohead' }
function track(n: number) {
return {
id: n,
title: `Song ${n}`,
duration_ms: 200_000,
track_no: n,
disc_no: 1,
album: { id: 9, title: 'OK Computer' },
artists: [artistRef],
format: 'flac',
}
}
function playlist(id: number, name: string, over: object = {}) {
return {
id,
name,
description: '',
track_count: 3,
duration_ms: 600_000,
created_at: '2026-11-01T10:00:00Z',
updated_at: '2026-11-02T10:00:00Z',
...over,
}
}
/** Items of a playlist: item ids are 10 + position, so they differ from the track ids. */
function item(position: number, trackId: number, available = true) {
return { id: 10 + position, position, available, added_at: '2026-11-02T10:00:00Z', track: track(trackId) }
}
const page = (items: object[], total = items.length) => ({ items, total, limit: 200, offset: 0 })
function renderPage(element: ReactElement, path: string, routePath: string) {
const client = new QueryClient({ defaultOptions: { queries: { retry: false } } })
return render(
<QueryClientProvider client={client}>
<MemoryRouter initialEntries={[path]}>
<Routes>
<Route path={routePath} element={element} />
<Route path="/playlists" element={<p>THE LIST OF PLAYLISTS</p>} />
</Routes>
</MemoryRouter>
</QueryClientProvider>,
)
}
beforeEach(async () => {
vi.spyOn(navigator, 'language', 'get').mockReturnValue('en-US')
await initI18n()
sessionStore.setState({ status: 'authenticated', user: { id: 1, email: 'tom@example.org', is_admin: false } })
usePlayer.setState({ queue: [], original: [], index: 0, playing: false, positionMs: 0, shuffle: false, repeat: 'off', seekMs: null, seekId: 0, playId: 0 })
})
// --- the list of playlists ----------------------------------------------------------------------
test('the playlists page lists mine, each linking to its own page', async () => {
mockFetch({
'GET /api/v1/playlists': () => page([playlist(3, 'Road trip'), playlist(4, 'Quiet', { track_count: 1, duration_ms: 90_000 })]),
})
renderPage(<PlaylistsPage />, '/playlists', '/playlists')
const link = await screen.findByRole('link', { name: /Road trip/ })
expect(link).toHaveAttribute('href', '/playlists/3')
expect(within(link).getByText(/3 songs/)).toBeInTheDocument()
expect(screen.getByRole('link', { name: /Quiet/ })).toHaveTextContent('1 song')
})
test('with no playlist the page says so and offers to make one', async () => {
mockFetch({ 'GET /api/v1/playlists': () => page([]) })
renderPage(<PlaylistsPage />, '/playlists', '/playlists')
expect(await screen.findByText(/no playlists yet/i)).toBeInTheDocument()
expect(screen.getByRole('textbox', { name: 'Name of the new playlist' })).toBeInTheDocument()
})
test('a new playlist is made with the name that was typed, and the list is read again', async () => {
let made = false
const { calls } = mockFetch({
'GET /api/v1/playlists': () => page(made ? [playlist(7, 'Gym')] : []),
'POST /api/v1/playlists': () => {
made = true
return new Response(JSON.stringify(playlist(7, 'Gym', { track_count: 0, duration_ms: 0 })), { status: 201, headers: { 'Content-Type': 'application/json' } })
},
})
renderPage(<PlaylistsPage />, '/playlists', '/playlists')
await userEvent.type(await screen.findByRole('textbox', { name: 'Name of the new playlist' }), ' Gym ')
await userEvent.click(screen.getByRole('button', { name: 'Create playlist' }))
expect(await screen.findByRole('link', { name: /Gym/ })).toBeInTheDocument()
const post = calls.find((c) => c.key === 'POST /api/v1/playlists')!
expect(JSON.parse(post.init.body as string)).toEqual({ name: 'Gym' })
expect(screen.getByRole('textbox', { name: 'Name of the new playlist' })).toHaveValue('')
})
test('the button waits for a name, and a refused playlist says why', async () => {
mockFetch({
'GET /api/v1/playlists': () => page([]),
'POST /api/v1/playlists': () => apiError(409, 'limit_reached'),
})
renderPage(<PlaylistsPage />, '/playlists', '/playlists')
const button = await screen.findByRole('button', { name: 'Create playlist' })
expect(button).toBeDisabled()
await userEvent.type(screen.getByRole('textbox', { name: 'Name of the new playlist' }), 'One more')
await userEvent.click(button)
expect(await screen.findByRole('alert')).toHaveTextContent(/limit/i)
})
// --- one playlist -----------------------------------------------------------------------------
function onePlaylist(over: MockRoutes = {}, items = [item(0, 1), item(1, 2), item(2, 3)]): MockRoutes {
return {
'GET /api/v1/playlists/3': () => playlist(3, 'Road trip', { description: 'for the car', track_count: items.length }),
'GET /api/v1/playlists/3/tracks': () => page(items),
...over,
}
}
const open = () => renderPage(<PlaylistPage />, '/playlists/3', '/playlists/:id')
test('a playlist shows its name, description, size and songs in order', async () => {
mockFetch(onePlaylist())
open()
expect(await screen.findByRole('heading', { level: 1, name: 'Road trip' })).toBeInTheDocument()
expect(screen.getByText('for the car')).toBeInTheDocument()
expect(screen.getByText(/3 songs/)).toBeInTheDocument()
const rows = await screen.findAllByRole('button', { name: /Song \d/ })
expect(rows.map((r) => r.textContent)).toEqual([expect.stringContaining('Song 1'), expect.stringContaining('Song 2'), expect.stringContaining('Song 3')])
})
test('an empty playlist says how to fill it', async () => {
mockFetch(onePlaylist({}, []))
open()
expect(await screen.findByText(/This playlist is empty/)).toBeInTheDocument()
expect(screen.getByRole('button', { name: 'Play' })).toBeDisabled()
})
test('a song that is not available is marked, cannot be played and is skipped by the playlist', async () => {
mockFetch(onePlaylist({}, [item(0, 1), item(1, 2, false), item(2, 3)]))
open()
await screen.findByRole('heading', { name: 'Road trip' })
expect(await screen.findByText('Not available')).toBeInTheDocument()
expect(screen.getByRole('button', { name: /Song 2/ })).toBeDisabled()
await userEvent.click(screen.getByRole('button', { name: 'Play' }))
expect(usePlayer.getState().queue.map((t) => t.id)).toEqual([1, 3])
expect(usePlayer.getState().index).toBe(0)
})
test('a click on a song plays the playlist from that song', async () => {
mockFetch(onePlaylist({}, [item(0, 1), item(1, 2, false), item(2, 3), item(3, 4)]))
open()
await userEvent.click(await screen.findByRole('button', { name: /Song 3/ }))
expect(usePlayer.getState().queue.map((t) => t.id)).toEqual([1, 3, 4])
expect(usePlayer.getState().index).toBe(1)
expect(usePlayer.getState().playing).toBe(true)
})
test('the same song twice is two rows, and the one that plays is marked, not both', async () => {
mockFetch(onePlaylist({}, [item(0, 1), item(1, 2), item(2, 1)]))
open()
const rows = await screen.findAllByRole('button', { name: /Song \d/ })
expect(rows).toHaveLength(3)
await userEvent.click(rows[2])
expect(usePlayer.getState().index).toBe(2)
expect(screen.getAllByRole('button', { name: /Song 1/ })[1]).toHaveAttribute('aria-current', 'true')
expect(screen.getAllByRole('button', { name: /Song 1/ })[0]).not.toHaveAttribute('aria-current')
})
test('a song moves down by one place, and the first cannot go up nor the last down', async () => {
const { calls } = mockFetch(onePlaylist({ 'PATCH /api/v1/playlists/3/tracks/10': () => new Response(null, { status: 204 }) }))
open()
await screen.findAllByRole('button', { name: /Song \d/ })
const downs = screen.getAllByRole('button', { name: 'Move down' })
const ups = screen.getAllByRole('button', { name: 'Move up' })
expect(ups[0]).toBeDisabled()
expect(downs[2]).toBeDisabled()
await userEvent.click(downs[0])
await waitFor(() => expect(calls.some((c) => c.key === 'PATCH /api/v1/playlists/3/tracks/10')).toBe(true))
const patch = calls.find((c) => c.key === 'PATCH /api/v1/playlists/3/tracks/10')!
expect(JSON.parse(patch.init.body as string)).toEqual({ position: 1 })
})
test('a song moves up by one place', async () => {
const { calls } = mockFetch(onePlaylist({ 'PATCH /api/v1/playlists/3/tracks/12': () => new Response(null, { status: 204 }) }))
open()
await screen.findAllByRole('button', { name: /Song \d/ })
await userEvent.click(screen.getAllByRole('button', { name: 'Move up' })[2])
await waitFor(() => expect(calls.some((c) => c.key === 'PATCH /api/v1/playlists/3/tracks/12')).toBe(true))
expect(JSON.parse(calls.find((c) => c.key === 'PATCH /api/v1/playlists/3/tracks/12')!.init.body as string)).toEqual({ position: 1 })
})
test('a song is taken out with its item id, not its track id', async () => {
const { calls } = mockFetch(onePlaylist({ 'DELETE /api/v1/playlists/3/tracks/11': () => new Response(null, { status: 204 }) }))
open()
await screen.findAllByRole('button', { name: /Song \d/ })
await userEvent.click(screen.getAllByRole('button', { name: 'Remove from playlist' })[1])
await waitFor(() => expect(calls.some((c) => c.key === 'DELETE /api/v1/playlists/3/tracks/11')).toBe(true))
})
test('a playlist is renamed from a window, and an empty name is not sent', async () => {
const { calls } = mockFetch(onePlaylist({ 'PATCH /api/v1/playlists/3': () => playlist(3, 'Long drive') }))
open()
await userEvent.click(await screen.findByRole('button', { name: 'Rename' }))
const dialog = await screen.findByRole('dialog')
const name = within(dialog).getByRole('textbox', { name: 'Name' })
expect(name).toHaveValue('Road trip')
await userEvent.clear(name)
expect(within(dialog).getByRole('button', { name: 'Save' })).toBeDisabled()
await userEvent.type(name, 'Long drive')
await userEvent.click(within(dialog).getByRole('button', { name: 'Save' }))
await waitFor(() => expect(calls.some((c) => c.key === 'PATCH /api/v1/playlists/3')).toBe(true))
expect(JSON.parse(calls.find((c) => c.key === 'PATCH /api/v1/playlists/3')!.init.body as string)).toEqual({ name: 'Long drive', description: 'for the car' })
})
test('deleting a playlist asks first, then goes back to the list', async () => {
const { calls } = mockFetch(onePlaylist({ 'DELETE /api/v1/playlists/3': () => new Response(null, { status: 204 }) }))
open()
await userEvent.click(await screen.findByRole('button', { name: 'Delete playlist' }))
expect(calls.some((c) => c.key === 'DELETE /api/v1/playlists/3')).toBe(false)
const dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/The songs stay in your library/)).toBeInTheDocument()
await userEvent.click(within(dialog).getByRole('button', { name: 'Delete' }))
expect(await screen.findByText('THE LIST OF PLAYLISTS')).toBeInTheDocument()
expect(calls.some((c) => c.key === 'DELETE /api/v1/playlists/3')).toBe(true)
})
test('a playlist that does not exist says so', async () => {
mockFetch({
'GET /api/v1/playlists/3': () => apiError(404, 'playlist_not_found'),
'GET /api/v1/playlists/3/tracks': () => apiError(404, 'playlist_not_found'),
})
open()
expect(await screen.findByText(/does not exist/)).toBeInTheDocument()
})
test('every page of a long playlist is read, so Play starts from the real beginning', async () => {
const all = Array.from({ length: 5 }, (_, i) => item(i, i + 1))
const { calls } = mockFetch({
'GET /api/v1/playlists/3': () => playlist(3, 'Long', { track_count: 5 }),
'GET /api/v1/playlists/3/tracks': ({ url }) => {
const limit = Number(url.searchParams.get('limit'))
const offset = Number(url.searchParams.get('offset'))
return { items: all.slice(offset, offset + Math.min(limit, 2)), total: 5, limit, offset }
},
})
open()
await waitFor(() => expect(screen.getAllByRole('button', { name: /Song \d/ })).toHaveLength(5))
expect(calls.filter((c) => c.key === 'GET /api/v1/playlists/3/tracks').length).toBeGreaterThanOrEqual(3)
})
// --- adding a song to a playlist ------------------------------------------------------------------
function songs(over: MockRoutes = {}): MockRoutes {
return {
'GET /api/v1/tracks': () => ({ items: [track(1), track(2)], total: 2, limit: 50, offset: 0 }),
'GET /api/v1/playlists': () => page([playlist(3, 'Road trip'), playlist(4, 'Quiet')]),
...over,
}
}
test('the button next to a song opens the playlists to choose from, and does not play the song', async () => {
mockFetch(songs())
renderPage(<SongsPage />, '/songs', '/songs')
const buttons = await screen.findAllByRole('button', { name: 'Add to playlist' })
expect(buttons).toHaveLength(2)
await userEvent.click(buttons[1])
const dialog = await screen.findByRole('dialog')
expect(within(dialog).getByText(/Song 2/)).toBeInTheDocument()
expect(await within(dialog).findByRole('button', { name: /Road trip/ })).toBeInTheDocument()
expect(within(dialog).getByRole('button', { name: /Quiet/ })).toBeInTheDocument()
expect(usePlayer.getState().queue).toEqual([])
})
test('choosing a playlist adds that song to it and says so', async () => {
const { calls } = mockFetch(songs({ 'POST /api/v1/playlists/3/tracks': () => playlist(3, 'Road trip', { track_count: 4 }) }))
renderPage(<SongsPage />, '/songs', '/songs')
await userEvent.click((await screen.findAllByRole('button', { name: 'Add to playlist' }))[1])
await userEvent.click(await screen.findByRole('button', { name: /Road trip/ }))
expect(await screen.findByText('Added to Road trip.')).toBeInTheDocument()
const post = calls.find((c) => c.key === 'POST /api/v1/playlists/3/tracks')!
expect(JSON.parse(post.init.body as string)).toEqual({ track_ids: [2] })
})
test('a new playlist can be made from the window, and the song goes into it', async () => {
const { calls } = mockFetch(
songs({
'POST /api/v1/playlists': () => new Response(JSON.stringify(playlist(8, 'Fresh', { track_count: 0 })), { status: 201, headers: { 'Content-Type': 'application/json' } }),
'POST /api/v1/playlists/8/tracks': () => playlist(8, 'Fresh', { track_count: 1 }),
}),
)
renderPage(<SongsPage />, '/songs', '/songs')
await userEvent.click((await screen.findAllByRole('button', { name: 'Add to playlist' }))[0])
const dialog = await screen.findByRole('dialog')
await userEvent.type(within(dialog).getByRole('textbox', { name: 'New playlist name' }), 'Fresh')
await userEvent.click(within(dialog).getByRole('button', { name: 'Create and add' }))
expect(await screen.findByText('Added to Fresh.')).toBeInTheDocument()
expect(JSON.parse(calls.find((c) => c.key === 'POST /api/v1/playlists')!.init.body as string)).toEqual({ name: 'Fresh' })
expect(JSON.parse(calls.find((c) => c.key === 'POST /api/v1/playlists/8/tracks')!.init.body as string)).toEqual({ track_ids: [1] })
})
test('a refusal while adding is shown in the window', async () => {
mockFetch(songs({ 'POST /api/v1/playlists/3/tracks': () => apiError(409, 'limit_reached') }))
renderPage(<SongsPage />, '/songs', '/songs')
await userEvent.click((await screen.findAllByRole('button', { name: 'Add to playlist' }))[0])
await userEvent.click(await screen.findByRole('button', { name: /Road trip/ }))
expect(await screen.findByRole('alert')).toHaveTextContent(/limit/i)
})
test('with no playlist yet the window says so and still lets you make one', async () => {
mockFetch(songs({ 'GET /api/v1/playlists': () => page([]) }))
renderPage(<SongsPage />, '/songs', '/songs')
await userEvent.click((await screen.findAllByRole('button', { name: 'Add to playlist' }))[0])
const dialog = await screen.findByRole('dialog')
expect(await within(dialog).findByText(/no playlists yet/i)).toBeInTheDocument()
expect(within(dialog).getByRole('textbox', { name: 'New playlist name' })).toBeInTheDocument()
})

View file

@ -13,6 +13,8 @@ import LibrariesPage from '@/pages/admin/LibrariesPage'
import ProvidersPage from '@/pages/admin/ProvidersPage' import ProvidersPage from '@/pages/admin/ProvidersPage'
import UsersPage from '@/pages/admin/UsersPage' import UsersPage from '@/pages/admin/UsersPage'
import NotFoundPage from '@/pages/NotFoundPage' import NotFoundPage from '@/pages/NotFoundPage'
import PlaylistPage from '@/pages/PlaylistPage'
import PlaylistsPage from '@/pages/PlaylistsPage'
import SearchPage from '@/pages/SearchPage' import SearchPage from '@/pages/SearchPage'
import SettingsPage from '@/pages/SettingsPage' import SettingsPage from '@/pages/SettingsPage'
import SongsPage from '@/pages/SongsPage' import SongsPage from '@/pages/SongsPage'
@ -29,6 +31,8 @@ export const routes: RouteObject[] = [
{ path: '/albums', element: <AlbumsPage /> }, { path: '/albums', element: <AlbumsPage /> },
{ path: '/albums/:id', element: <AlbumPage /> }, { path: '/albums/:id', element: <AlbumPage /> },
{ path: '/songs', element: <SongsPage /> }, { path: '/songs', element: <SongsPage /> },
{ path: '/playlists', element: <PlaylistsPage /> },
{ path: '/playlists/:id', element: <PlaylistPage /> },
{ path: '/settings', element: <SettingsPage /> }, { path: '/settings', element: <SettingsPage /> },
{ {
path: '/admin', path: '/admin',