diff --git a/app/admin/page.tsx b/app/admin/page.tsx index e9eb936..95e699e 100644 --- a/app/admin/page.tsx +++ b/app/admin/page.tsx @@ -5,6 +5,7 @@ import { useEffect, useState } from "react"; import Card from "@/components/Card" import { Input } from "@/components/FormElements"; +import { Screens } from "@/components/DatabaseOverview"; interface Songbook { id: number; @@ -121,7 +122,7 @@ export default function AdminPage() {
- + Name des Buchs
- + Sprache (Optional)
- + Liederbuch wählen setSelectedSongbookId(e.target.value)} @@ -165,7 +166,7 @@ export default function AdminPage() {
- + Nummer
- + Titel
- + Ziel-Liederbuch setSelectedSongbookId(e.target.value)} @@ -206,7 +207,7 @@ export default function AdminPage() {
- + Datei auswählen (.csv)
+
+ console.log(song)} + className="" + /> + + + +
); diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..71c7436 --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,23 @@ +import Image from "next/image"; + +export default function DashboardPage() { + return ( + <> + {/* Das Hintergrundbild brecht aus allen Containern aus und füllt das Fenster */} +
+ {/* Hintergrund */} +
+ + {/* Dein Inhalt auf dieser Seite */} +
+

Dashboard is comming soon...

+
+ + ); +} \ No newline at end of file diff --git a/app/page.tsx b/app/page.tsx index 71c7436..e1e2b7e 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,23 +1,5 @@ -import Image from "next/image"; +import { redirect } from "next/navigation"; -export default function DashboardPage() { - return ( - <> - {/* Das Hintergrundbild brecht aus allen Containern aus und füllt das Fenster */} -
- {/* Hintergrund */} -
- - {/* Dein Inhalt auf dieser Seite */} -
-

Dashboard is comming soon...

-
- - ); +export default function Page() { + redirect("/dashboard") } \ No newline at end of file diff --git a/app/sender/page.tsx b/app/sender/page.tsx index a5a3486..71e4465 100644 --- a/app/sender/page.tsx +++ b/app/sender/page.tsx @@ -3,6 +3,7 @@ import { useState, useEffect } from "react"; import { Input } from "@/components/FormElements"; +import { Screens } from "@/components/DatabaseOverview"; interface Songbook { id: number; @@ -88,71 +89,9 @@ export default function SenderPage() { }; return ( -
- {/* LIEDERSUCHE */} -
-

- Liedersuche & Datenbank -

- -
- search(e.target.value)} - /> -
- - {/* TABELLE */} -
- - - - - - - - - - - {searchResults.length === 0 ? ( - - - - ) : ( - searchResults.map((song) => { - const songBook = songbooks.find((book) => book.id === song.songbook_id); - return ( - - - - - - - ); - }) - )} - -
TitelLiederbuchNummerAktion
Keine Lieder gefunden
- {song.title} - - {songBook ? songBook.name : "Unbekannt"} - - - {songBook ? songBook.name : "Unbekannt"} - - {song.song_number} - - 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 - -
-
-
-
+ sendID(String(song.song_id), String(song.songbook_id))} + /> ); } \ No newline at end of file diff --git a/components/Card.tsx b/components/Card.tsx index 0a8450d..e5c1377 100644 --- a/components/Card.tsx +++ b/components/Card.tsx @@ -1,14 +1,22 @@ -import { ReactNode } from "react"; +import { ReactNode, ComponentPropsWithoutRef } from "react"; -export default function Card({title, children}: {title: string, children: ReactNode}) { - return ( -
-

- {title} -

-
- {children} -
-
- ); +interface CardProps extends ComponentPropsWithoutRef<"section"> { + title: string; + children: ReactNode; +} + +export default function Card({ title, children, className = "", ...props }: CardProps) { + return ( +
+

+ {title} +

+
+ {children} +
+
+ ); } \ No newline at end of file diff --git a/components/DatabaseOverview.tsx b/components/DatabaseOverview.tsx new file mode 100644 index 0000000..1e327f7 --- /dev/null +++ b/components/DatabaseOverview.tsx @@ -0,0 +1,143 @@ +import { useState, useEffect, ComponentPropsWithoutRef } from "react"; + +import Card from "./Card" +import { Input } from "./FormElements" + +interface SongsProps extends Omit, "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([]); + const [allSongs, setAllSongs] = useState([]); + const [songbooks, setSongbooks] = useState([]); + + + 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 ( + +
+ search(e.target.value)} + /> +
+ {/* TABELLE */} +
+ + + + + + + + + + + {searchResults.length === 0 ? ( + + + + ) : ( + searchResults.map((song) => { + const songBook = songbooks.find((book) => book.id === song.songbook_id); + return ( + + + + + + + ); + }) + )} + +
TitelLiederbuchNummerAktion
Keine Lieder gefunden
+ {song.title} + + {songBook ? songBook.name : "Unbekannt"} + + + {songBook ? songBook.name : "Unbekannt"} + + {song.song_number} + + 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} + +
+
+
+ ) +} + +export const Screens = { + Songs: Songs, +} \ No newline at end of file diff --git a/components/FormElements.tsx b/components/FormElements.tsx index d2f722c..fd78cad 100644 --- a/components/FormElements.tsx +++ b/components/FormElements.tsx @@ -3,13 +3,14 @@ import { ComponentPropsWithoutRef } from "react"; interface TextfieldProps extends ComponentPropsWithoutRef<"input"> {} -function Textfield({value, onChange, placeholder}: TextfieldProps) { +function Textfield({value, onChange, placeholder, ...props}: TextfieldProps) { return ( ) } @@ -46,9 +47,18 @@ function Button({ children, ...props }: ComponentPropsWithoutRef<"button">) { ) } +function Label( {children}: ComponentPropsWithoutRef<"label">) { + return ( + + ) +} + export const Input = { Text: Textfield, Select: Dropdown, File: File, Button: Button, + Label: Label, }; \ No newline at end of file diff --git a/components/Header.tsx b/components/Header.tsx index 3aa6a89..c9b3882 100644 --- a/components/Header.tsx +++ b/components/Header.tsx @@ -5,7 +5,7 @@ export default function Header() {
PsalmTafel