Keeps a page's list of playlists in step with the socket's playlist_* messages, and their owners' names. The user's profile, the playlists page and the search call it.

Functions

f
usePlaylistListSync(
items: Playlist[],
setPlaylists: (fn: (prev: Playlist[]) => Playlist[]) => void,
options?: PlaylistListSyncOptions
): void

Applies the socket's playlist events to items, the loaded list, which setPlaylists updates. A created playlist goes where the list's order puts it, an updated one changes in place or leaves when it turns private (unless isOwner), one that left comes back where it was when it returns, a deleted one leaves, and a playlist's dumpCount and lastDumpAt follow its dumps. One that a change brings up the order moves up to its place, as a playlist does in the updated order when it takes a dump; one that falls stays where it is, its place being perhaps on a page not loaded. A renamed user's playlists take their new name.

Interfaces

I
PlaylistListSyncOptions

Passed to usePlaylistListSync by each page, to fit its list.

  • isOwner: boolean

    Keeps private playlists in the list, for their owner.

  • ownerId: string

    Adds only this user's playlists, when one is created or comes back into view. Without it, anyone's are added.

  • sort: PlaylistSort

    The order the list is in, for one the API sorts: the playlists page's and a profile's. A list in an order of its own leaves it out, the followed playlists being by the date they were followed and a search's results the search's: it takes no new playlist, since the socket says neither what the user follows nor what a search matches, and moves none. Playlists already listed still change, go, and come back where they were.