From a362559d9c482e9fba843900adf11cc87b1e0180 Mon Sep 17 00:00:00 2001 From: mrjvs Date: Fri, 19 Jan 2024 19:30:25 +0100 Subject: [PATCH] Add onboarding state to settings --- src/pages/parts/settings/ConnectionsPart.tsx | 2 + src/pages/parts/settings/SetupPart.tsx | 79 ++++++++++++++++++++ src/pages/parts/settings/SidebarPart.tsx | 4 +- 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 src/pages/parts/settings/SetupPart.tsx diff --git a/src/pages/parts/settings/ConnectionsPart.tsx b/src/pages/parts/settings/ConnectionsPart.tsx index 007a6220..8a01f2b3 100644 --- a/src/pages/parts/settings/ConnectionsPart.tsx +++ b/src/pages/parts/settings/ConnectionsPart.tsx @@ -8,6 +8,7 @@ import { SettingsCard } from "@/components/layout/SettingsCard"; import { AuthInputBox } from "@/components/text-inputs/AuthInputBox"; import { Divider } from "@/components/utils/Divider"; import { Heading1 } from "@/components/utils/Text"; +import { SetupPart } from "@/pages/parts/settings/SetupPart"; interface ProxyEditProps { proxyUrls: string[] | null; @@ -147,6 +148,7 @@ export function ConnectionsPart(props: BackendEditProps & ProxyEditProps) {
{t("settings.connections.title")}
+ ((resolve, reject) => { + setTimeout(() => reject(new Error("Timed out!")), 1000); + singularProxiedFetch(url, testUrl, {}) + .then((res) => { + if (res.url !== testUrl) return reject(new Error("Not a proxy")); + resolve(); + }) + .catch(reject); + }); +} + +function useIsSetup() { + const proxyUrls = useAuthStore((s) => s.proxySet); + const { loading, value } = useAsync(async (): Promise => { + const extensionStatus: Status = (await isExtensionActive()) + ? "success" + : "unset"; + let proxyStatus: Status = "unset"; + if (proxyUrls && proxyUrls.length > 0) { + try { + await testProxy(proxyUrls[0]); + proxyStatus = "success"; + } catch { + proxyStatus = "error"; + } + } + return { + extension: extensionStatus, + proxy: proxyStatus, + defaultProxy: "success", + }; + }, [proxyUrls]); + + let globalState: Status = "unset"; + if (value?.extension === "success" || value?.proxy === "success") + globalState = "success"; + if (value?.proxy === "error" || value?.extension === "error") + globalState = "error"; + + return { + setupStates: value, + globalState, + loading, + }; +} + +export function SetupPart() { + const navigate = useNavigate(); + const { loading, setupStates, globalState } = useIsSetup(); + if (loading || !setupStates) return

Loading states...

; + return ( +
+

state: {globalState}

+

extension: {setupStates.extension}

+

proxy: {setupStates.proxy}

+

defaults: {setupStates.defaultProxy}

+ +
+ ); +} diff --git a/src/pages/parts/settings/SidebarPart.tsx b/src/pages/parts/settings/SidebarPart.tsx index 2b6e5c3f..560d9e5a 100644 --- a/src/pages/parts/settings/SidebarPart.tsx +++ b/src/pages/parts/settings/SidebarPart.tsx @@ -45,8 +45,8 @@ export function SidebarPart() { }, { textKey: "settings.locale.title", - id: "settings-locale", - icon: Icons.BOOKMARK, + id: "settings-preferences", + icon: Icons.SETTINGS, }, { textKey: "settings.appearance.title",