fix(app): reset edit sheet state on open, check deleteSong response status
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import {
|
||||
Sheet, SheetContent, SheetHeader, SheetTitle,
|
||||
} 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 [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) {
|
||||
e.preventDefault();
|
||||
setLoading(true);
|
||||
|
||||
@@ -44,7 +44,8 @@ export async function createSong(body: {
|
||||
}
|
||||
|
||||
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> {
|
||||
|
||||
Reference in New Issue
Block a user