Add AbortController cleanup to async frontend effects

This commit is contained in:
2026-04-18 21:30:57 +02:00
parent 2105f8b435
commit 6c053cdaee
16 changed files with 128 additions and 37 deletions

View File

@@ -23,16 +23,27 @@ export function useSchedule(): UseScheduleReturn {
const [error, setError] = useState<string | null>(null);
useEffect(() => {
const controller = new AbortController();
setLoading(true);
fetchSchedule()
setError(null);
fetchSchedule(controller.signal)
.then((data) => {
if (controller.signal.aborted) return;
setInfo(data);
setLoading(false);
})
.catch((err: unknown) => {
if (controller.signal.aborted) return;
handleFetchError(err, setError, "Failed to load schedule");
})
.finally(() => {
if (controller.signal.aborted) return;
setLoading(false);
});
return (): void => {
controller.abort();
};
}, []);
const saveSchedule = useCallback(async (config: ScheduleConfig): Promise<void> => {