From e6570dd7ec5d7aea3c3d0c0235476a1227bbe71f Mon Sep 17 00:00:00 2001 From: MohamedBassem Date: Tue, 5 Mar 2024 18:27:38 +0000 Subject: extension: Instead of manually creating api keys, let users exchange their username passwords for one --- packages/browser-extension/src/OptionsPage.tsx | 71 ++++---------------------- 1 file changed, 10 insertions(+), 61 deletions(-) (limited to 'packages/browser-extension/src/OptionsPage.tsx') diff --git a/packages/browser-extension/src/OptionsPage.tsx b/packages/browser-extension/src/OptionsPage.tsx index 5f0f479a..9a490995 100644 --- a/packages/browser-extension/src/OptionsPage.tsx +++ b/packages/browser-extension/src/OptionsPage.tsx @@ -1,22 +1,12 @@ -import React, { useEffect, useRef, useState } from "react"; +import React, { useEffect } from "react"; import usePluginSettings from "./utils/settings"; import { api } from "./utils/trpc"; import Spinner from "./Spinner"; +import { useNavigate } from "react-router-dom"; export default function OptionsPage() { - const [settings, setSettings, _1, _2, _3] = usePluginSettings(); - - const apiKeyRef = useRef(null); - const addressRef = useRef(null); - - const [settingsInput, setSettingsInput] = useState(settings); - - useEffect(() => { - setSettingsInput(settings); - }, [settings]); - - const [isSaved, setIsSaved] = useState(false); - const [error, setError] = useState(null); + const navigate = useNavigate(); + const { settings, setSettings } = usePluginSettings(); const { data: whoami, @@ -24,7 +14,11 @@ export default function OptionsPage() { error: whoAmIError, } = api.users.whoami.useQuery(); - const invalidateWhoami = api.useUtils().users.whoami.invalidate; + const invalidateWhoami = api.useUtils().users.whoami.refetch; + + useEffect(() => { + invalidateWhoami(); + }, [settings, invalidateWhoami]); let loggedInMessage: React.ReactNode; if (whoAmIError) { @@ -43,65 +37,20 @@ export default function OptionsPage() { loggedInMessage = {whoami.name}; } - const onSave = () => { - if (apiKeyRef.current?.value == "") { - setError("API Key can't be empty"); - return; - } - if (addressRef.current?.value == "") { - setError("Server addres can't be empty"); - return; - } - setSettings({ - apiKey: apiKeyRef.current?.value || "", - address: addressRef.current?.value || "https://demo.hoarder.app", - }); - setTimeout(() => { - setIsSaved(false); - }, 2000); - setIsSaved(true); - invalidateWhoami(); - }; - const onLogout = () => { setSettings((s) => ({ ...s, apiKey: "" })); invalidateWhoami(); + navigate("/notconfigured"); }; return (
Settings
-

{error}

Logged in as: {loggedInMessage}
-
- - - setSettingsInput((s) => ({ ...s, address: e.target.value })) - } - className="h-8 flex-1 rounded-lg border border-gray-300 p-2" - /> -
-
- - - setSettingsInput((s) => ({ ...s, apiKey: e.target.value })) - } - className="h-8 flex-1 rounded-lg border border-gray-300 p-2" - /> -
- -- cgit v1.2.3-70-g09d2