mirror of
https://github.com/Psychotoxical/psysonic.git
synced 2026-07-22 15:25:46 +00:00
feat(genre): play, shuffle and queue buttons on the genre view (#926)
* feat(genre): add paginated songs-by-genre API Wraps the Subsonic getSongsByGenre endpoint plus a fetchAllSongsByGenre helper that paginates until exhausted, capped to keep the queue and the burst of requests bounded for very large genres. * refactor(playback): extract shared bulk play/shuffle/enqueue helper A single fetchTracks-driven core (loading flag, empty guard, canonical shuffleArray) so async detail-page play buttons stop growing divergent copies. Artist detail now reuses it, dropping its weaker sort-random shuffle. * feat(genre): play, shuffle and queue buttons on the genre view Header buttons load the genre's songs and start ordered or shuffled playback, or append them to the queue. The slice is bounded to stay within the queue resolver's cache budget so every row resolves instead of rendering as a placeholder. Strings added across all nine locales. * docs(changelog): genre play/shuffle buttons (#926)
This commit is contained in:
committed by
GitHub
parent
6c74cae0b7
commit
e734a8fc43
@@ -1,5 +1,5 @@
|
||||
import { api, libraryFilterParams } from './subsonicClient';
|
||||
import type { SubsonicAlbum, SubsonicGenre } from './subsonicTypes';
|
||||
import type { SubsonicAlbum, SubsonicGenre, SubsonicSong } from './subsonicTypes';
|
||||
|
||||
export async function getGenres(): Promise<SubsonicGenre[]> {
|
||||
const data = await api<{ genres: { genre: SubsonicGenre | SubsonicGenre[] } }>('getGenres.view');
|
||||
@@ -21,3 +21,32 @@ export async function getAlbumsByGenre(genre: string, size = 50, offset = 0): Pr
|
||||
if (!raw) return [];
|
||||
return Array.isArray(raw) ? raw : [raw];
|
||||
}
|
||||
|
||||
/** Single page of songs for a genre (Subsonic `getSongsByGenre`, supported by Navidrome). */
|
||||
export async function getSongsByGenre(genre: string, count = 500, offset = 0): Promise<SubsonicSong[]> {
|
||||
const data = await api<{ songsByGenre: { song: SubsonicSong | SubsonicSong[] } }>('getSongsByGenre.view', {
|
||||
genre,
|
||||
count,
|
||||
offset,
|
||||
_t: Date.now(),
|
||||
...libraryFilterParams(),
|
||||
});
|
||||
const raw = data.songsByGenre?.song;
|
||||
if (!raw) return [];
|
||||
return Array.isArray(raw) ? raw : [raw];
|
||||
}
|
||||
|
||||
/**
|
||||
* Every song in a genre, paginated until exhausted. Capped to keep the queue and the
|
||||
* burst of server requests bounded for very large genres (a handful of sequential pages).
|
||||
*/
|
||||
export async function fetchAllSongsByGenre(genre: string, cap = 5000): Promise<SubsonicSong[]> {
|
||||
const PAGE = 500;
|
||||
const songs: SubsonicSong[] = [];
|
||||
for (let offset = 0; songs.length < cap; offset += PAGE) {
|
||||
const page = await getSongsByGenre(genre, PAGE, offset);
|
||||
songs.push(...page);
|
||||
if (page.length < PAGE) break;
|
||||
}
|
||||
return songs.length > cap ? songs.slice(0, cap) : songs;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user