Update song list start time after saving changes in waveform editor

This commit is contained in:
Hördle Bot
2025-12-05 21:33:41 +01:00
parent da777ffcf3
commit d816422419
2 changed files with 48 additions and 33 deletions

View File

@@ -17,22 +17,27 @@ export default function SpecialEditorPage() {
const [special, setSpecial] = useState<CurateSpecial | null>(null); const [special, setSpecial] = useState<CurateSpecial | null>(null);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
useEffect(() => { const fetchSpecial = async (showLoading = true) => {
const fetchSpecial = async () => { try {
try { if (showLoading) {
const res = await fetch(`/api/specials/${specialId}`); setLoading(true);
if (res.ok) { }
const data = await res.json(); const res = await fetch(`/api/specials/${specialId}`);
setSpecial(data); if (res.ok) {
} const data = await res.json();
} catch (error) { setSpecial(data);
console.error('Error fetching special:', error); }
} finally { } catch (error) {
console.error('Error fetching special:', error);
} finally {
if (showLoading) {
setLoading(false); setLoading(false);
} }
}; }
};
fetchSpecial(); useEffect(() => {
fetchSpecial(true);
}, [specialId]); }, [specialId]);
const handleSaveStartTime = async (songId: number, startTime: number) => { 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'); const errorText = await res.text().catch(() => res.statusText || 'Unknown error');
console.error('Error updating special song (admin):', res.status, errorText); console.error('Error updating special song (admin):', res.status, errorText);
throw new Error(`Failed to save start time: ${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);
} }
}; };

View File

@@ -25,32 +25,36 @@ export default function CuratorSpecialEditorPage() {
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [error, setError] = useState<string | null>(null); const [error, setError] = useState<string | null>(null);
useEffect(() => { const fetchSpecial = async (showLoading = true) => {
const fetchSpecial = async () => { try {
try { if (showLoading) {
setLoading(true); setLoading(true);
const res = await fetch(`/api/curator/specials/${specialId}`, { }
headers: getCuratorAuthHeaders(), const res = await fetch(`/api/curator/specials/${specialId}`, {
}); headers: getCuratorAuthHeaders(),
if (res.status === 403) { });
setError(t('specialForbidden')); if (res.status === 403) {
return; setError(t('specialForbidden'));
} return;
if (!res.ok) { }
setError('Failed to load special'); if (!res.ok) {
return;
}
const data = await res.json();
setSpecial(data);
} catch (e) {
setError('Failed to load special'); 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); setLoading(false);
} }
}; }
};
useEffect(() => {
if (specialId) { if (specialId) {
fetchSpecial(); fetchSpecial(true);
} }
}, [specialId, t]); }, [specialId, t]);
@@ -67,6 +71,9 @@ export default function CuratorSpecialEditorPage() {
setError(t('specialForbidden')); setError(t('specialForbidden'));
} else if (!res.ok) { } else if (!res.ok) {
setError('Failed to save changes'); setError('Failed to save changes');
} else {
// Reload special data to update the start time in the song list
await fetchSpecial(false);
} }
}; };