feat: add api for getSongInfos

feat: show song informations of selected song
This commit is contained in:
robin committed 2026-07-28 15:00:48 +02:00
1 parent d6fb6ec16d
commit d871bddc99
2 files changed
+64 -3

No files matched your search

+44 -3
View File
@@ -20,6 +20,13 @@ interface Song {
title: string;
}
interface SongInfo {
songbook_id: number;
songbook_name: string;
song_number: string;
title: string;
}
export default function AdminPage() {
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
const [selectedSongbookId, setSelectedSongbookId] = useState("");
@@ -33,6 +40,7 @@ export default function AdminPage() {
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
async function handleCSVUpload(formData: FormData) {
setUploadStatus("Verarbeite...");
@@ -45,6 +53,27 @@ export default function AdminPage() {
}
}
useEffect(() => {
if (!selectedSong) {
setSongInfos([]);
return;
}
async function fetchSongInfos() {
try {
const res = await fetch(`/api/songs/${selectedSong?.song_id}`);
if (res.ok) {
const data = await res.json();
setSongInfos(data);
}
} catch (error) {
console.error("Fehler beim Laden der Songinfos:", error);
}
}
fetchSongInfos();
}, [selectedSong]);
useEffect(() => {
async function loadSongbooks() {
try {
@@ -248,9 +277,21 @@ export default function AdminPage() {
<Card title="Ausgewähltes Lied">
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
<Card title="Informationen" className="mt-4">
<p>Liederbuch-ID: {selectedSong?.songbook_id}</p>
<p>Nummer: {selectedSong?.song_number}</p>
<p>Lied-ID: {selectedSong?.song_id}</p>
<div className="text-sm space-y-1">
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.song_id ?? "-"}</p>
<p><span className="font-semibold">In Liederbüchern:</span></p>
{songInfos.length > 0 ? (
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
{songInfos.map((info) => (
<li key={info.songbook_id}>
{info.songbook_name} (Nr. {info.song_number})
</li>
))}
</ul>
) : (
<p className="text-xs text-neutral-500">Keine Daten geladen</p>
)}
</div>
</Card>
<Card title="Aktionen">
<Card title="Zu Liederbuch hinzufügen">