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

ThreadCommandSubtitle.tsx

111 lines3.9 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 environmentLabel?: string | null;
40 branch: string | null;
41 worktreePath: string | null;
42 isCurrent: boolean;
43 driverKind?: ProviderDriverKind | null;
44 providerDisplayName?: string | null;
45 variant?: ThreadCommandSubtitleVariant;
46 className?: string;
47}) {
48 const variant = props.variant ?? THREAD_COMMAND_SUBTITLE_VARIANT;
49 const isWorktree = props.worktreePath != null && props.worktreePath.trim().length > 0;
50 const showHarness =
51 variant !== "favicon-workspace" && props.driverKind != null && props.providerDisplayName;
52​
53 const projectLabel = props.projectTitle?.trim() || null;
54 const branchLabel = props.branch?.trim() || null;
55​
56 if (!projectLabel && !branchLabel && !props.isCurrent && !showHarness) {
57 return null;
58 }
59​
60 return (
61 <span
62 className={cn(
63 "inline-flex min-w-0 max-w-full items-center gap-1 text-xs text-muted-foreground/70",
64 props.className,
65 )}
66 >
67 {projectLabel ? (
68 <span className="inline-flex min-w-0 items-center gap-1">
69 {props.project ? (
70 <ProjectFavicon project={props.project} className="size-3 shrink-0" />
71 ) : null}
72 <span className="min-w-0 truncate">{projectLabel}</span>
73 {props.environmentLabel ? (
74 <>
75 <CommandPaletteMetaDot />
76 <span className="shrink-0">{props.environmentLabel}</span>
77 </>
78 ) : null}
79 </span>
80 ) : null}
81​
82 {branchLabel ? (
83 <>
84 {projectLabel ? <CommandPaletteMetaDot /> : null}
85 <span className="inline-flex min-w-0 items-center gap-1">
86 <WorkspaceIcon variant={variant} isWorktree={isWorktree} />
87 <span className="min-w-0 truncate">{branchLabel}</span>
88 </span>
89 </>
90 ) : null}
91​
92 {showHarness && props.driverKind ? (
93 <>
94 {projectLabel || branchLabel ? <CommandPaletteMetaDot /> : null}
95 <ProviderInstanceIcon
96 driverKind={props.driverKind}
97 displayName={props.providerDisplayName ?? props.driverKind}
98 iconClassName="size-3 shrink-0 opacity-70"
99 />
100 </>
101 ) : null}
102​
103 {props.isCurrent ? (
104 <>
105 {projectLabel || branchLabel || showHarness ? <CommandPaletteMetaDot /> : null}
106 <span className="shrink-0">Current thread</span>
107 </>
108 ) : null}
109 </span>
110 );