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 = () => {
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<HTMLFormElement>) => {
@@ -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 (