Main #21
No files matched your search
+187
-9
@@ -1,10 +1,11 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { uploadCSVAction } from "./actions";
|
import { uploadCSVAction } from "./actions";
|
||||||
import { useEffect, useState } from "react";
|
import { JSXElementConstructor, Key, ReactElement, ReactNode, ReactPortal, 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";
|
||||||
|
|
||||||
interface Songbook {
|
interface Songbook {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -12,6 +13,20 @@ interface Songbook {
|
|||||||
language: 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[]>([]);
|
const [songbooks, setSongbooks] = useState<Songbook[]>([]);
|
||||||
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
const [selectedSongbookId, setSelectedSongbookId] = useState("");
|
||||||
@@ -24,6 +39,9 @@ export default function AdminPage() {
|
|||||||
|
|
||||||
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
const [uploadStatus, setUploadStatus] = useState<string | null>(null);
|
||||||
|
|
||||||
|
const [selectedSong, setSelectedSong] = useState<Song | null>(null);
|
||||||
|
const [songInfos, setSongInfos] = useState<SongInfo[]>([])
|
||||||
|
|
||||||
async function handleCSVUpload(formData: FormData) {
|
async function handleCSVUpload(formData: FormData) {
|
||||||
setUploadStatus("Verarbeite...");
|
setUploadStatus("Verarbeite...");
|
||||||
const result = await uploadCSVAction(formData);
|
const result = await uploadCSVAction(formData);
|
||||||
@@ -35,6 +53,27 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (!selectedSong) {
|
||||||
|
setSongInfos([]);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function fetchSongInfos() {
|
||||||
|
try {
|
||||||
|
const res = await fetch(`/api/songs/${selectedSong?.song_id}`);
|
||||||
|
if (res.ok) {
|
||||||
|
const data = await res.json();
|
||||||
|
setSongInfos(data);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Fehler beim Laden der Songinfos:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fetchSongInfos();
|
||||||
|
}, [selectedSong]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
async function loadSongbooks() {
|
async function loadSongbooks() {
|
||||||
try {
|
try {
|
||||||
@@ -78,6 +117,57 @@ export default function AdminPage() {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const attachSong = async () => {
|
||||||
|
if (!selectedSongbookId || !number || !selectedSong) {
|
||||||
|
alert("Alle Felder ausfüllen!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/songs/attach", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
songbookId: selectedSongbookId,
|
||||||
|
songId: selectedSong.song_id,
|
||||||
|
number: number,
|
||||||
|
})
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
alert("Lied erfolgreich zum Liederbuch hinzugefügt!");
|
||||||
|
} else {
|
||||||
|
alert("Fehler beim Senden.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed sending current songID:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeSong = async () => {
|
||||||
|
if (!selectedSongbookId || !selectedSong) {
|
||||||
|
alert("Alle Felder ausfüllen!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const res = await fetch("/api/songs/remove", {
|
||||||
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: JSON.stringify({
|
||||||
|
songbookId: selectedSongbookId,
|
||||||
|
songId: selectedSong.song_id
|
||||||
|
})
|
||||||
|
});
|
||||||
|
if (res.ok) {
|
||||||
|
alert("Lied erfolgreich aus dem Liederbuch gelöscht!");
|
||||||
|
} else {
|
||||||
|
alert("Fehler beim Senden.");
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed sending current songID:", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const addSongbook = async () => {
|
const addSongbook = async () => {
|
||||||
if (!newBookName) {
|
if (!newBookName) {
|
||||||
alert("Der Name des Liederbuches darf nicht leer sein!");
|
alert("Der Name des Liederbuches darf nicht leer sein!");
|
||||||
@@ -121,7 +211,7 @@ export default function AdminPage() {
|
|||||||
<Card title="Neues Liederbuch">
|
<Card title="Neues Liederbuch">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Name des Buchs</label>
|
<Input.Label>Name des Buchs</Input.Label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="z.B. Gesangbuch"
|
placeholder="z.B. Gesangbuch"
|
||||||
@@ -130,7 +220,7 @@ export default function AdminPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Sprache (Optional)</label>
|
<Input.Label>Sprache (Optional)</Input.Label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="z.B. Deutsch"
|
placeholder="z.B. Deutsch"
|
||||||
@@ -150,7 +240,7 @@ export default function AdminPage() {
|
|||||||
<Card title="Lied hinzufügen">
|
<Card title="Lied hinzufügen">
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Liederbuch wählen</label>
|
<Input.Label>Liederbuch wählen</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={selectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
@@ -165,7 +255,7 @@ export default function AdminPage() {
|
|||||||
</div>
|
</div>
|
||||||
<div className="grid grid-cols-3 gap-2">
|
<div className="grid grid-cols-3 gap-2">
|
||||||
<div className="col-span-1">
|
<div className="col-span-1">
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Nummer</label>
|
<Input.Label>Nummer</Input.Label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="12a"
|
placeholder="12a"
|
||||||
@@ -174,7 +264,7 @@ export default function AdminPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Liedtitel</label>
|
<Input.Label>Titel</Input.Label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Großer Gott, wir..."
|
placeholder="Großer Gott, wir..."
|
||||||
@@ -188,11 +278,11 @@ export default function AdminPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="CSV-Massenimport">
|
<Card title="CSV-Massenimport">
|
||||||
<form action={handleCSVUpload} className="h-full 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={selectedSongbookId} />
|
||||||
<div className="space-y-4">
|
<div className="space-y-4">
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Ziel-Liederbuch</label>
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={selectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
@@ -206,7 +296,7 @@ export default function AdminPage() {
|
|||||||
</Input.Select>
|
</Input.Select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Datei auswählen (.csv)</label>
|
<Input.Label>Datei auswählen (.csv)</Input.Label>
|
||||||
<Input.File
|
<Input.File
|
||||||
name="csvFile"
|
name="csvFile"
|
||||||
accept=".csv"
|
accept=".csv"
|
||||||
@@ -229,6 +319,94 @@ export default function AdminPage() {
|
|||||||
</form>
|
</form>
|
||||||
</Card>
|
</Card>
|
||||||
</div>
|
</div>
|
||||||
|
<div className="grid grid-cols-1 lg:grid-cols-2 gap-6">
|
||||||
|
<Screens.Songs
|
||||||
|
actionName="Auswählen"
|
||||||
|
onSelectSong={(song) => setSelectedSong(song)}
|
||||||
|
className=""
|
||||||
|
/>
|
||||||
|
<Card title="Ausgewähltes Lied">
|
||||||
|
<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">In Liederbüchern:</span></p>
|
||||||
|
{songInfos.length > 0 ? (
|
||||||
|
<ul className="list-disc list-inside pl-2 text-xs text-neutral-400">
|
||||||
|
{songInfos.map((info) => (
|
||||||
|
<li key={info.songbook_id}>
|
||||||
|
{info.songbook_name} (Nr. {info.song_number})
|
||||||
|
</li>
|
||||||
|
))}
|
||||||
|
</ul>
|
||||||
|
) : (
|
||||||
|
<p className="text-xs text-neutral-500">Keine Daten geladen</p>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<Card title="Aktionen">
|
||||||
|
<Card title="Zu Liederbuch hinzufügen">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
|
<Input.Select
|
||||||
|
value={selectedSongbookId}
|
||||||
|
onChange={(e) => setSelectedSongbookId(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})` : ""}
|
||||||
|
</option>
|
||||||
|
))}
|
||||||
|
</Input.Select>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<Input.Label>Nummer</Input.Label>
|
||||||
|
<Input.Text
|
||||||
|
type="text"
|
||||||
|
placeholder="12a"
|
||||||
|
value={number}
|
||||||
|
onChange={(e) => setNumber(e.target.value)}
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
Lied hinzufügen
|
||||||
|
</Input.Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
<Card title="Aus Liederbuch löschen">
|
||||||
|
<div className="space-y-4">
|
||||||
|
<div>
|
||||||
|
<Input.Label>Ziel-Liederbuch</Input.Label>
|
||||||
|
<Input.Select
|
||||||
|
value={selectedSongbookId}
|
||||||
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
|
>
|
||||||
|
<option value="">-- Bitte wählen --</option>
|
||||||
|
{songInfos.length > 0 ? (
|
||||||
|
songInfos.map((info) => (
|
||||||
|
<option key={info.songbook_id} value={String(info.songbook_id)}>
|
||||||
|
{info.songbook_name} (Nr. {info.song_number})
|
||||||
|
</option>
|
||||||
|
))
|
||||||
|
): ""}
|
||||||
|
</Input.Select>
|
||||||
|
</div>
|
||||||
|
<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"
|
||||||
|
>
|
||||||
|
Lied aus Liederbuch löschen
|
||||||
|
</Input.Button>
|
||||||
|
</div>
|
||||||
|
</Card>
|
||||||
|
</Card>
|
||||||
|
</Card>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { getSongInfos } from "@/lib/db/managing";
|
||||||
|
|
||||||
|
export async function GET(
|
||||||
|
request: Request,
|
||||||
|
{ params }: { params: Promise<{ id: string }> }
|
||||||
|
) {
|
||||||
|
try {
|
||||||
|
const { id } = await params;
|
||||||
|
const songInfos = await getSongInfos(id);
|
||||||
|
|
||||||
|
return NextResponse.json(songInfos || []);
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Fehler beim Laden der Songinfos" },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,40 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { attachSongToSongbook } from "@/lib/db/managing";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = await request.json();
|
||||||
|
const { songId, songbookId, number } = body;
|
||||||
|
|
||||||
|
if (isNaN(songId) || isNaN(songbookId) || !number) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Ungültige IDs oder fehlende Nummer." },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await attachSongToSongbook(
|
||||||
|
Number(songId),
|
||||||
|
Number(songbookId),
|
||||||
|
String(number)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: "Lied erfolgreich verknüpft!" },
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Fehler beim Verknüpfen in der Datenbank." },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error in /api/songs/attach:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Ungültiges JSON oder Serverfehler." },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { NextResponse } from "next/server";
|
||||||
|
import { removeSongfromSongbook } from "@/lib/db/managing";
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
try {
|
||||||
|
const body = await request.json();
|
||||||
|
const { songId, songbookId } = body;
|
||||||
|
|
||||||
|
if (isNaN(songId) || isNaN(songbookId)) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Ungültige IDs." },
|
||||||
|
{ status: 400 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = await removeSongfromSongbook(
|
||||||
|
Number(songId),
|
||||||
|
Number(songbookId)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (result.success) {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ message: "Lied erfolgreich aus dem Liederbuch gelöscht!" },
|
||||||
|
{ status: 200 }
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Fehler beim Löschen aus dem Liederbuch." },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.error("API Error in /api/songs/remove:", error);
|
||||||
|
return NextResponse.json(
|
||||||
|
{ error: "Ungültiges JSON oder Serverfehler." },
|
||||||
|
{ status: 500 }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
+4
-65
@@ -3,6 +3,7 @@
|
|||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
|
|
||||||
import { Input } from "@/components/FormElements";
|
import { Input } from "@/components/FormElements";
|
||||||
|
import { Screens } from "@/components/DatabaseOverview";
|
||||||
|
|
||||||
interface Songbook {
|
interface Songbook {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -88,71 +89,9 @@ export default function SenderPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<Screens.Songs
|
||||||
{/* LIEDERSUCHE */}
|
actionName="Anzeigen"
|
||||||
<div className="p-4 sm:p-6 flex flex-col h-[500px]">
|
onSelectSong={(song) => sendID(String(song.song_id), String(song.songbook_id))}
|
||||||
<h2 className="text-lg font-semibold mb-3 flex items-center gap-2">
|
|
||||||
Liedersuche & Datenbank
|
|
||||||
</h2>
|
|
||||||
|
|
||||||
<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 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={() => sendID(String(song.song_id), String(song.songbook_id))}
|
|
||||||
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"
|
|
||||||
>
|
|
||||||
Anzeigen
|
|
||||||
</Input.Button>
|
|
||||||
</td>
|
|
||||||
</tr>
|
|
||||||
);
|
|
||||||
})
|
|
||||||
)}
|
|
||||||
</tbody>
|
|
||||||
</table>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+15
-4
@@ -1,12 +1,23 @@
|
|||||||
import { ReactNode } from "react";
|
import { ReactNode, ComponentPropsWithoutRef } from "react";
|
||||||
|
|
||||||
export default function Card({title, children}: {title: string, children: ReactNode}) {
|
interface CardProps extends ComponentPropsWithoutRef<"section"> {
|
||||||
|
title: string;
|
||||||
|
children: ReactNode;
|
||||||
|
hasLeftBorder?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export default function Card({ title, hasLeftBorder = false, children, className = "", ...props }: CardProps) {
|
||||||
return (
|
return (
|
||||||
<section className="p-5 flex flex-col justify-between">
|
<section
|
||||||
|
className={`p-5 flex flex-col justify-between ${className} bg-slate-400/30 dark:bg-slate-700/30 rounded-xl`}
|
||||||
|
{...props}
|
||||||
|
>
|
||||||
<h2 className="text-lg font-semibold mb-4 flex items-center gap-2">
|
<h2 className="text-lg font-semibold mb-4 flex items-center gap-2">
|
||||||
{title}
|
{title}
|
||||||
</h2>
|
</h2>
|
||||||
<div>
|
|
||||||
|
{/* border-l-2 fügt den Strich links ein, pl-4 macht Platz zum Inhalt */}
|
||||||
|
<div className={`flex-1 min-h-0 flex flex-col border-neutral-200 dark:border-neutral-800 ${hasLeftBorder ? "border-l-2 pl-4}" : ""}`}>
|
||||||
{children}
|
{children}
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -0,0 +1,143 @@
|
|||||||
|
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,
|
||||||
|
}
|
||||||
@@ -3,13 +3,14 @@ import { ComponentPropsWithoutRef } from "react";
|
|||||||
|
|
||||||
interface TextfieldProps extends ComponentPropsWithoutRef<"input"> {}
|
interface TextfieldProps extends ComponentPropsWithoutRef<"input"> {}
|
||||||
|
|
||||||
function Textfield({value, onChange, placeholder}: TextfieldProps) {
|
function Textfield({value, onChange, placeholder, ...props}: TextfieldProps) {
|
||||||
return (
|
return (
|
||||||
<input
|
<input
|
||||||
className="w-full border border-neutral-700 rounded-lg px-4 py-2.5 placeholder-neutral-500 focus:outline-none focus:border-blue-400 text-sm"
|
className="w-full border border-neutral-700 rounded-lg px-4 py-2.5 placeholder-neutral-500 focus:outline-none focus:border-blue-400 text-sm"
|
||||||
value={value}
|
value={value}
|
||||||
onChange={onChange}
|
onChange={onChange}
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
|
{...props}
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -46,9 +47,18 @@ function Button({ children, ...props }: ComponentPropsWithoutRef<"button">) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function Label( {children}: ComponentPropsWithoutRef<"label">) {
|
||||||
|
return (
|
||||||
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">
|
||||||
|
{children}
|
||||||
|
</label>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
export const Input = {
|
export const Input = {
|
||||||
Text: Textfield,
|
Text: Textfield,
|
||||||
Select: Dropdown,
|
Select: Dropdown,
|
||||||
File: File,
|
File: File,
|
||||||
Button: Button,
|
Button: Button,
|
||||||
|
Label: Label,
|
||||||
};
|
};
|
||||||
@@ -2,7 +2,7 @@ import NavItem from "./NavItem";
|
|||||||
|
|
||||||
export default function Header() {
|
export default function Header() {
|
||||||
return (
|
return (
|
||||||
<header className="fixed top-0 left-0 w-full z-50 p-4 flex justify-between items-center backdrop-blur-md">
|
<header className="fixed top-0 left-0 w-full z-50 p-4 flex justify-between items-center backdrop-blur-md border-b-2 border-slate-500">
|
||||||
<div className="font-bold text-xl">PsalmTafel</div>
|
<div className="font-bold text-xl">PsalmTafel</div>
|
||||||
<nav className="flex gap-4 border-2 rounded-full">
|
<nav className="flex gap-4 border-2 rounded-full">
|
||||||
<NavItem path="/dashboard">Dashboard</NavItem>
|
<NavItem path="/dashboard">Dashboard</NavItem>
|
||||||
|
|||||||
+67
-2
@@ -1,5 +1,4 @@
|
|||||||
import Database from "better-sqlite3";
|
import Database from "better-sqlite3";
|
||||||
import { Noto_Sans_Tamil_Supplement } from "next/font/google";
|
|
||||||
import path from "path";
|
import path from "path";
|
||||||
|
|
||||||
const dbPath = path.join(process.cwd(), "songs.db");
|
const dbPath = path.join(process.cwd(), "songs.db");
|
||||||
@@ -69,6 +68,32 @@ export async function getSong(songbookId: number, songId: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function getSongInfos(songId: string) {
|
||||||
|
try {
|
||||||
|
const songRecords = db.prepare(`
|
||||||
|
SELECT
|
||||||
|
ss.songbook_id,
|
||||||
|
sb.name AS songbook_name,
|
||||||
|
ss.song_number,
|
||||||
|
s.title
|
||||||
|
FROM songbook_songs ss
|
||||||
|
JOIN songbooks sb ON ss.songbook_id = sb.id
|
||||||
|
JOIN songs s ON ss.song_id = s.id
|
||||||
|
WHERE s.id = ?
|
||||||
|
`).all(songId) as {
|
||||||
|
songbook_id: number;
|
||||||
|
songbook_name: string;
|
||||||
|
song_number: string;
|
||||||
|
title: string;
|
||||||
|
}[] | undefined
|
||||||
|
|
||||||
|
return songRecords || null;
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Fehler in getSong:", error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function addSongToSongbook(title:string, songbookId:number, number:string) {
|
export async function addSongToSongbook(title:string, songbookId:number, number:string) {
|
||||||
try {
|
try {
|
||||||
const runTransaction = db.transaction(() => {
|
const runTransaction = db.transaction(() => {
|
||||||
@@ -95,6 +120,46 @@ export async function addSongToSongbook(title:string, songbookId:number, number:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export async function attachSongToSongbook(songId: number, songbookId: number, number: string) {
|
||||||
|
try {
|
||||||
|
const songExists = db.prepare("SELECT id FROM songs WHERE id = ?").get(songId);
|
||||||
|
if (!songExists) {
|
||||||
|
console.error(`Song mit ID ${songId} existiert nicht in DB.`);
|
||||||
|
return { success: false, error: "Song nicht gefunden." };
|
||||||
|
}
|
||||||
|
|
||||||
|
const bookExists = db.prepare("SELECT id FROM songbooks WHERE id = ?").get(songbookId);
|
||||||
|
if (!bookExists) {
|
||||||
|
console.error(`Songbook mit ID ${songbookId} existiert nicht in DB.`);
|
||||||
|
return { success: false, error: "Liederbuch nicht gefunden." };
|
||||||
|
}
|
||||||
|
|
||||||
|
db.prepare(`
|
||||||
|
INSERT OR REPLACE INTO songbook_songs (songbook_id, song_id, song_number)
|
||||||
|
VALUES (?, ?, ?)
|
||||||
|
`).run(songbookId, songId, number);
|
||||||
|
|
||||||
|
return { success: true };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in attachSongToSongbook:", error);
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function removeSongfromSongbook(songId: number, songbookId: number) {
|
||||||
|
try {
|
||||||
|
const info = db.prepare(`
|
||||||
|
DELETE FROM songbook_songs
|
||||||
|
WHERE songbook_id = ? AND song_id = ?
|
||||||
|
`).run(songbookId, songId);
|
||||||
|
|
||||||
|
return { success: info.changes > 0 };
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Error in removeSongfromSongbook:", error);
|
||||||
|
return { success: false };
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export async function getSongbooks() {
|
export async function getSongbooks() {
|
||||||
try {
|
try {
|
||||||
const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all();
|
const songbooks = db.prepare('SELECT id, name, language FROM songbooks ORDER BY name ASC').all();
|
||||||
@@ -104,7 +169,7 @@ export async function getSongbooks() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function addSongbook(name:String, language:String) {
|
export async function addSongbook(name: string, language: string) {
|
||||||
try {
|
try {
|
||||||
const info = db.prepare(`
|
const info = db.prepare(`
|
||||||
INSERT INTO songbooks (name, language)
|
INSERT INTO songbooks (name, language)
|
||||||
|
|||||||
Reference in new issue
Block a user