Adds add to favorites button in SongRow

This commit is contained in:
2025-02-23 17:58:26 -08:00
parent 8ab927333b
commit d010d68056
8 changed files with 115 additions and 57 deletions

View File

@@ -142,28 +142,18 @@ export const API = {
return response.json();
},
async addToFavorites(url: string): Promise<void> {
// Maybe a little weird to make an empty PlaylistItem here, but we do want to support adding
// known PlaylistItems to favorites in the future.
const playlistItem: PlaylistItem = {
filename: url,
title: null,
id: 0,
playing: null,
metadata: undefined,
};
async addToFavorites(filename: string): Promise<void> {
await fetch('/api/favorites', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(playlistItem),
body: JSON.stringify({ filename }),
});
},
async removeFromFavorites(id: number): Promise<void> {
await fetch(`/api/favorites/${id}`, { method: 'DELETE' });
async removeFromFavorites(filename: string): Promise<void> {
await fetch(`/api/favorites/${encodeURIComponent(filename)}`, { method: 'DELETE' });
},
async clearFavorites(): Promise<void> {