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