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";
|
"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,17 +83,17 @@ 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;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/songs", {
|
const res = await fetch("/api/songs", {
|
||||||
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!");
|
||||||
@@ -198,9 +191,9 @@ export default function AdminPage() {
|
|||||||
return (
|
return (
|
||||||
<div className="font-sans p-4 sm:p-6 lg:p-8">
|
<div className="font-sans p-4 sm:p-6 lg:p-8">
|
||||||
<div className="max-w-6xl mx-auto space-y-6">
|
<div className="max-w-6xl mx-auto space-y-6">
|
||||||
|
|
||||||
{/* HEADER */}
|
{/* HEADER */}
|
||||||
|
|
||||||
<h2 className="text-lg font-semibold mb-3 flex items-center gap-2">
|
<h2 className="text-lg font-semibold mb-3 flex items-center gap-2">
|
||||||
Datenbank verwalten, neue Bücher erstellen und Lieder einpflegen
|
Datenbank verwalten, neue Bücher erstellen und Lieder einpflegen
|
||||||
</h2>
|
</h2>
|
||||||
@@ -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>
|
||||||
@@ -228,7 +221,7 @@ export default function AdminPage() {
|
|||||||
onChange={(e) => setNewBookLanguage(e.target.value)}
|
onChange={(e) => setNewBookLanguage(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input.Button
|
<Input.Button
|
||||||
onClick={addSongbook}
|
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"
|
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>
|
<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>
|
||||||
@@ -304,7 +297,7 @@ export default function AdminPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="mt-6 space-y-3">
|
<div className="mt-6 space-y-3">
|
||||||
<Input.Button
|
<Input.Button
|
||||||
type="submit"
|
type="submit"
|
||||||
>
|
>
|
||||||
Hochladen & Verarbeiten
|
Hochladen & Verarbeiten
|
||||||
@@ -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>
|
||||||
@@ -370,7 +363,7 @@ export default function AdminPage() {
|
|||||||
onChange={(e) => setNumber(e.target.value)}
|
onChange={(e) => setNumber(e.target.value)}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<Input.Button
|
<Input.Button
|
||||||
onClick={attachSong}
|
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"
|
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>
|
<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 ? (
|
||||||
@@ -396,7 +389,7 @@ export default function AdminPage() {
|
|||||||
): ""}
|
): ""}
|
||||||
</Input.Select>
|
</Input.Select>
|
||||||
</div>
|
</div>
|
||||||
<Input.Button
|
<Input.Button
|
||||||
onClick={removeSong}
|
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"
|
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>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+1
-1
@@ -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.
Reference in new issue
Block a user