Changed the name to 'AllSongsTable'

This commit is contained in:
Rudi committed 2026-10-13 21:25:53 +02:00
1 parent 1d047c06a7
commit 998434e4eb
3 files changed
+46 -53

No files matched your search

+45 -52
View File
@@ -1,46 +1,39 @@
"use client"; "use client";
import { uploadCSVAction } from "./actions"; import { uploadCSVAction } from "./actions";
import { JSXElementConstructor, Key, ReactElement, ReactNode, ReactPortal, useEffect, useState } from "react"; import { useEffect, useState } from "react";
import Card from "@/components/Card" import Card from "@/components/Card"
import { Input } from "@/components/FormElements"; import { Input } from "@/components/FormElements";
import { Screens } from "@/components/DatabaseOverview"; import { Screens } from "@/components/AllSongsTable";
interface Songbook { import { Song, SongBook, SongDetailed } from "@/lib/db/response";
id: number;
name: string;
language: string;
}
interface Song {
song_id: number;
songbook_id: number;
song_number: 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[]>([]); // New Songbook
const [selectedSongbookId, setSelectedSongbookId] = useState(""); const [newBookTitle, setNewBookTitle] = useState("");
const [newBookLanguage, setNewBookLanguage] = useState("");
// New Song
const [addSongSelectedSongbookId, addSongSetSelectedSongbookId] = useState("");
const [number, setNumber] = useState(""); const [number, setNumber] = useState("");
const [title, setTitle] = useState(""); const [title, setTitle] = useState("");
const [newBookName, setNewBookName] = useState(""); // Import Songs
const [newBookLanguage, setNewBookLanguage] = useState(""); const [importSelectedSongbookId, importSetSelectedSongbookId] = useState("");
const [uploadStatus, setUploadStatus] = useState<string | null>(null); const [uploadStatus, setUploadStatus] = useState<string | null>(null);
//
const [songbooks, setSongbooks] = useState<SongBook[]>([]);
const [selectedSong, setSelectedSong] = useState<Song | null>(null); const [selectedSong, setSelectedSong] = useState<Song | null>(null);
const [songInfos, setSongInfos] = useState<SongInfo[]>([]) const [songInfos, setSongInfos] = useState<SongDetailed[]>([])
async function handleCSVUpload(formData: FormData) { async function handleCSVUpload(formData: FormData) {
setUploadStatus("Verarbeite..."); setUploadStatus("Verarbeite...");
@@ -61,7 +54,7 @@ export default function AdminPage() {
async function fetchSongInfos() { async function fetchSongInfos() {
try { try {
const res = await fetch(`/api/songs/${selectedSong?.song_id}`); const res = await fetch(`/api/songs/${selectedSong?.id}`);
if (res.ok) { if (res.ok) {
const data = await res.json(); const data = await res.json();
setSongInfos(data); setSongInfos(data);
@@ -90,7 +83,7 @@ export default function AdminPage() {
}, []); }, []);
const addSong = async () => { const addSong = async () => {
if (!selectedSongbookId || !number || !title) { if (!addSongSelectedSongbookId || !number || !title) {
alert("Alle Felder ausfüllen!"); alert("Alle Felder ausfüllen!");
return; return;
} }
@@ -100,7 +93,7 @@ export default function AdminPage() {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
songbookId: Number(selectedSongbookId), songbookId: Number(addSongSelectedSongbookId),
number: number, number: number,
title: title title: title
}) })
@@ -118,7 +111,7 @@ export default function AdminPage() {
}; };
const attachSong = async () => { const attachSong = async () => {
if (!selectedSongbookId || !number || !selectedSong) { if (!addSongSelectedSongbookId || !number || !selectedSong) {
alert("Alle Felder ausfüllen!"); alert("Alle Felder ausfüllen!");
return; return;
} }
@@ -128,8 +121,8 @@ export default function AdminPage() {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
songbookId: selectedSongbookId, songbookId: addSongSelectedSongbookId,
songId: selectedSong.song_id, songId: selectedSong.id,
number: number, number: number,
}) })
}); });
@@ -144,7 +137,7 @@ export default function AdminPage() {
} }
const removeSong = async () => { const removeSong = async () => {
if (!selectedSongbookId || !selectedSong) { if (!addSongSelectedSongbookId || !selectedSong) {
alert("Alle Felder ausfüllen!"); alert("Alle Felder ausfüllen!");
return; return;
} }
@@ -154,8 +147,8 @@ export default function AdminPage() {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ body: JSON.stringify({
songbookId: selectedSongbookId, songbookId: addSongSelectedSongbookId,
songId: selectedSong.song_id songId: selectedSong.id
}) })
}); });
if (res.ok) { if (res.ok) {
@@ -169,7 +162,7 @@ export default function AdminPage() {
} }
const addSongbook = async () => { const addSongbook = async () => {
if (!newBookName) { if (!newBookTitle) {
alert("Der Name des Liederbuches darf nicht leer sein!"); alert("Der Name des Liederbuches darf nicht leer sein!");
return; return;
} }
@@ -178,14 +171,14 @@ export default function AdminPage() {
const res = await fetch("/api/songbooks", { const res = await fetch("/api/songbooks", {
method: "POST", method: "POST",
headers: { "Content-Type": "application/json" }, headers: { "Content-Type": "application/json" },
body: JSON.stringify({ name: newBookName, language: newBookLanguage }) body: JSON.stringify({ name: newBookTitle, language: newBookLanguage })
}); });
if (res.ok) { if (res.ok) {
const createdBook = await res.json(); const createdBook = await res.json();
setSongbooks([...songbooks, createdBook]); setSongbooks([...songbooks, createdBook]);
alert("Liederbuch erfolgreich erstellt!"); alert("Liederbuch erfolgreich erstellt!");
setNewBookName(""); setNewBookTitle("");
setNewBookLanguage(""); setNewBookLanguage("");
} else { } else {
alert("Failed adding songbook!"); alert("Failed adding songbook!");
@@ -215,8 +208,8 @@ export default function AdminPage() {
<Input.Text <Input.Text
type="text" type="text"
placeholder="z.B. Gesangbuch" placeholder="z.B. Gesangbuch"
value={newBookName} value={newBookTitle}
onChange={(e) => setNewBookName(e.target.value)} onChange={(e) => setNewBookTitle(e.target.value)}
/> />
</div> </div>
<div> <div>
@@ -242,13 +235,13 @@ export default function AdminPage() {
<div> <div>
<Input.Label>Liederbuch wählen</Input.Label> <Input.Label>Liederbuch wählen</Input.Label>
<Input.Select <Input.Select
value={selectedSongbookId} value={addSongSelectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)} onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
> >
<option value="">-- Bitte wählen --</option> <option value="">-- Bitte wählen --</option>
{songbooks.map((book) => ( {songbooks.map((book) => (
<option key={book.id} value={String(book.id)}> <option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""} {book.title}{book.language ? ` (${book.language})` : ""}
</option> </option>
))} ))}
</Input.Select> </Input.Select>
@@ -279,18 +272,18 @@ export default function AdminPage() {
<Card title="CSV-Massenimport"> <Card title="CSV-Massenimport">
<form action={handleCSVUpload} className="flex flex-col justify-between"> <form action={handleCSVUpload} className="flex flex-col justify-between">
<input type="hidden" name="songbookId" value={selectedSongbookId} /> <input type="hidden" name="songbookId" value={addSongSelectedSongbookId} />
<div className="space-y-4"> <div className="space-y-4">
<div> <div>
<Input.Label>Ziel-Liederbuch</Input.Label> <Input.Label>Ziel-Liederbuch</Input.Label>
<Input.Select <Input.Select
value={selectedSongbookId} value={addSongSelectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)} onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
> >
<option value="">-- Bitte wählen --</option> <option value="">-- Bitte wählen --</option>
{songbooks.map((book) => ( {songbooks.map((book) => (
<option key={book.id} value={String(book.id)}> <option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""} {book.title}{book.language ? ` (${book.language})` : ""}
</option> </option>
))} ))}
</Input.Select> </Input.Select>
@@ -329,7 +322,7 @@ export default function AdminPage() {
<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">
<div className="text-sm space-y-1"> <div className="text-sm space-y-1">
<p><span className="font-semibold">Lied-ID:</span> {selectedSong?.song_id ?? "-"}</p> <p><span className="font-semibold">Lied-ID:</span> {selectedSong?.id ?? "-"}</p>
<p><span className="font-semibold">In Liederbüchern:</span></p> <p><span className="font-semibold">In Liederbüchern:</span></p>
{songInfos.length > 0 ? ( {songInfos.length > 0 ? (
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400"> <ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
@@ -350,13 +343,13 @@ export default function AdminPage() {
<div> <div>
<Input.Label>Ziel-Liederbuch</Input.Label> <Input.Label>Ziel-Liederbuch</Input.Label>
<Input.Select <Input.Select
value={selectedSongbookId} value={addSongSelectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)} onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
> >
<option value="">-- Bitte wählen --</option> <option value="">-- Bitte wählen --</option>
{songbooks.map((book) => ( {songbooks.map((book) => (
<option key={book.id} value={String(book.id)}> <option key={book.id} value={String(book.id)}>
{book.name}{book.language ? ` (${book.language})` : ""} {book.title}{book.language ? ` (${book.language})` : ""}
</option> </option>
))} ))}
</Input.Select> </Input.Select>
@@ -383,8 +376,8 @@ export default function AdminPage() {
<div> <div>
<Input.Label>Ziel-Liederbuch</Input.Label> <Input.Label>Ziel-Liederbuch</Input.Label>
<Input.Select <Input.Select
value={selectedSongbookId} value={addSongSelectedSongbookId}
onChange={(e) => setSelectedSongbookId(e.target.value)} onChange={(e) => addSongSetSelectedSongbookId(e.target.value)}
> >
<option value="">-- Bitte wählen --</option> <option value="">-- Bitte wählen --</option>
{songInfos.length > 0 ? ( {songInfos.length > 0 ? (
+1 -1
View File
@@ -1,6 +1,6 @@
"use client"; "use client";
import { Screens } from "@/components/DatabaseOverview"; import { Screens } from "@/components/AllSongsTable";
export default function SenderPage() { export default function SenderPage() {
const sendSong = async (title: string, bookTitle: string, number: string) => { const sendSong = async (title: string, bookTitle: string, number: string) => {
File renamed without changes.