From 1329512fbbc9a48c5742f4f48e288b50de4a8f80 Mon Sep 17 00:00:00 2001 From: AINDUSTRIES Date: Sat, 29 Aug 2026 18:07:16 +0200 Subject: [PATCH] Implemented settings ui --- app/components/settings.tsx | 118 +++++++++++++++++++++++++++++++++--- 1 file changed, 110 insertions(+), 8 deletions(-) diff --git a/app/components/settings.tsx b/app/components/settings.tsx index e72f86d..5a5d4c7 100644 --- a/app/components/settings.tsx +++ b/app/components/settings.tsx @@ -1,7 +1,6 @@ import { Modal, Button, - InputGroup, Input, TextField, Form, @@ -9,9 +8,11 @@ import { Description, Label, Typography, + Spinner, } from "@heroui/react"; -import type { Dispatch, SetStateAction } from "react"; +import { useState, type Dispatch, type SetStateAction } from "react"; import { useAuth } from "~/hooks/auth"; +import { useNotification } from "~/hooks/notification"; export function Settings({ show, @@ -20,7 +21,82 @@ export function Settings({ show: boolean; setShow: Dispatch>; }) { - const { user, loading, login, logout } = useAuth(); + const { user, update } = useAuth(); + const { notify } = useNotification(); + const [loading, setLoading] = useState(false); + + const notifySucess = () => { + notify( + { + type: "success", + loading: false, + title: "Settings successfully updated!", + message: "", + }, + 2000, + ) + }; + + const onSubmit = (e: React.FormEvent) => { + e.preventDefault(); + const formData = new FormData(e.currentTarget); + const data: Record = {}; + + // Convert FormData to plain object + formData.forEach((value, key) => { + data[key] = value.toString(); + }); + + 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", + }, + }).catch((e) => { + notify( + { + type: "danger", + loading: false, + title: "An error occured.", + message: `An error occured: ${e}`, + }, + 10000, + ); + }); + + 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 (
@@ -39,14 +115,14 @@ export function Settings({ }} /> -
+
Account settings. Update your profile information - either manually or from Steam.{" "} + either manually or from Steam.
Change several settings concerning some functionnalities of the app. @@ -73,8 +149,21 @@ export function Settings({
-
- +