Changed the Sender Page
This commit is contained in:
1 parent
bdc864cf94
commit
1d047c06a7
4 files changed
+145
-199
No files matched your search
@@ -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"};
|
||||
}
|
||||
}
|
||||
}
|
||||
+7
-77
@@ -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;
|
||||
}
|
||||
|
||||
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)}
|
||||
/>
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user