Update song list start time after saving changes in waveform editor
This commit is contained in:
@@ -17,9 +17,11 @@ 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) {
|
||||||
|
setLoading(true);
|
||||||
|
}
|
||||||
const res = await fetch(`/api/specials/${specialId}`);
|
const res = await fetch(`/api/specials/${specialId}`);
|
||||||
if (res.ok) {
|
if (res.ok) {
|
||||||
const data = await res.json();
|
const data = await res.json();
|
||||||
@@ -28,11 +30,14 @@ export default function SpecialEditorPage() {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error fetching special:', error);
|
console.error('Error fetching special:', error);
|
||||||
} finally {
|
} 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -25,10 +25,11 @@ 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}`, {
|
const res = await fetch(`/api/curator/specials/${specialId}`, {
|
||||||
headers: getCuratorAuthHeaders(),
|
headers: getCuratorAuthHeaders(),
|
||||||
});
|
});
|
||||||
@@ -45,12 +46,15 @@ export default function CuratorSpecialEditorPage() {
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
setError('Failed to load special');
|
setError('Failed to load special');
|
||||||
} finally {
|
} 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);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user