import cx from "classnames"
import React, { useEffect } from "react"
import LoginToggle from "src/components/login-toggle"
import DeviceDetailsView from "src/components/views/device-details-view"
import HomeView from "src/components/views/home-view"
import LegacyClientView from "src/components/views/legacy-client-view"
import LoginClientView from "src/components/views/login-client-view"
import SSHView from "src/components/views/ssh-view"
import useAuth, { AuthResponse } from "src/hooks/auth"
import useNodeData, { NodeData } from "src/hooks/node-data"
import { ReactComponent as TailscaleIcon } from "src/icons/tailscale-icon.svg"
import { Link, Route, Router, Switch, useLocation } from "wouter"
export default function App() {
const { data: auth, loading: loadingAuth, newSession } = useAuth()
return (
{loadingAuth || !auth ? (
Loading...
// TODO(sonia): add a loading view
) : (
)}
)
}
function WebClient({
auth,
newSession,
}: {
auth: AuthResponse
newSession: () => Promise
}) {
const { data, refreshData, updateNode, updatePrefs } = useNodeData()
useEffect(() => {
refreshData()
}, [auth, refreshData])
return !data ? (
Loading...
) : data.Status === "NeedsLogin" || data.Status === "NoState" ? (
// Client not on a tailnet, render login.
updateNode({ Reauthenticate: true })}
/>
) : data.DebugMode !== "full" && data.DebugMode !== "login" ? (
// Render legacy client interface.
<>
{/* TODO: add license to new client */}
>
) : (
// Otherwise render the new web client.
<>
{/* TODO */}Subnet router
{/* TODO */}Share local content
Page not found
>
)
}
function Header({
node,
auth,
newSession,
}: {
node: NodeData
auth: AuthResponse
newSession: () => Promise
}) {
const [loc] = useLocation()
return (
<>
{loc !== "/" && (
← Back to {node.DeviceName}
)}
>
)
}
function Footer({
licensesURL,
className,
}: {
licensesURL: string
className?: string
}) {
return (
)
}