The best way to control Claude Code, Codex and more from any computer or phone
| 1 | import { |
| 2 | type AddProjectRemoteSource, |
| 3 | type NewProjectPublishTarget, |
| 4 | } from "@t3tools/client-runtime/operations/projects"; |
| 5 | import { sourceControlClients } from "@t3tools/client-runtime/source-control-clients"; |
| 6 | import type { SourceControlProviderKind } from "@t3tools/contracts"; |
| 7 | import { FolderGit2Icon, LinkIcon } from "lucide-react"; |
| 8 | import { type ReactNode, useState } from "react"; |
| 9 | import { T, useGT } from "gt-react"; |
| 10 | |
| 11 | import { sourceControlIcon } from "~/sourceControlPresentation"; |
| 12 | import { ITEM_ICON_CLASS } from "./CommandPalette.logic"; |
| 13 | import { CommandPaletteTitleIcon } from "./CommandPaletteResults"; |
| 14 | import { Button } from "./ui/button"; |
| 15 | import { Kbd, KbdGroup } from "./ui/kbd"; |
| 16 | import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "./ui/select"; |
| 17 | import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; |
| 18 | |
| 19 | export function remoteProjectSourceIcon( |
| 20 | source: AddProjectRemoteSource, |
| 21 | className: string, |
| 22 | ): ReactNode { |
| 23 | if (source === "url") return <LinkIcon className={className} />; |
| 24 | const Icon = sourceControlIcon(sourceControlClients.get(source)); |
| 25 | return <Icon className={className} />; |
| 26 | } |
| 27 | |
| 28 | export function sourceControlHostIcon( |
| 29 | definition: NewProjectPublishTarget["definition"], |
| 30 | className: string, |
| 31 | ): ReactNode { |
| 32 | const Icon = sourceControlIcon(definition); |
| 33 | return <Icon className={className} />; |
| 34 | } |
| 35 | |
| 36 | /** The input's trailing submit button for the add-project, clone, and new-project flows. */ |
| 37 | export function CommandPaletteSubmitButton(props: { |
| 38 | readonly id: string; |
| 39 | readonly label: ReactNode; |
| 40 | readonly shortcutLabel: string; |
| 41 | readonly ariaLabel: string; |
| 42 | readonly tooltip: ReactNode; |
| 43 | readonly disabled: boolean; |
| 44 | readonly onSubmit: () => void; |
| 45 | }) { |
| 46 | return ( |
| 47 | <Tooltip> |
| 48 | <TooltipTrigger |
| 49 | render={ |
| 50 | <Button |
| 51 | id={props.id} |
| 52 | variant="outline" |
| 53 | size="xs" |
| 54 | className="absolute inset-e-2.5 top-1/2 -translate-y-1/2" |
| 55 | aria-label={props.ariaLabel} |
| 56 | disabled={props.disabled} |
| 57 | onMouseDown={(event) => { |
| 58 | event.preventDefault(); |
| 59 | }} |
| 60 | onClick={props.onSubmit} |
| 61 | /> |
| 62 | } |
| 63 | > |
| 64 | <span>{props.label}</span> |
| 65 | <KbdGroup className="pointer-events-none -me-0.5"> |
| 66 | <Kbd>{props.shortcutLabel}</Kbd> |
| 67 | </KbdGroup> |
| 68 | </TooltipTrigger> |
| 69 | <TooltipPopup side="top">{props.tooltip}</TooltipPopup> |
| 70 | </Tooltip> |
| 71 | ); |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * Picks which host a new project publishes to. The row it sits in toggles on click, so the |
| 76 | * picker keeps its clicks to itself. The row also cancels pointerdown to keep focus in the |
| 77 | * input, which drops the mousedown Select opens on, so the picker opens on click instead. |
| 78 | */ |
| 79 | export function NewProjectPublishHostPicker(props: { |
| 80 | readonly disabled: boolean; |
| 81 | readonly targets: ReadonlyArray<NewProjectPublishTarget>; |
| 82 | readonly value: SourceControlProviderKind; |
| 83 | readonly onValueChange: (kind: SourceControlProviderKind) => void; |
| 84 | }) { |
| 85 | const gt = useGT(); |
| 86 | const [open, setOpen] = useState(false); |
| 87 | return ( |
| 88 | <span |
| 89 | className="flex" |
| 90 | onClick={(event) => { |
| 91 | event.stopPropagation(); |
| 92 | // React bubbles the popup's clicks here through its portal; only the |
| 93 | // trigger opens the picker. |
| 94 | if (!event.currentTarget.contains(event.target as Node)) return; |
| 95 | if (!props.disabled) setOpen(true); |
| 96 | }} |
| 97 | > |
| 98 | <Select |
| 99 | disabled={props.disabled} |
| 100 | open={open} |
| 101 | onOpenChange={setOpen} |
| 102 | value={props.value} |
| 103 | onValueChange={(kind) => { |
| 104 | if (kind !== null) props.onValueChange(kind); |
| 105 | }} |
| 106 | > |
| 107 | <SelectTrigger size="xs" variant="ghost" aria-label={gt("Host for the new repository")}> |
| 108 | <SelectValue> |
| 109 | {(kind: SourceControlProviderKind) => sourceControlClients.get(kind).label} |
| 110 | </SelectValue> |
| 111 | </SelectTrigger> |
| 112 | <SelectPopup align="end" alignItemWithTrigger={false}> |
| 113 | {props.targets.map((target) => ( |
| 114 | <SelectItem key={target.definition.kind} hideIndicator value={target.definition.kind}> |
| 115 | <span className="inline-flex items-center gap-1.5"> |
| 116 | {sourceControlHostIcon(target.definition, "size-3.5")} |
| 117 | {target.definition.label} |
| 118 | </span> |
| 119 | </SelectItem> |
| 120 | ))} |
| 121 | </SelectPopup> |
| 122 | </Select> |
| 123 | </span> |
| 124 | ); |
| 125 | } |
| 126 | |
| 127 | export function NewProjectSummary(props: { |
| 128 | readonly name: string; |
| 129 | readonly pathPreview: string; |
| 130 | readonly projectsRoot: string | null; |
| 131 | readonly environmentLabel: string | null; |
| 132 | }) { |
| 133 | const gt = useGT(); |
| 134 | const environment = props.environmentLabel; |
| 135 | return ( |
| 136 | <div className="p-2 pb-0"> |
| 137 | <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5"> |
| 138 | <CommandPaletteTitleIcon> |
| 139 | <FolderGit2Icon className={ITEM_ICON_CLASS} /> |
| 140 | </CommandPaletteTitleIcon> |
| 141 | <span className="flex min-w-0 flex-1 flex-col"> |
| 142 | <span className="truncate text-foreground text-sm"> |
| 143 | {props.name.length > 0 ? props.name : gt("New project")} |
| 144 | </span> |
| 145 | <span className="truncate text-muted-foreground/85 text-xs"> |
| 146 | {props.name.length > 0 |
| 147 | ? environment === null |
| 148 | ? gt("Creates {path}", { path: props.pathPreview }) |
| 149 | : gt("Creates {path} on {environment}", { path: props.pathPreview, environment }) |
| 150 | : environment === null |
| 151 | ? gt("Goes in {root}", { root: String(props.projectsRoot) }) |
| 152 | : gt("Goes in {root} on {environment}", { |
| 153 | root: String(props.projectsRoot), |
| 154 | environment, |
| 155 | })} |
| 156 | </span> |
| 157 | </span> |
| 158 | </div> |
| 159 | </div> |
| 160 | ); |
| 161 | } |
| 162 | |
| 163 | export function RemoteRepositorySummary(props: { |
| 164 | readonly source: AddProjectRemoteSource; |
| 165 | readonly title: string; |
| 166 | readonly description: string; |
| 167 | }) { |
| 168 | return ( |
| 169 | <div className="shrink-0 p-2 pb-0"> |
| 170 | <div className="px-2 py-1.5 font-medium text-muted-foreground text-xs"> |
| 171 | <T>Repository</T> |
| 172 | </div> |
| 173 | <div className="flex min-h-8 items-center gap-2 rounded-sm px-2 py-1.5"> |
| 174 | <CommandPaletteTitleIcon> |
| 175 | {remoteProjectSourceIcon(props.source, ITEM_ICON_CLASS)} |
| 176 | </CommandPaletteTitleIcon> |
| 177 | <span className="flex min-w-0 flex-1 flex-col"> |
| 178 | <span className="truncate text-foreground text-sm">{props.title}</span> |
| 179 | <span className="truncate text-muted-foreground/85 text-xs">{props.description}</span> |
| 180 | </span> |
| 181 | </div> |
| 182 | </div> |
| 183 | ); |
| 184 | } |