Everything a playlist's page shows and changes goes through this hook. It loads the playlist with its dumps, keeps them live, and makes the changes its owner or a moderator makes there.
Returns the playlist at /@username/playlists/slug from
GET /api/users/@:username/playlists/:slug, with the dumps the viewer may
see in it. The socket's events keep its details and dumps live: a dump
another client removes, or that turns private, fades out, one it adds, or
that turns public, is fetched, a new order is applied, and a playlist
deleted, or turned private by someone else, sends the page home. A
reconnection loads it again. A new slug replaces the URL, keeping
the page's view, and a path that names the playlist on screen, as that
one does, fetches nothing.
Returned by usePlaylist to PlaylistDetail.
-
actionError: string | null
It says why the server refused a removal, a reorder or a delete.
-
applyDetails: (playlist: Playlist) => void
Shows the playlist as
PlaylistEditFormsaved it. -
deletePlaylist: () => Promise<void>
Leaves for home once the playlist is deleted, or sets
actionError. -
fading: Record<string, FadeState>
It holds the dumps being removed, which stay listed while they fade. A dump in it can't be dragged, and during its
cooldownits removal can be undone. -
move: () => voidfrom: number,to: number
Moves the dump at
fromtoto, counted among the dumps not fading, on screen only, as a drag goes along. -
remove: (dumpId: string) => void
Fades the dump out, and takes it out of the playlist on the server when the fade ends, or when the page is left before.
-
saveOrder: () => void
Sends the order
moveleft, as a drag ends. - state: FetchState<PlaylistWithDumps>
-
undoRemove: (dumpId: string) => void
Keeps a dump that
removeis fading out. Nothing was sent yet.
Usage
import * as mod from "src/hooks/playlist/usePlaylist.ts";