From bafbc3da4c4f150347142b18fc28cf2d4b9d773b Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Fri, 11 Apr 2025 00:04:58 +0200 Subject: [PATCH] Ui fixes --- .../devices.$id.settings.access._index.tsx | 93 +++++++++++-------- ui/src/routes/devices.$id.settings.tsx | 13 ++- 2 files changed, 64 insertions(+), 42 deletions(-) diff --git a/ui/src/routes/devices.$id.settings.access._index.tsx b/ui/src/routes/devices.$id.settings.access._index.tsx index ac8cbc2..d8eebf9 100644 --- a/ui/src/routes/devices.$id.settings.access._index.tsx +++ b/ui/src/routes/devices.$id.settings.access._index.tsx @@ -14,17 +14,17 @@ import notifications from "@/notifications"; import { DEVICE_API } from "@/ui.config"; import { useJsonRpc } from "@/hooks/useJsonRpc"; import { isOnDevice } from "@/main"; +import { TextAreaWithLabel } from "@components/TextArea"; import { LocalDevice } from "./devices.$id"; import { SettingsItem } from "./devices.$id.settings"; import { CloudState } from "./adopt"; -import { TextAreaWithLabel } from "@components/TextArea"; export interface TLSState { mode: "self-signed" | "custom" | "disabled"; certificate?: string; privateKey?: string; -}; +} export const loader = async () => { if (isOnDevice) { @@ -147,9 +147,37 @@ export default function SettingsAccessIndexRoute() { } }; + // Function to update TLS state - accepts a mode parameter + const updateTlsState = useCallback( + (mode: string, cert?: string, key?: string) => { + const state = { mode } as TLSState; + if (cert && key) { + state.certificate = cert; + state.privateKey = key; + } + + send("setTLSState", { state }, resp => { + if ("error" in resp) { + notifications.error( + `Failed to update TLS settings: ${resp.error.data || "Unknown error"}`, + ); + return; + } + + notifications.success("TLS settings updated successfully"); + }); + }, + [send], + ); + // Handle TLS mode change const handleTlsModeChange = (value: string) => { setTlsMode(value); + + // For "disabled" and "self-signed" modes, immediately apply the settings + if (value !== "custom") { + updateTlsState(value); + } }; const handleTlsCertChange = (value: string) => { @@ -160,21 +188,10 @@ export default function SettingsAccessIndexRoute() { setTlsKey(value); }; - const handleTlsUpdate = useCallback(() => { - const state = { mode: tlsMode } as TLSState; - if (tlsMode !== "disabled") { - state.certificate = tlsCert; - state.privateKey = tlsKey; - } - send("setTLSState", { state }, resp => { - if ("error" in resp) { - notifications.error(`Failed to update TLS settings: ${resp.error.data || "Unknown error"}`); - return; - } - - notifications.success("TLS settings updated successfully"); - }); - }, [send, tlsMode, tlsCert, tlsKey]); + // Update the custom TLS settings button click handler + const handleCustomTlsUpdate = () => { + updateTlsState(tlsMode, tlsCert, tlsKey); + }; // Fetch device ID and cloud state on component mount useEffect(() => { @@ -203,11 +220,9 @@ export default function SettingsAccessIndexRoute() { /> <> - Select the TLS mode for your device experimental
- The feature might not work as expected, please report any issues if you encounter any. - } + title="HTTPS Mode" + badge="Experimental" + description="Configure secure HTTPS access to your device" >
handleTlsCertChange(e.target.value)} /> @@ -243,32 +260,28 @@ export default function SettingsAccessIndexRoute() {
handleTlsKeyChange(e.target.value)} /> -

- Private key won't be shown again after saving. -

+
+
)} - -
-
-
-
-
-

{title}

+
+ {title} + {badge && ( + + {badge} + + )} +
{loading && }
-

{description}

+
{description}
{children ?
{children}
: null}