Compare commits

..
Author SHA1 Message Date
Rudi 998434e4eb Changed the name to 'AllSongsTable' 2026-10-13 21:25:53 +02:00
Rudi 1d047c06a7 Changed the Sender Page 2026-10-13 21:22:54 +02:00
6 changed files with 224 additions and 285 deletions

No files matched your search

+6 -3
View File
@@ -1,8 +1,11 @@
"use server";
import { error } from "console";
//import { error } from "console";
import Papa from "papaparse";
import { addSongToSongbook } from "@/lib/db/managing";
import { createSong } from "@/lib/db/song";
//import { createSongBook } from "@/lib/db/songbook.ts";
import { addSongToBook } from "@/lib/db/songbooksongs.ts";
interface CSVRow {
nummer: string;
@@ -40,4 +43,4 @@ export async function uploadCSVAction(formData:FormData) {
console.error(error);
return { success: false, error: "Error"};
}
}
}
+54 -61
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,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>
);
}
}
+8 -78
View File
@@ -1,97 +1,27 @@
"use client";
import { useState, useEffect } from "react";
import { Input } from "@/components/FormElements";
import { Screens } from "@/components/DatabaseOverview";
interface Songbook {
id: number;
name: string;
language: string;
}
interface Song {
song_id: number;
songbook_id: number;
song_number: string;
title: string;
}
import { Screens } from "@/components/AllSongsTable";
export default function SenderPage() {
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
const [song_search_name, setSongSearchName] = useState("");
const [allSongs, setAllSongs] = useState<Song[]>([]);
const [searchResults, setSearchResults] = useState<Song[]>([]);
const getSongslist = async () => {
const sendSong = async (title: string, bookTitle: string, number: string) => {
try {
const res = await fetch("/api/songs");
if (res.ok) {
const data = await res.json();
setAllSongs(data);
setSearchResults(data);
}
} catch (error) {
setAllSongs([]);
console.error("Failed fetching songslist!");
}
};
useEffect(() => {
async function loadSongbooks() {
try {
const res = await fetch("/api/songbooks");
if (res.ok) {
const data = await res.json();
setSongbooks(data);
}
} catch (error) {
console.error("Loading songbooks failed: ", error);
}
}
loadSongbooks();
getSongslist();
}, []);
const sendID = async (sID: string, sbID: string) => {
if (!sID || !sbID) {
alert("Bitte Liederbuch UND SongID auswählen/eingeben!");
return;
}
try {
const res = await fetch("/api/stream/currentID", {
const res = await fetch("/api/stream", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ songbookID: sbID, songID: sID }),
body: JSON.stringify({ song: title, songBook: bookTitle, number }),
});
if (!res.ok) {
alert("Fehler beim Senden.");
}
} catch (error) {
console.error("Failed sending current songID:", error);
}
};
const search = (query: string) => {
setSongSearchName(query);
if (query.trim() !== "") {
setSearchResults(
allSongs.filter((song) =>
song.title.toLowerCase().includes(query.toLowerCase()) ||
song.song_number.includes(query)
)
);
} else {
setSearchResults(allSongs);
console.error("Failed sending current song:", error);
}
};
return (
<Screens.Songs
actionName="Anzeigen"
onSelectSong={(song) => sendID(String(song.song_id), String(song.songbook_id))}
actionName="Anzeigen"
onSelectSong={(song, book, number) => sendSong(song.title, book.title, number)}
/>
);
}
}
+146
View File
@@ -0,0 +1,146 @@
import { useState, useEffect, useMemo, ComponentPropsWithoutRef } from "react";
import Card from "./Card"
import { Input } from "./FormElements"
import { Song, SongBookDetailed } from "@/lib/db/response";
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
onSelectSong?: (song: Song, book: { id: number; title: string }, songNumber: string) => void;
actionName?: string;
songBooks?: SongBookDetailed[];
}
function Songs({ actionName, onSelectSong, songBooks, className = "", ...props }: SongsProps) {
const [query, setQuery] = useState("");
const [fetchedBooks, setFetchedBooks] = useState<SongBookDetailed[]>([]);
useEffect(() => {
if (songBooks) return;
async function load() {
try {
const res = await fetch("/api/songbooks");
if (!res.ok) return;
const list: { id: number }[] = await res.json();
const details = await Promise.all(
list.map(async (b) => {
const r = await fetch(`/api/songbooks/${b.id}`);
return r.ok ? await r.json() : null;
})
);
setFetchedBooks(details.filter(Boolean));
} catch (error) {
console.error("Loading songbooks failed: ", error);
}
}
load();
}, [songBooks]);
const books = songBooks ?? fetchedBooks;
// Pro Buch filtern; Bücher ohne Treffer werden ausgeblendet
const groups = useMemo(() => {
const q = query.trim().toLowerCase();
return books
.map((book) => {
const bookMatches = q !== "" && book.title.toLowerCase().includes(q);
const songs = (book.songs ?? []).filter(
(e) =>
!q ||
bookMatches ||
e.song.title.toLowerCase().includes(q) ||
String(e.songNumber).toLowerCase().includes(q)
);
return { book, songs };
})
.filter((g) => g.songs.length > 0);
}, [books, query]);
const th = "p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider";
return (
<Card
{...props}
title="Alle Lieder"
className={`h-[500px] ${className}`}
>
<div className="mb-4">
<Input.Text
type="text"
placeholder="Nach Songtitel, Nummer oder Liederbuch suchen..."
value={query}
onChange={(e) => setQuery(e.target.value)}
/>
</div>
<div className="flex-1 min-h-0 overflow-auto border border-neutral-200 dark:border-neutral-800 rounded-lg bg-white dark:bg-black">
<table className="w-full text-left border-collapse text-sm">
<thead className="bg-neutral-100 dark:bg-neutral-900 sticky top-0 border-b border-neutral-200 dark:border-neutral-800 z-10">
<tr>
<th className={`${th} w-24 text-center`}>Nummer</th>
<th className={th}>Titel</th>
<th className={`${th} text-right`}>Aktion</th>
</tr>
</thead>
{groups.length === 0 ? (
<tbody>
<tr>
<td colSpan={3} className="p-8 text-center text-neutral-400 dark:text-neutral-500">
Keine Lieder gefunden
</td>
</tr>
</tbody>
) : (
groups.map(({ book, songs }) => (
<tbody key={book.id} className="divide-y divide-neutral-200 dark:divide-neutral-800">
<tr className="bg-neutral-50 dark:bg-neutral-950">
<th
colSpan={3}
className="p-3 text-sm font-bold text-neutral-900 dark:text-white border-y border-neutral-200 dark:border-neutral-800"
>
{book.title}
{book.language && (
<span className="ml-2 text-xs font-normal text-neutral-500 dark:text-neutral-400">
({book.language})
</span>
)}
</th>
</tr>
{songs.map((entry) => (
<tr
key={`${book.id}-${entry.song.id}`}
className="hover:bg-neutral-100/60 dark:hover:bg-neutral-900/40 transition"
>
<td className="p-3 text-center font-mono text-blue-600 dark:text-blue-400 font-bold">
{entry.songNumber}
</td>
<td className="p-3 font-medium text-neutral-900 dark:text-white">
{entry.song.title}
</td>
<td className="p-3 text-right">
<Input.Button
onClick={() =>
onSelectSong?.(
entry.song,
{ id: book.id, title: book.title },
String(entry.songNumber)
)
}
className="bg-white dark:bg-black hover:bg-blue-600 dark:hover:bg-blue-600 border border-neutral-300 dark:border-neutral-700 hover:border-blue-600 dark:hover:border-blue-500 hover:text-white font-medium rounded-md px-3 py-1.5 transition text-xs"
>
{actionName}
</Input.Button>
</td>
</tr>
))}
</tbody>
))
)}
</table>
</div>
</Card>
)
}
export const Screens = {
Songs: Songs,
}
-143
View File
@@ -1,143 +0,0 @@
import { useState, useEffect, ComponentPropsWithoutRef } from "react";
import Card from "./Card"
import { Input } from "./FormElements"
interface SongsProps extends Omit<ComponentPropsWithoutRef<typeof Card>, "title" | "children"> {
onSelectSong?: (song: Song) => void;
actionName?: string;
}
interface Song {
song_id: number;
songbook_id: number;
song_number: string;
title: string;
}
interface Songbook {
id: number;
name: string;
language: string;
}
function Songs({ actionName, onSelectSong, className = "", ...props }: SongsProps) {
const [song_search_name, setSongSearchName] = useState("");
const [searchResults, setSearchResults] = useState<Song[]>([]);
const [allSongs, setAllSongs] = useState<Song[]>([]);
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
const search = (query: string) => {
setSongSearchName(query);
if (query.trim() !== "") {
setSearchResults(
allSongs.filter((song) =>
song.title.toLowerCase().includes(query.toLowerCase()) ||
song.song_number.includes(query)
)
);
} else {
setSearchResults(allSongs);
}
};
useEffect(() => {
const getSongslist = async () => {
try {
const res = await fetch("/api/songs");
if (res.ok) {
const data = await res.json();
setAllSongs(data);
setSearchResults(data);
}
} catch (error) {
setAllSongs([]);
console.error("Failed fetching songslist!");
}
};
async function loadSongbooks() {
try {
const res = await fetch("/api/songbooks");
if (res.ok) {
const data = await res.json();
setSongbooks(data);
}
} catch (error) {
console.error("Loading songbooks failed: ", error);
}
}
loadSongbooks();
getSongslist();
}, []);
return (
<Card
{...props}
title="Alle Lieder"
className={`h-[500px] ${className}`}
>
<div className="mb-4">
<Input.Text
type="text"
placeholder="Nach Songtitel oder Nummer suchen..."
value={song_search_name}
onChange={(e) => search(e.target.value)}
/>
</div>
{/* TABELLE */}
<div className="flex-1 min-h-0 overflow-auto border border-neutral-200 dark:border-neutral-800 rounded-lg bg-white dark:bg-black">
<table className="w-full text-left border-collapse text-sm">
<thead className="bg-neutral-100 dark:bg-neutral-900 sticky top-0 border-b border-neutral-200 dark:border-neutral-800 z-10">
<tr>
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Titel</th>
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider">Liederbuch</th>
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-center">Nummer</th>
<th className="p-3 text-xs font-semibold text-neutral-600 dark:text-neutral-400 uppercase tracking-wider text-right">Aktion</th>
</tr>
</thead>
<tbody className="divide-y divide-neutral-200 dark:divide-neutral-800">
{searchResults.length === 0 ? (
<tr>
<td colSpan={4} className="p-8 text-center text-neutral-400 dark:text-neutral-500">Keine Lieder gefunden</td>
</tr>
) : (
searchResults.map((song) => {
const songBook = songbooks.find((book) => book.id === song.songbook_id);
return (
<tr key={`${song.songbook_id}-${song.song_id}`} className="hover:bg-neutral-100/60 dark:hover:bg-neutral-900/40 transition">
<td className="p-3 font-medium text-neutral-900 dark:text-white max-w-[180px] sm:max-w-none truncate">
{song.title}
<span className="block text-xs text-neutral-500 dark:text-neutral-400 sm:hidden mt-0.5">
{songBook ? songBook.name : "Unbekannt"}
</span>
</td>
<td className="p-3 text-neutral-700 dark:text-neutral-300 hidden sm:table-cell">
{songBook ? songBook.name : "Unbekannt"}
</td>
<td className="p-3 text-center font-mono text-blue-600 dark:text-blue-400 font-bold">
{song.song_number}
</td>
<td className="p-3 text-right">
<Input.Button
onClick={() => onSelectSong?.(song)}
className="bg-white dark:bg-black hover:bg-blue-600 dark:hover:bg-blue-600 border border-neutral-300 dark:border-neutral-700 hover:border-blue-600 dark:hover:border-blue-500 hover:text-white font-medium rounded-md px-3 py-1.5 transition text-xs"
>
{actionName}
</Input.Button>
</td>
</tr>
);
})
)}
</tbody>
</table>
</div>
</Card>
)
}
export const Screens = {
Songs: Songs,
}
+10
View File
@@ -18,6 +18,16 @@ export interface SongDetailed {
};
}
export interface SongBookDetailed {
id: number;
title: string;
language: string;
songs?: {
songNumber: string;
song: Song;
}[]
}
export type APIResponse<T> =
| { success: true; status: number; data: T }
| { success: false; status: number; error: string };