Merge pull request 'fix: fixed typo' (#29) from environment into main
Deploy Next.js via Docker / deploy (push) Successful in 12s
Deploy Next.js via Docker / deploy (push) Successful in 12s
Reviewed-on: Schanbro/PsalmTafel#29
This commit was merged in pull request #29.
This commit is contained in:
commit
1ea117e8fe
14 files changed
+107
-557
No files matched your search
+9
-187
@@ -1,11 +1,10 @@
|
|||||||
"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";
|
|
||||||
|
|
||||||
interface Songbook {
|
interface Songbook {
|
||||||
id: number;
|
id: number;
|
||||||
@@ -13,20 +12,6 @@ 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("");
|
||||||
@@ -39,9 +24,6 @@ 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);
|
||||||
@@ -53,27 +35,6 @@ 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 {
|
||||||
@@ -117,57 +78,6 @@ 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!");
|
||||||
@@ -211,7 +121,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>
|
||||||
<Input.Label>Name des Buchs</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Name des Buchs</label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="z.B. Gesangbuch"
|
placeholder="z.B. Gesangbuch"
|
||||||
@@ -220,7 +130,7 @@ export default function AdminPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Input.Label>Sprache (Optional)</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Sprache (Optional)</label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="z.B. Deutsch"
|
placeholder="z.B. Deutsch"
|
||||||
@@ -240,7 +150,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>
|
||||||
<Input.Label>Liederbuch wählen</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Liederbuch wählen</label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={selectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
@@ -255,7 +165,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">
|
||||||
<Input.Label>Nummer</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Nummer</label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="12a"
|
placeholder="12a"
|
||||||
@@ -264,7 +174,7 @@ export default function AdminPage() {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<div className="col-span-2">
|
<div className="col-span-2">
|
||||||
<Input.Label>Titel</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Liedtitel</label>
|
||||||
<Input.Text
|
<Input.Text
|
||||||
type="text"
|
type="text"
|
||||||
placeholder="Großer Gott, wir..."
|
placeholder="Großer Gott, wir..."
|
||||||
@@ -278,11 +188,11 @@ export default function AdminPage() {
|
|||||||
</Card>
|
</Card>
|
||||||
|
|
||||||
<Card title="CSV-Massenimport">
|
<Card title="CSV-Massenimport">
|
||||||
<form action={handleCSVUpload} className="flex flex-col justify-between">
|
<form action={handleCSVUpload} className="h-full 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>
|
||||||
<Input.Label>Ziel-Liederbuch</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Ziel-Liederbuch</label>
|
||||||
<Input.Select
|
<Input.Select
|
||||||
value={selectedSongbookId}
|
value={selectedSongbookId}
|
||||||
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
onChange={(e) => setSelectedSongbookId(e.target.value)}
|
||||||
@@ -296,7 +206,7 @@ export default function AdminPage() {
|
|||||||
</Input.Select>
|
</Input.Select>
|
||||||
</div>
|
</div>
|
||||||
<div>
|
<div>
|
||||||
<Input.Label>Datei auswählen (.csv)</Input.Label>
|
<label className="block text-xs font-semibold text-neutral-400 uppercase tracking-wider mb-1.5">Datei auswählen (.csv)</label>
|
||||||
<Input.File
|
<Input.File
|
||||||
name="csvFile"
|
name="csvFile"
|
||||||
accept=".csv"
|
accept=".csv"
|
||||||
@@ -319,94 +229,6 @@ 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>
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -1,20 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
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 }
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import Image from "next/image";
|
|
||||||
|
|
||||||
export default function DashboardPage() {
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
{/* Das Hintergrundbild brecht aus allen Containern aus und füllt das Fenster */}
|
|
||||||
<div className="fixed inset-0 -z-10 h-screen w-screen overflow-hidden">
|
|
||||||
{/* <Image
|
|
||||||
src="/fakurian_purple.jpg"
|
|
||||||
alt="Hintergrund"
|
|
||||||
fill
|
|
||||||
className="object-cover"
|
|
||||||
priority
|
|
||||||
/> */}
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{/* Dein Inhalt auf dieser Seite */}
|
|
||||||
<div className="relative">
|
|
||||||
<p>Dashboard is comming soon...</p>
|
|
||||||
</div>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
+2
-2
@@ -15,8 +15,8 @@ const geistMono = Geist_Mono({
|
|||||||
});
|
});
|
||||||
|
|
||||||
export const metadata: Metadata = {
|
export const metadata: Metadata = {
|
||||||
title: "PsalmTafel",
|
title: "Create Next App",
|
||||||
description: "Liedernummer-Anzeige für den Chor ",
|
description: "Generated by create next app",
|
||||||
};
|
};
|
||||||
|
|
||||||
export default function RootLayout({
|
export default function RootLayout({
|
||||||
|
|||||||
+21
-3
@@ -1,5 +1,23 @@
|
|||||||
import { redirect } from "next/navigation";
|
import Image from "next/image";
|
||||||
|
|
||||||
export default function Page() {
|
export default function DashboardPage() {
|
||||||
redirect("/dashboard")
|
return (
|
||||||
|
<>
|
||||||
|
{/* Das Hintergrundbild brecht aus allen Containern aus und füllt das Fenster */}
|
||||||
|
<div className="fixed inset-0 -z-10 h-screen w-screen overflow-hidden">
|
||||||
|
{/* <Image
|
||||||
|
src="/fakurian_purple.jpg"
|
||||||
|
alt="Hintergrund"
|
||||||
|
fill
|
||||||
|
className="object-cover"
|
||||||
|
priority
|
||||||
|
/> */}
|
||||||
|
</div>
|
||||||
|
|
||||||
|
{/* Dein Inhalt auf dieser Seite */}
|
||||||
|
<div className="relative">
|
||||||
|
<p>Dashboard is comming soon...</p>
|
||||||
|
</div>
|
||||||
|
</>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
+65
-4
@@ -3,7 +3,6 @@
|
|||||||
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;
|
||||||
@@ -89,9 +88,71 @@ export default function SenderPage() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Screens.Songs
|
<div>
|
||||||
actionName="Anzeigen"
|
{/* LIEDERSUCHE */}
|
||||||
onSelectSong={(song) => sendID(String(song.song_id), String(song.songbook_id))}
|
<div className="p-4 sm:p-6 flex flex-col h-[500px]">
|
||||||
|
<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>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
+4
-15
@@ -1,23 +1,12 @@
|
|||||||
import { ReactNode, ComponentPropsWithoutRef } from "react";
|
import { ReactNode } from "react";
|
||||||
|
|
||||||
interface CardProps extends ComponentPropsWithoutRef<"section"> {
|
export default function Card({title, children}: {title: string, children: ReactNode}) {
|
||||||
title: string;
|
|
||||||
children: ReactNode;
|
|
||||||
hasLeftBorder?: boolean;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default function Card({ title, hasLeftBorder = false, children, className = "", ...props }: CardProps) {
|
|
||||||
return (
|
return (
|
||||||
<section
|
<section className="p-5 flex flex-col justify-between">
|
||||||
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>
|
||||||
|
|||||||
@@ -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,
|
|
||||||
}
|
|
||||||
@@ -3,14 +3,13 @@ import { ComponentPropsWithoutRef } from "react";
|
|||||||
|
|
||||||
interface TextfieldProps extends ComponentPropsWithoutRef<"input"> {}
|
interface TextfieldProps extends ComponentPropsWithoutRef<"input"> {}
|
||||||
|
|
||||||
function Textfield({value, onChange, placeholder, ...props}: TextfieldProps) {
|
function Textfield({value, onChange, placeholder}: 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}
|
|
||||||
/>
|
/>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -47,18 +46,9 @@ 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,10 +2,10 @@ 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 border-b-2 border-slate-500">
|
<header className="fixed top-0 left-0 w-full z-50 p-4 flex justify-between items-center backdrop-blur-md">
|
||||||
<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</NavItem>
|
||||||
<NavItem path="/sender">Sender</NavItem>
|
<NavItem path="/sender">Sender</NavItem>
|
||||||
<NavItem path="/receiver">Empfänger</NavItem>
|
<NavItem path="/receiver">Empfänger</NavItem>
|
||||||
<NavItem path="/admin">Verwaltung</NavItem>
|
<NavItem path="/admin">Verwaltung</NavItem>
|
||||||
|
|||||||
+2
-67
@@ -1,4 +1,5 @@
|
|||||||
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");
|
||||||
@@ -68,32 +69,6 @@ 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(() => {
|
||||||
@@ -120,46 +95,6 @@ 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();
|
||||||
@@ -169,7 +104,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)
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "psalm-talel",
|
"name": "psalm-tafel",
|
||||||
"version": "0.0.5",
|
"version": "0.0.5",
|
||||||
"private": true,
|
"private": true,
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
Reference in new issue
Block a user