refactor: refactor UI using jotai

This commit is contained in:
Kevin Yue
2023-06-07 09:20:44 +08:00
parent c07e232ec2
commit 1af21432d4
27 changed files with 866 additions and 640 deletions

44
gpgui/src/atoms/status.ts Normal file
View File

@@ -0,0 +1,44 @@
import { atom } from "jotai";
import vpnService from "../services/vpnService";
export type Status =
| "disconnected"
| "prelogin"
| "authenticating-saml"
| "authenticating-password"
| "portal-config"
| "gateway-login"
| "connecting"
| "connected"
| "disconnecting"
| "error";
export const statusAtom = atom<Status>("disconnected");
statusAtom.onMount = (setAtom) => {
return vpnService.onStatusChanged((status) => {
status === "connected" && setAtom("connected");
});
};
const statusTextMap: Record<Status, String> = {
disconnected: "Not Connected",
prelogin: "Portal pre-logging in...",
"authenticating-saml": "Authenticating...",
"authenticating-password": "Authenticating...",
"portal-config": "Retrieving portal config...",
"gateway-login": "Logging in to gateway...",
connecting: "Connecting...",
connected: "Connected",
disconnecting: "Disconnecting...",
error: "Error",
};
export const statusTextAtom = atom((get) => {
const status = get(statusAtom);
return statusTextMap[status];
});
export const isProcessingAtom = atom((get) => {
const status = get(statusAtom);
return status !== "disconnected" && status !== "connected";
});