Skip to content
Source
Sign inSign up
pingdotgg/t3code
Open History to see the last commit

ThreadCommandSubtitle.tsx

104 lines3.7 KB

1import type { ProviderDriverKind } from "@t3tools/contracts";
2import { FolderGit2Icon, FolderIcon, GitBranchIcon } from "lucide-react";
3import { ProjectFavicon, type ProjectFaviconProject } from "./ProjectFavicon";
4import { ProviderInstanceIcon } from "./chat/ProviderInstanceIcon";
5import { cn } from "~/lib/utils";
6​
7/**
8 * Flip this while reviewing command-palette thread subtitles.
9 * - favicon-workspace-harness: favicon + Folder/FolderGit2 + branch + harness (default)
10 * - favicon-workspace: same without harness
11 * - favicon-branch-harness: GitBranch for local, FolderGit2 for worktrees, + harness
12 */
13export type ThreadCommandSubtitleVariant =
14 | "favicon-workspace-harness"
15 | "favicon-workspace"
16 | "favicon-branch-harness";
17​
18const THREAD_COMMAND_SUBTITLE_VARIANT: ThreadCommandSubtitleVariant = "favicon-workspace-harness";
19​
20export const COMMAND_PALETTE_META_ICON_CLASS = "size-3 shrink-0 text-muted-foreground/70";
21​
22export function CommandPaletteMetaDot() {
23 return <span className="shrink-0 text-muted-foreground/50">·</span>;
25​
26function WorkspaceIcon(props: { variant: ThreadCommandSubtitleVariant; isWorktree: boolean }) {
27 if (props.isWorktree) {
28 return <FolderGit2Icon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
29 }
30 if (props.variant === "favicon-branch-harness") {
31 return <GitBranchIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
32 }
33 return <FolderIcon className={COMMAND_PALETTE_META_ICON_CLASS} aria-hidden />;
35​
36export function ThreadCommandSubtitle(props: {
37 project: ProjectFaviconProject | null;
38 projectTitle: string | null;
39 branch: string | null;
40 worktreePath: string | null;
41 isCurrent: boolean;
42 driverKind?: ProviderDriverKind | null;
43 providerDisplayName?: string | null;
44 variant?: ThreadCommandSubtitleVariant;
45 className?: string;
46}) {
47 const variant = props.variant ?? THREAD_COMMAND_SUBTITLE_VARIANT;
48 const isWorktree = props.worktreePath != null && props.worktreePath.trim().length > 0;
49 const showHarness =
50 variant !== "favicon-workspace" && props.driverKind != null && props.providerDisplayName;
51​
52 const projectLabel = props.projectTitle?.trim() || null;
53 const branchLabel = props.branch?.trim() || null;
54​
55 if (!projectLabel && !branchLabel && !props.isCurrent && !showHarness) {
56 return null;
57 }
58​
59 return (
60 <span
61 className={cn(
62 "inline-flex min-w-0 max-w-full items-center gap-1 text-xs text-muted-foreground/70",
63 props.className,
64 )}
65 >
66 {projectLabel ? (
67 <span className="inline-flex min-w-0 items-center gap-1">
68 {props.project ? (
69 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
70 ) : null}
71 <span className="min-w-0 truncate">{projectLabel}</span>
72 </span>
73 ) : null}
74​
75 {branchLabel ? (
76 <>
77 {projectLabel ? <CommandPaletteMetaDot /> : null}
78 <span className="inline-flex min-w-0 items-center gap-1">
79 <WorkspaceIcon variant={variant} isWorktree={isWorktree} />
80 <span className="min-w-0 truncate">{branchLabel}</span>
81 </span>
82 </>
83 ) : null}
84​
85 {showHarness && props.driverKind ? (
86 <>
87 {projectLabel || branchLabel ? <CommandPaletteMetaDot /> : null}
88 <ProviderInstanceIcon
89 driverKind={props.driverKind}
90 displayName={props.providerDisplayName ?? props.driverKind}
91 iconClassName="size-3 shrink-0 opacity-70"
92 />
93 </>
94 ) : null}
95​
96 {props.isCurrent ? (
97 <>
98 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
99 <span className="shrink-0">Current thread</span>
100 </>
101 ) : null}
102 </span>
103 );