Fix success notification showing when failing to update settings

This commit is contained in:
2026-08-29 18:12:21 +02:00
parent 1329512fbb
commit e14bd80d8d

View File

@@ -28,13 +28,13 @@ export function Settings({
const notifySucess = () => { const notifySucess = () => {
notify( notify(
{ {
type: "success", type: "success",
loading: false, loading: false,
title: "Settings successfully updated!", title: "Settings successfully updated!",
message: "", message: "",
}, },
2000, 2000,
) );
}; };
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => { const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
@@ -49,14 +49,47 @@ export function Settings({
const save = async () => { const save = async () => {
setLoading(true); setLoading(true);
await fetch(`${import.meta.env.VITE_BASE_API_URL}/update`, { let ok = await fetch(
body: JSON.stringify(data), `${import.meta.env.VITE_BASE_API_URL}/update`,
credentials: "include", {
method: "POST", body: JSON.stringify(data),
headers: { credentials: "include",
"Content-Type": "application/json", 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( notify(
{ {
type: "danger", type: "danger",
@@ -68,33 +101,12 @@ export function Settings({
); );
}); });
if (ok) {
await update(); await update();
setLoading(false);
notifySucess(); 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); setLoading(false);
notifySucess();
}; };
return ( return (