overlays.tsx
This file
Path
apps/web/src/features/shared/shell/overlays.tsx
254 lines · 6.9 KiB · TypeScript
Last changed by
Merge redesign into mainoscabrielbefore adoptioncaedd21
History of this fileTake it
Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 1why, one step back1import { Brand } from "@repo/brand";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 2why, one step back2import type { ProjectListing } from "@repo/protocol/domain/front-page";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 3why, one step back3import { useRouter } from "@tanstack/react-router";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 4why, one step back4import { FolderInput, Keyboard } from "lucide-react";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 5–22why, one step back5import { useRef } from "react";6import type { RefObject } from "react";78import {9 Combobox,10 ComboboxEmpty,11 ComboboxInput,12 ComboboxItem,13 ComboboxList,14} from "../../../components/ui/combobox.tsx";15import {16 Dialog,17 DialogContent,18 DialogDescription,19 DialogHeader,20 DialogTitle,21} from "../../../components/ui/dialog.tsx";22import { Sheet, SheetContent } from "../../../components/ui/sheet.tsx";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 23why, one step back23import { PostureMark } from "../../project/posture-mark.tsx";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 24–25why, one step back24import { KeysHelp, useKeys } from "../keys.tsx";25import { AppLink } from "../link.tsx";Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 26–27why, one step back26import { IMPORT_PATH } from "../paths.ts";27import { useCurrentProject, useShell, useShellReads } from "./context.ts";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 28why, one step back28import type { Overlay } from "./context.ts";Merge redesign into mainoscabrielbefore adoptioncaedd21
line 29why, one step back29import { SITE_LINKS } from "./top-bar.tsx";Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 30–44why, one step back3031export interface OverlayProps {32 readonly overlay: Overlay | undefined;33 readonly onClose: () => void;34}3536const openState = (open: boolean, onClose: () => void) => ({37 onOpenChange: (next: boolean) => {38 if (!next) {39 onClose();40 }41 },42 open,43});44Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 45–47why, one step back45const ROW =46 "text-ui text-foreground hover:bg-surface flex h-10 min-w-0 items-center gap-2.5 px-3 no-underline transition-colors duration-[120ms] focus-visible:outline-offset-[-2px] [&[aria-current]]:font-semibold";47Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 48–51why, one step back48const atLeastTablet = () => globalThis.matchMedia("(min-width: 40rem)").matches;4950const ProjectSwitcher = ({51 input,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 52why, one step back52 listed,Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 53–55why, one step back53 onChosen,54}: {55 readonly input: RefObject<HTMLInputElement | null>;Merge redesign into mainoscabrielbefore adoptioncaedd21
line 56why, one step back56 readonly listed: readonly ProjectListing[] | undefined;Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 57–102why, one step back57 readonly onChosen: () => void;58}) => {59 const current = useCurrentProject();60 const router = useRouter();61 const names = (listed ?? []).map(({ project }) => project);6263 return (64 <Combobox65 autoHighlight66 inline67 items={names}68 onValueChange={(name) => {69 if (name !== null) {70 onChosen();71 router.history.push(`/${name}`);72 }73 }}74 open75 value={current ?? null}76 >77 <div className="border-rule border-b p-3">78 <ComboboxInput79 aria-label="Find a project"80 className="w-full"81 placeholder="Find a project"82 ref={input}83 showTrigger={false}84 />85 </div>86 {listed === undefined ? (87 <p className="text-ui text-muted-foreground p-4">88 Reading the projects…89 </p>90 ) : (91 <>92 <ComboboxEmpty className="p-4">93 No project by that name.94 </ComboboxEmpty>95 <ComboboxList className="max-h-none p-1">96 {(name: string) => {97 const listing = listed.find(({ project }) => project === name);9899 return (100 <ComboboxItem className="h-10 gap-3" key={name} value={name}>101 <span className="min-w-0 truncate font-medium">{name}</span>102 {listing === undefined ? null : (Review fixes for 1203oscabrielbefore adoption950d5e0
lines 103–104why, one step back103 <span className="ml-auto flex shrink-0 items-center gap-3">104 <span className="text-muted-foreground text-label tabular-nums">Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 105–107why, one step back105 {listing.openAsks} open106 </span>107 <PostureMark posture={listing.posture} />Review fixes for 1203oscabrielbefore adoption950d5e0
line 108why, one step back108 </span>Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 109–119why, one step back109 )}110 </ComboboxItem>111 );112 }}113 </ComboboxList>114 </>115 )}116 </Combobox>117 );118};119Merge build/1412-lists-and-people into mainoscabrielbefore adoption3f8c8b9
lines 120–121why, one step back120export const ProjectsSheetBody = ({121 input,Merge redesign into mainoscabrielbefore adoptioncaedd21
line 122why, one step back122 listed,Merge build/1412-lists-and-people into mainoscabrielbefore adoption3f8c8b9
lines 123–125why, one step back123 onChosen,124}: {125 readonly input: RefObject<HTMLInputElement | null>;Merge redesign into mainoscabrielbefore adoptioncaedd21
line 126why, one step back126 readonly listed: readonly ProjectListing[] | undefined;Merge build/1412-lists-and-people into mainoscabrielbefore adoption3f8c8b9
lines 127–129why, one step back127 readonly onChosen: () => void;128}) => (129 <>Merge redesign into mainoscabrielbefore adoptioncaedd21
line 130why, one step back130 <ProjectSwitcher input={input} listed={listed} onChosen={onChosen} />Merge build/1412-lists-and-people into mainoscabrielbefore adoption3f8c8b9
line 131why, one step back131 <div className="border-rule border-t p-1">Merge redesign into mainoscabrielbefore adoptioncaedd21
line 132why, one step back132 <AppLink className={ROW} to={IMPORT_PATH}>Merge build/1412-lists-and-people into mainoscabrielbefore adoption3f8c8b9
lines 133–143why, one step back133 <FolderInput134 aria-hidden="true"135 className="text-muted-foreground size-4 shrink-0"136 strokeWidth={1.75}137 />138 Import a repo139 </AppLink>140 </div>141 </>142);143Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 144–145why, one step back144/** Below `nav` the top bar's links fold into this sheet, with the keys' list. */145export const MenuBody = () => {Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 146–148why, one step back146 const { open } = useShell();147148 return (Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 149–159why, one step back149 <div className="flex flex-col gap-1 px-1 py-2">150 {SITE_LINKS.map(({ label, to }) => (151 <AppLink152 activeOptions={{ includeSearch: false }}153 className={ROW}154 key={to}155 to={to}156 >157 {label}158 </AppLink>159 ))}Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 160why, one step back160 <buttonMerge redesign into mainoscabrielbefore adoptioncaedd21
line 161why, one step back161 className={`${ROW} w-full cursor-pointer`}Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 162–207why, one step back162 onClick={() => {163 open("keys");164 }}165 type="button"166 >167 <Keyboard168 aria-hidden="true"169 className="text-muted-foreground size-4"170 strokeWidth={1.75}171 />172 Keys173 </button>174 </div>175 );176};177178const KeysDialog = ({179 onClose,180 open,181}: {182 readonly onClose: () => void;183 readonly open: boolean;184}) => {185 const keys = useKeys();186187 return (188 <Dialog {...openState(open, onClose)}>189 <DialogContent className="sm:max-w-md">190 <DialogHeader>191 <DialogTitle>Keys</DialogTitle>192 <DialogDescription>193 Every key has a twin you can click: rows are links, files are rows194 of the tree, and commands have their copy buttons.195 </DialogDescription>196 </DialogHeader>197 <KeysHelp198 on={keys?.on ?? true}199 onChange={(on) => {200 keys?.setOn(on);201 }}202 />203 </DialogContent>204 </Dialog>205 );206};207Merge build/comments-web-features into mainoscabrielbefore adoption74bfc72
line 208why, one step back208/** They stay mounted once loaded, so each one slides in from closed. */Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 209–229why, one step back209/** The list is read while the search is open, never by the shell on every page. */210const ListedProjects = ({211 input,212 onChosen,213}: {214 readonly input: RefObject<HTMLInputElement | null>;215 readonly onChosen: () => void;216}) => {217 const { ReadProjects } = useShellReads();218219 return ReadProjects === undefined ? (220 <ProjectsSheetBody input={input} listed={undefined} onChosen={onChosen} />221 ) : (222 <ReadProjects>223 {(listed) => (224 <ProjectsSheetBody input={input} listed={listed} onChosen={onChosen} />225 )}226 </ReadProjects>227 );228};229Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 230–235why, one step back230const ShellOverlays = ({ onClose, overlay }: OverlayProps) => {231 const filter = useRef<HTMLInputElement>(null);232233 return (234 <>235 <Sheet {...openState(overlay === "menu", onClose)}>Merge redesign into mainoscabrielbefore adoptioncaedd21
lines 236–237why, one step back236 <SheetContent side="right" title={Brand.name}>237 <MenuBody />Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 238–243why, one step back238 </SheetContent>239 </Sheet>240 <Sheet {...openState(overlay === "projects", onClose)}>241 <SheetContent242 initialFocus={filter}243 side={overlay === "projects" && atLeastTablet() ? "left" : "full"}Merge redesign into mainoscabrielbefore adoptioncaedd21
line 244why, one step back244 title="Search projects"Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
line 245why, one step back245 >Merge redesign into mainoscabrielbefore adoptioncaedd21
line 246why, one step back246 <ListedProjects input={filter} onChosen={onClose} />Put every page in the Control room shell: rail, bars, workspace, router links, keys, head, error and pending statesoscabrielbefore adoptionddbd51e
lines 247–254why, one step back247 </SheetContent>248 </Sheet>249 <KeysDialog onClose={onClose} open={overlay === "keys"} />250 </>251 );252};253254export default ShellOverlays;