mirror of
https://github.com/outbackdingo/firezone.git
synced 2026-01-27 10:18:54 +00:00
Despite still being in development, the `tauri-specta` project already proves to be quite useful. It allows us to generate TypeScript bindings for our commands and events, creating a type-safe contract between the frontend and the backend. For example, this ensures that the TypeScript code calls a command actually with the required parameters and thus avoids runtime failures. Similarly, the frontend can listen on type-safe events without having to use any magic strings.
114 lines
2.8 KiB
TypeScript
114 lines
2.8 KiB
TypeScript
import React from "react";
|
|
import logo from "../logo.png";
|
|
import { Button, Spinner } from "flowbite-react";
|
|
import { SessionViewModel } from "../generated/bindings";
|
|
|
|
interface OverviewPageProps {
|
|
session: SessionViewModel | null;
|
|
signOut: () => void;
|
|
signIn: () => void;
|
|
}
|
|
|
|
export default function Overview(props: OverviewPageProps) {
|
|
return (
|
|
<div className="flex flex-col items-center justify-center gap-4 min-h-screen">
|
|
<img src={logo} alt="Firezone Logo" className="w-40 h-40" />
|
|
|
|
<h1 className="text-6xl font-bold">Firezone</h1>
|
|
|
|
<Session {...props} />
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Session(props: OverviewPageProps) {
|
|
if (!props.session) {
|
|
return <SignedOut {...props} />;
|
|
}
|
|
|
|
switch (props.session) {
|
|
case "SignedOut": {
|
|
return <SignedOut {...props} />;
|
|
}
|
|
case "Loading": {
|
|
return <Loading />;
|
|
}
|
|
default: {
|
|
const { account_slug, actor_name } = props.session.SignedIn;
|
|
|
|
return (
|
|
<SignedIn
|
|
accountSlug={account_slug}
|
|
actorName={actor_name}
|
|
signOut={props.signOut}
|
|
/>
|
|
);
|
|
}
|
|
}
|
|
}
|
|
|
|
interface SignedOutProps {
|
|
signIn: () => void;
|
|
}
|
|
|
|
function SignedOut({ signIn }: SignedOutProps) {
|
|
return (
|
|
<div>
|
|
<div className="flex flex-col items-center gap-4">
|
|
<p className="text-center">
|
|
You can sign in by clicking the Firezone icon in the taskbar or by
|
|
clicking "Sign in" below.
|
|
</p>
|
|
<Button onClick={signIn}>Sign in</Button>
|
|
<p className="text-xs text-center">
|
|
Firezone will continue running after this window is closed.
|
|
<br />
|
|
It is always available from the taskbar.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
interface SignedInProps {
|
|
accountSlug: string;
|
|
actorName: string;
|
|
signOut: () => void;
|
|
}
|
|
|
|
function SignedIn({ actorName, accountSlug, signOut }: SignedInProps) {
|
|
return (
|
|
<div>
|
|
<div className="flex flex-col items-center gap-4">
|
|
<p className="text-center">
|
|
You are currently signed into
|
|
<span className="font-bold">{accountSlug}</span>
|
|
as
|
|
<span className="font-bold">{actorName}</span>
|
|
.<br />
|
|
Click the Firezone icon in the taskbar to see the list of Resources.
|
|
</p>
|
|
<Button onClick={signOut}>Sign out</Button>
|
|
<p className="text-xs text-center">
|
|
Firezone will continue running in the taskbar after this window is
|
|
closed.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
function Loading() {
|
|
return (
|
|
<div>
|
|
<div className="flex flex-col items-center gap-4">
|
|
<Spinner />
|
|
<p className="text-xs text-center">
|
|
Firezone will continue running in the taskbar after this window is
|
|
closed.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
);
|
|
}
|