feat(smart): covers on the Smart playlists page

- GET /smart-playlists/{id}/covers and GET /smart-playlists/suggested/{key}/covers say which albums stand for a smart playlist: up to 4 albums that have a cover, in the order of the songs the rules give now (for the variant asked), each once. They are worked out apart from the songs, and the answer may be kept for a few minutes.
- The cards of the Smart playlists page are a grid with the collage. The list shows at once and each card asks for its own covers after that, showing the rings until they arrive or when they cannot be read.
- The pages of a smart playlist and of a suggested one use the same covers for the variant on screen, so only albums that have a cover are shown.
This commit is contained in:
tgiachi 2026-11-13 11:41:23 +01:00
commit 82b92eaf08
2 changed files with 648 additions and 67 deletions

View file

@ -1012,6 +1012,32 @@ export interface paths {
patch?: never;
trace?: never;
};
"/smart-playlists/suggested/{key}/covers": {
parameters: {
query?: never;
header?: never;
path: {
/** @description A key from `GET /smart-playlists/suggested`. */
key: components["parameters"]["SuggestedKey"];
};
cookie?: never;
};
/**
* The covers of a suggested smart playlist
* @description Up to 4 albums that have a cover and stand for it, in the order of the songs the rules give now (the ones of
* `variant`), each once: their covers (`GET /albums/{id}/cover`) make its picture. It is worked out apart from the
* songs so that a list of smart playlists can show the rest without waiting for the rules of every one of them; the
* answer may be kept by the client for a few minutes. Empty when none of the songs has an album with a cover.
*/
get: operations["getSuggestedSmartPlaylistCovers"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/smart-playlists/suggested/{key}/playlist": {
parameters: {
query?: never;
@ -1093,6 +1119,31 @@ export interface paths {
patch?: never;
trace?: never;
};
"/smart-playlists/{id}/covers": {
parameters: {
query?: never;
header?: never;
path: {
id: components["parameters"]["Id"];
};
cookie?: never;
};
/**
* The covers of a smart playlist
* @description Up to 4 albums that have a cover and stand for it, in the order of the songs the rules give now (the ones of
* `variant`), each once: their covers (`GET /albums/{id}/cover`) make its picture. It is worked out apart from the
* songs so that a list of smart playlists can show the rest without waiting for the rules of every one of them; the
* answer may be kept by the client for a few minutes. Empty when none of the songs has an album with a cover.
*/
get: operations["getSmartPlaylistCovers"];
put?: never;
post?: never;
delete?: never;
options?: never;
head?: never;
patch?: never;
trace?: never;
};
"/smart-playlists/{id}/playlist": {
parameters: {
query?: never;
@ -2657,6 +2708,9 @@ export interface components {
/** @default 0 */
variant: number;
};
SmartCovers: {
album_ids: number[];
};
SmartTracks: {
variant: number;
/** @description In the order of the playlist. Empty when no song meets the rules. */
@ -4713,6 +4767,35 @@ export interface operations {
404: components["responses"]["SuggestedNotFound"];
};
};
getSuggestedSmartPlaylistCovers: {
parameters: {
query?: {
/** @description The variant that is on screen, from 0 (the songs of the day) up. */
variant?: number;
};
header?: never;
path: {
/** @description A key from `GET /smart-playlists/suggested`. */
key: components["parameters"]["SuggestedKey"];
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description The albums. */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["SmartCovers"];
};
};
400: components["responses"]["InvalidInput"];
401: components["responses"]["Unauthorized"];
404: components["responses"]["SuggestedNotFound"];
};
};
saveSuggestedSmartPlaylist: {
parameters: {
query?: never;
@ -4858,6 +4941,34 @@ export interface operations {
404: components["responses"]["SmartPlaylistNotFound"];
};
};
getSmartPlaylistCovers: {
parameters: {
query?: {
/** @description The variant that is on screen, from 0 (the songs of the day) up. */
variant?: number;
};
header?: never;
path: {
id: components["parameters"]["Id"];
};
cookie?: never;
};
requestBody?: never;
responses: {
/** @description The albums. */
200: {
headers: {
[name: string]: unknown;
};
content: {
"application/json": components["schemas"]["SmartCovers"];
};
};
400: components["responses"]["InvalidInput"];
401: components["responses"]["Unauthorized"];
404: components["responses"]["SmartPlaylistNotFound"];
};
};
saveSmartPlaylist: {
parameters: {
query?: never;

View file

@ -43,6 +43,28 @@ export function useSmartTracks(id: number, variant: number) {
})
}
/**
* The albums that stand for a smart playlist, for its picture: up to four that have a cover, in the order of its songs.
* It is asked apart from the songs, once the list is on screen, and kept for a few minutes.
*/
export function useSmartCovers(id: number, variant = 0) {
return useQuery({
queryKey: ['smart-covers', id, variant],
queryFn: () => api.get<{ album_ids: number[] }>(`/smart-playlists/${id}/covers`, variant > 0 ? { variant } : undefined).then((r) => r.album_ids),
staleTime: 5 * 60_000,
})
}
/** The same for a suggested smart playlist. */
export function useSuggestedCovers(key: string, variant = 0) {
return useQuery({
queryKey: ['smart-suggested-covers', key, variant],
queryFn: () =>
api.get<{ album_ids: number[] }>(`/smart-playlists/suggested/${encodeURIComponent(key)}/covers`, variant > 0 ? { variant } : undefined).then((r) => r.album_ids),
staleTime: 5 * 60_000,
})
}
/** The songs that rules give, without keeping them. It asks again when the rules change. */
export function useSmartPreview(input: SmartInput) {
return useQuery({
@ -100,7 +122,7 @@ function refresh(client: QueryClient) {
return client.invalidateQueries({
predicate: (query) => {
const key = query.queryKey[0]
return typeof key === 'string' && (key.startsWith('/smart-playlists') || key === 'smart' || key === 'smart-tracks')
return typeof key === 'string' && (key.startsWith('/smart-playlists') || key === 'smart' || key === 'smart-tracks' || key === 'smart-covers')
},
})
}