From e14bd80d8d488723de22e36294cfd2ac1cc08412 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sat, 29 Aug 2026 18:12:21 +0200 Subject: [PATCH] Fix success notification showing when failing to update settings --- app/components/settings.tsx | 86 +++++++++++++++++++++---------------- 1 file changed, 49 insertions(+), 37 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index 5a5d4c7..e25f06d 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -28,13 +28,13 @@ export function Settings({ const notifySucess = () => { notify( { - type: "success", - loading: false, - title: "Settings successfully updated!", - message: "", - }, - 2000, - ) + type: "success", + loading: false, + title: "Settings successfully updated!", + message: "", + }, + 2000, + ); }; const onSubmit = (e: React.FormEvent) => { @@ -49,14 +49,47 @@ export function Settings({ const save = async () => { setLoading(true); - await fetch(`${import.meta.env.VITE_BASE_API_URL}/update`, { - body: JSON.stringify(data), - credentials: "include", - method: "POST", - headers: { - "Content-Type": "application/json", + let ok = await fetch( + `${import.meta.env.VITE_BASE_API_URL}/update`, + { + body: JSON.stringify(data), + credentials: "include", + method: "POST", + headers: { + "Content-Type": "application/json", + }, }, - }).catch((e) => { + ) + .then((r) => r.ok) + .catch((e) => { + notify( + { + type: "danger", + loading: false, + title: "An error occured.", + message: `An error occured: ${e}`, + }, + 10000, + ); + }); + + if (ok) { + await update(); + notifySucess(); + } + setLoading(false); + }; + + save(); + }; + + const loadFromSteam = async () => { + setLoading(true); + let ok = await fetch(`${import.meta.env.VITE_BASE_API_URL}/reload`, { + credentials: "include", + }) + .then((r) => r.ok) + .catch((e) => { notify( { type: "danger", @@ -68,33 +101,12 @@ export function Settings({ ); }); + if (ok) { await update(); - setLoading(false); notifySucess(); - }; + } - save(); - }; - - const loadFromSteam = async () => { - setLoading(true); - await fetch(`${import.meta.env.VITE_BASE_API_URL}/reload`, { - credentials: "include", - }).catch((e) => { - notify( - { - type: "danger", - loading: false, - title: "An error occured.", - message: `An error occured: ${e}`, - }, - 10000, - ); - }); - - await update(); setLoading(false); - notifySucess(); }; return (