aboutsummaryrefslogtreecommitdiffstats
path: root/packages/browser-extension/src/SettingsPage.tsx
blob: bae870ac5d68ec2ecf2929efc741950291f6ebdc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import { useRef } from "react";
import usePluginSettings from "./settings";
import { useNavigate } from "react-router-dom";

export default function SettingsPage() {
  const navigate = useNavigate();
  const [settings, setSettings, _1, _2, _3] = usePluginSettings();

  const apiKeyRef = useRef<HTMLInputElement>(null);
  const addressRef = useRef<HTMLInputElement>(null);

  const onSave = () => {
    setSettings({
      apiKey: apiKeyRef.current?.value || "",
      address: addressRef.current?.value || "",
    });
  };

  return (
    <div className="flex flex-col space-y-2">
      <span className="text-lg">Settings</span>
      <hr />
      <div className="flex space-x-2 pt-2">
        <label className="m-auto h-full">API Key</label>
        <input
          ref={apiKeyRef}
          defaultValue={settings.apiKey}
          className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
        />
      </div>
      <div className="flex space-x-2">
        <label className="m-auto h-full">Server Address</label>
        <input
          ref={addressRef}
          defaultValue={settings.address}
          className="h-8 flex-1 rounded-lg border border-gray-300 p-2"
        />
      </div>
      <button
        className="rounded-lg border border-gray-200"
        onClick={onSave}
      >
        Save
      </button>
      <button
        className="rounded-lg border border-gray-200"
        onClick={() => navigate("/")}
      >
        Back
      </button>
    </div>
  );
}