import cx from "classnames"
import React, { useEffect } from "react"
import LegacyClientView from "src/components/views/legacy-client-view"
import LoginClientView from "src/components/views/login-client-view"
import ManagementClientView from "src/components/views/management-client-view"
import ReadonlyClientView from "src/components/views/readonly-client-view"
import useAuth, { AuthResponse } from "src/hooks/auth"
import useNodeData, { NodeData, NodeUpdate } from "src/hooks/node-data"
import { ReactComponent as TailscaleIcon } from "src/icons/tailscale-icon.svg"
import ProfilePic from "src/ui/profile-pic"
import { Link, Route, Router, Switch, useLocation } from "wouter"
import DeviceDetailsView from "./views/device-details-view"
export default function App() {
const { data: auth, loading: loadingAuth, newSession } = useAuth()
return (
{loadingAuth ? (
Loading...
// TODO(sonia): add a loading view
) : (
)}
)
}
function WebClient({
auth,
newSession,
}: {
auth?: AuthResponse
newSession: () => Promise
}) {
const { data, refreshData, updateNode } = useNodeData()
useEffect(() => {
refreshData()
}, [auth, refreshData])
if (!data) {
return Loading...
// TODO(sonia): add a loading view
}
return (
<>
{/* TODO(sonia): get rid of the conditions here once full/readonly
* views live on same components */}
{data.DebugMode === "full" && auth?.ok && }
{data.DebugMode !== "" && (
<>
{/* TODO */}Subnet router
{/* TODO */}Tailscale SSH server
{/* TODO */}Share local content
>
)}
Page not found
>
)
}
function HomeView({
auth,
data,
newSession,
refreshData,
updateNode,
}: {
auth?: AuthResponse
data: NodeData
newSession: () => Promise
refreshData: () => Promise
updateNode: (update: NodeUpdate) => Promise | undefined
}) {
return (
<>
{data?.Status === "NeedsLogin" || data?.Status === "NoState" ? (
// Client not on a tailnet, render login.
updateNode({ Reauthenticate: true })}
/>
) : data.DebugMode === "full" && auth?.ok ? (
// Render new client interface in management mode.
) : data.DebugMode === "login" || data.DebugMode === "full" ? (
// Render new client interface in readonly mode.
) : (
// Render legacy client interface.
)}
{}
>
)
}
function Header({ node }: { node: NodeData }) {
const [loc] = useLocation()
return (
<>
{loc !== "/" && (
← Back to {node.DeviceName}
)}
>
)
}
export function Footer({
licensesURL,
className,
}: {
licensesURL: string
className?: string
}) {
return (
)
}