Changed the name to 'AllSongsTable'
This commit is contained in:
1 parent
1d047c06a7
commit
998434e4eb
3 files changed
+55
-62
No files matched your search
+54
-61
@@ -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,17 +83,17 @@ export default function AdminPage() {
|
||||
}, []);
|
||||
|
||||
const addSong = async () => {
|
||||
if (!selectedSongbookId || !number || !title) {
|
||||
if (!addSongSelectedSongbookId || !number || !title) {
|
||||
alert("Alle Felder ausfüllen!");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
const res = await fetch("/api/songs", {
|
||||
method: "POST",
|
||||
headers: { "Content-Type": "application/json" },
|
||||
body: JSON.stringify({
|
||||
songbookId: Number(selectedSongbookId),
|
||||
body: JSON.stringify({
|
||||
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!");
|
||||
@@ -198,9 +191,9 @@ export default function AdminPage() {
|
||||
return (
|
||||
<div className="font-sans p-4 sm:p-6 lg:p-8">
|
||||
<div className="max-w-6xl mx-auto space-y-6">
|
||||
|
||||
|
||||
{/* HEADER */}
|
||||
|
||||
|
||||
<h2 className="text-lg font-semibold mb-3 flex items-center gap-2">
|
||||
Datenbank verwalten, neue Bücher erstellen und Lieder einpflegen
|
||||
</h2>
|
||||
@@ -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>
|
||||
@@ -228,7 +221,7 @@ export default function AdminPage() {
|
||||
onChange={(e) => setNewBookLanguage(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Input.Button
|
||||
<Input.Button
|
||||
onClick={addSongbook}
|
||||
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
|
||||
>
|
||||
@@ -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>
|
||||
@@ -304,7 +297,7 @@ export default function AdminPage() {
|
||||
/>
|
||||
</div>
|
||||
<div className="mt-6 space-y-3">
|
||||
<Input.Button
|
||||
<Input.Button
|
||||
type="submit"
|
||||
>
|
||||
Hochladen & Verarbeiten
|
||||
@@ -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>
|
||||
@@ -370,7 +363,7 @@ export default function AdminPage() {
|
||||
onChange={(e) => setNumber(e.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<Input.Button
|
||||
<Input.Button
|
||||
onClick={attachSong}
|
||||
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
|
||||
>
|
||||
@@ -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 ? (
|
||||
@@ -396,7 +389,7 @@ export default function AdminPage() {
|
||||
): ""}
|
||||
</Input.Select>
|
||||
</div>
|
||||
<Input.Button
|
||||
<Input.Button
|
||||
onClick={removeSong}
|
||||
className="w-full mt-6 bg-blue-600 hover:bg-blue-700 text-white font-semibold rounded-lg px-4 py-2.5 transition text-sm shadow-sm"
|
||||
>
|
||||
@@ -410,4 +403,4 @@ export default function AdminPage() {
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user