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

@@ -34,7 +34,7 @@ export function Settings({
message: "", message: "",
}, },
2000, 2000,
) );
}; };
const onSubmit = (e: React.FormEvent<HTMLFormElement>) => { const onSubmit = (e: React.FormEvent<HTMLFormElement>) => {
@@ -49,14 +49,19 @@ 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(
`${import.meta.env.VITE_BASE_API_URL}/update`,
{
body: JSON.stringify(data), body: JSON.stringify(data),
credentials: "include", credentials: "include",
method: "POST", method: "POST",
headers: { headers: {
"Content-Type": "application/json", "Content-Type": "application/json",
}, },
}).catch((e) => { },
)
.then((r) => r.ok)
.catch((e) => {
notify( notify(
{ {
type: "danger", type: "danger",
@@ -68,9 +73,11 @@ export function Settings({
); );
}); });
if (ok) {
await update(); await update();
setLoading(false);
notifySucess(); notifySucess();
}
setLoading(false);
}; };
save(); save();
@@ -78,9 +85,11 @@ export function Settings({
const loadFromSteam = async () => { const loadFromSteam = async () => {
setLoading(true); setLoading(true);
await fetch(`${import.meta.env.VITE_BASE_API_URL}/reload`, { let ok = await fetch(`${import.meta.env.VITE_BASE_API_URL}/reload`, {
credentials: "include", credentials: "include",
}).catch((e) => { })
.then((r) => r.ok)
.catch((e) => {
notify( notify(
{ {
type: "danger", type: "danger",
@@ -92,9 +101,12 @@ export function Settings({
); );
}); });
if (ok) {
await update(); await update();
setLoading(false);
notifySucess(); notifySucess();
}
setLoading(false);
}; };
return ( return (