Feat/admin options #14
No files matched your search
+44
-3
@@ -20,6 +20,13 @@ interface Song {
|
|||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface SongInfo {
|
||||||
|
songbook_id: number;
|
||||||
|
songbook_name: string;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}
|
||||||
|
|
||||||
export default function AdminPage() {
|
export default function AdminPage() {
|
||||||
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
||||||
@@ -33,6 +40,7 @@ export default function AdminPage() {
|
|||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||||
|
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
|
||||||
|
|
||||||
async function handleCSVUpload(formData: FormData) {
|
async function handleCSVUpload(formData: FormData) {
|
||||||
setUploadStatus("Verarbeite...");
|
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(() => {
|
useEffect(() => {
|
||||||
async function loadSongbooks() {
|
async function loadSongbooks() {
|
||||||
try {
|
try {
|
||||||
@@ -248,9 +277,21 @@ export default function AdminPage() {
|
|||||||
<Card title="Ausgewähltes Lied">
|
<Card title="Ausgewähltes Lied">
|
||||||
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
|
<Input.Text value={selectedSong ? selectedSong.title : ""} disabled></Input.Text>
|
||||||
<Card title="Informationen" className="mt-4">
|
<Card title="Informationen" className="mt-4">
|
||||||
<p>Liederbuch-ID: {selectedSong?.songbook_id}</p>
|
<div className="text-sm space-y-1">
|
||||||
<p>Nummer: {selectedSong?.song_number}</p>
|
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.song_id ?? "-"}</p>
|
||||||
<p>Lied-ID: {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>
|
||||||
<Card title="Aktionen">
|
<Card title="Aktionen">
|
||||||
<Card title="Zu Liederbuch hinzufügen">
|
<Card title="Zu Liederbuch hinzufügen">
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSongInfos } from "@/lib/db/managing";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const { id } = await params;
|
||||||
|
const songInfos = await getSongInfos(id);
|
||||||
|
|
||||||
|
return NextResponse.json(songInfos || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Fehler beim Laden der Songinfos" },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in new issue
Block a user