From 73c1c1cf89f1432261115d360ba2eec177ccd506 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?H=C3=B6rdle=20Bot?= Date: Sat, 6 Dec 2025 21:58:27 +0100 Subject: [PATCH] fix: restore accidentally deleted admin specials editor page --- app/admin/specials/[id]/page.tsx | 89 ++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 app/admin/specials/[id]/page.tsx diff --git a/app/admin/specials/[id]/page.tsx b/app/admin/specials/[id]/page.tsx new file mode 100644 index 0000000..e4d76bf --- /dev/null +++ b/app/admin/specials/[id]/page.tsx @@ -0,0 +1,89 @@ +'use client'; + +import { useEffect, useState } from 'react'; +import { useParams, useRouter, usePathname } from 'next/navigation'; +import CurateSpecialEditor, { CurateSpecial } from '@/components/CurateSpecialEditor'; + +export default function SpecialEditorPage() { + const params = useParams(); + const router = useRouter(); + const pathname = usePathname(); + const specialId = params.id as string; + + // Locale aus dem Pfad ableiten (/en/..., /de/...) + const localeFromPath = pathname?.split('/')[1] as 'de' | 'en' | undefined; + const locale: 'de' | 'en' = localeFromPath === 'de' || localeFromPath === 'en' ? localeFromPath : 'en'; + + const [special, setSpecial] = useState(null); + const [loading, setLoading] = useState(true); + + const fetchSpecial = async (showLoading = true) => { + try { + if (showLoading) { + setLoading(true); + } + const res = await fetch(`/api/specials/${specialId}`); + if (res.ok) { + const data = await res.json(); + setSpecial(data); + } + } catch (error) { + console.error('Error fetching special:', error); + } finally { + if (showLoading) { + setLoading(false); + } + } + }; + + useEffect(() => { + fetchSpecial(true); + }, [specialId]); + + const handleSaveStartTime = async (songId: number, startTime: number) => { + const res = await fetch(`/api/specials/${specialId}/songs`, { + method: 'PUT', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ songId, startTime }), + }); + + if (!res.ok) { + const errorText = await res.text().catch(() => res.statusText || 'Unknown error'); + console.error('Error updating special song (admin):', res.status, errorText); + throw new Error(`Failed to save start time: ${errorText}`); + } else { + // Reload special data to update the start time in the song list + await fetchSpecial(false); + } + }; + + if (loading) { + return ( +
+

Loading...

+
+ ); + } + + if (!special) { + return ( +
+

Special not found

+ +
+ ); + } + + return ( + router.push('/admin')} + onSaveStartTime={handleSaveStartTime} + backLabel="← Back to Admin" + headerPrefix="Edit Special:" + noSongsSubHint="Go back to the admin dashboard to add songs to this special." + /> + ); +} +