iterate.com / cloud

git clone https://git.iterate.com/repos/cloud

cloud / internal-packages / installer / src / CloudNav.tsxmain at aacbc74

// The sidebar of iterate Cloud, on every page of it: the person's deployments, and the wizard for
// a new one. Collapsed, each row is its icon with the row's words as a tooltip.
import { Link, useNavigate, useRouterState } from "@tanstack/react-router";
import { Plus, Server } from "lucide-react";
import {
  SidebarGroup,
  SidebarGroupContent,
  SidebarGroupLabel,
  SidebarMenu,
  SidebarMenuButton,
  SidebarMenuItem,
} from "@iterate-com/ui/components/ui/sidebar";
import { cn } from "cn";
import { startNewDeployment, useDeployments, useMe } from "./your-deployments.ts";

export function CloudNav() {
  const path = useRouterState({ select: (state) => state.location.pathname });
  const hash = useRouterState({ select: (state) => state.location.hash });
  const navigate = useNavigate();
  const { me } = useMe();
  const deployments = useDeployments(me?.connected === true).data?.deployments || [];
  return (
    <>
      <SidebarGroup>
        <SidebarGroupContent>
          <SidebarMenu>
            <SidebarMenuItem>
              <SidebarMenuButton
                isActive={path === "/deployments" && !hash}
                tooltip="Your deployments"
                render={<Link to="/deployments" data-nav="deployments" />}
              >
                <Server />
                <span>Your deployments</span>
              </SidebarMenuButton>
            </SidebarMenuItem>
            <SidebarMenuItem>
              <SidebarMenuButton
                isActive={path === "/"}
                tooltip="New deployment"
                render={
                  <Link
                    to="/"
                    data-nav="new"
                    // the wizard from its first question, once its own start has run
                    onClick={(event) => {
                      event.preventDefault();
                      void startNewDeployment().then(() => navigate({ to: "/" }));
                    }}
                  />
                }
              >
                <Plus />
                <span>New deployment</span>
              </SidebarMenuButton>
            </SidebarMenuItem>
          </SidebarMenu>
        </SidebarGroupContent>
      </SidebarGroup>
      {deployments.length > 0 && (
        <SidebarGroup className="group-data-[collapsible=icon]:hidden">
          <SidebarGroupLabel>Deployments</SidebarGroupLabel>
          <SidebarGroupContent>
            <SidebarMenu>
              {deployments.map((deployment) => (
                <SidebarMenuItem key={deployment.domain}>
                  <SidebarMenuButton
                    isActive={path === "/deployments" && hash === deployment.domain}
                    render={
                      <Link
                        to="/deployments"
                        hash={deployment.domain}
                        data-nav-deployment={deployment.domain}
                      />
                    }
                  >
                    <span
                      aria-hidden
                      className={cn(
                        "size-2 shrink-0 rounded-full",
                        deployment.answers ? "bg-success" : "bg-warning",
                      )}
                    />
                    <span className="truncate">{deployment.domain}</span>
                    <span className="sr-only">
                      {deployment.answers ? "answers" : "does not answer"}
                    </span>
                  </SidebarMenuButton>
                </SidebarMenuItem>
              ))}
            </SidebarMenu>
          </SidebarGroupContent>
        </SidebarGroup>
      )}
    </>
  );
}