diff --git a/app/admin/specials/[id]/page.tsx b/app/admin/specials/[id]/page.tsx index 1890e51..e4d76bf 100644 --- a/app/admin/specials/[id]/page.tsx +++ b/app/admin/specials/[id]/page.tsx @@ -17,22 +17,27 @@ export default function SpecialEditorPage() { const [special, setSpecial] = useState(null); const [loading, setLoading] = useState(true); - useEffect(() => { - const fetchSpecial = async () => { - try { - 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 { + 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); } - }; + } + }; - fetchSpecial(); + useEffect(() => { + fetchSpecial(true); }, [specialId]); const handleSaveStartTime = async (songId: number, startTime: number) => { @@ -46,6 +51,9 @@ export default function SpecialEditorPage() { 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); } }; diff --git a/app/curator/specials/[id]/page.tsx b/app/curator/specials/[id]/page.tsx index 353b1bd..686ed7d 100644 --- a/app/curator/specials/[id]/page.tsx +++ b/app/curator/specials/[id]/page.tsx @@ -25,32 +25,36 @@ export default function CuratorSpecialEditorPage() { const [loading, setLoading] = useState(true); const [error, setError] = useState(null); - useEffect(() => { - const fetchSpecial = async () => { - try { + const fetchSpecial = async (showLoading = true) => { + try { + if (showLoading) { setLoading(true); - const res = await fetch(`/api/curator/specials/${specialId}`, { - headers: getCuratorAuthHeaders(), - }); - if (res.status === 403) { - setError(t('specialForbidden')); - return; - } - if (!res.ok) { - setError('Failed to load special'); - return; - } - const data = await res.json(); - setSpecial(data); - } catch (e) { + } + const res = await fetch(`/api/curator/specials/${specialId}`, { + headers: getCuratorAuthHeaders(), + }); + if (res.status === 403) { + setError(t('specialForbidden')); + return; + } + if (!res.ok) { setError('Failed to load special'); - } finally { + return; + } + const data = await res.json(); + setSpecial(data); + } catch (e) { + setError('Failed to load special'); + } finally { + if (showLoading) { setLoading(false); } - }; + } + }; + useEffect(() => { if (specialId) { - fetchSpecial(); + fetchSpecial(true); } }, [specialId, t]); @@ -67,6 +71,9 @@ export default function CuratorSpecialEditorPage() { setError(t('specialForbidden')); } else if (!res.ok) { setError('Failed to save changes'); + } else { + // Reload special data to update the start time in the song list + await fetchSpecial(false); } };