fix(app): reset edit sheet state on open, check deleteSong response status

This commit is contained in:
2026-04-08 03:48:46 +02:00
parent 8fc6e48aac
commit 19829a0589
2 changed files with 11 additions and 2 deletions

View File

@@ -1,4 +1,4 @@
import { useState } from "react"; import { useEffect, useState } from "react";
import { import {
Sheet, SheetContent, SheetHeader, SheetTitle, Sheet, SheetContent, SheetHeader, SheetTitle,
} from "~/components/ui/sheet"; } from "~/components/ui/sheet";
@@ -22,6 +22,14 @@ export function EditSongSheet({ id, meta, open, onOpenChange, onUpdated }: Props
const [key, setKey] = useState(meta.original_key ?? ""); const [key, setKey] = useState(meta.original_key ?? "");
const [loading, setLoading] = useState(false); const [loading, setLoading] = useState(false);
useEffect(() => {
if (open) {
setTitle(meta.title);
setArtist(meta.artist);
setKey(meta.original_key ?? "");
}
}, [open, meta.title, meta.artist, meta.original_key]);
async function handleSubmit(e: React.FormEvent) { async function handleSubmit(e: React.FormEvent) {
e.preventDefault(); e.preventDefault();
setLoading(true); setLoading(true);

View File

@@ -44,7 +44,8 @@ export async function createSong(body: {
} }
export async function deleteSong(id: string): Promise<void> { export async function deleteSong(id: string): Promise<void> {
await fetch(`${getApiBase()}/songs/${id}`, { method: "DELETE" }); const res = await fetch(`${getApiBase()}/songs/${id}`, { method: "DELETE" });
if (!res.ok) throw new Error(`Failed to delete song: HTTP ${res.status}`);
} }
export async function updateSong(id: string, patch: UpdateSongRequest): Promise<SongSummary> { export async function updateSong(id: string, patch: UpdateSongRequest): Promise<SongSummary> {