@devries-cameron20 / t3code Mirror · read-only
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 75 lines 2.29 KB
Raw
1 import type { ResolvedKeybindingsConfig } from "@t3tools/contracts";
2 import { useGT } from "gt-react";
3 import { PinIcon, PinOffIcon } from "lucide-react";
4 import type { KeyboardEvent } from "react";
5
6 import { resolveShortcutCommand } from "../keybindings";
7
8 import { cn } from "~/lib/utils";
9 import { Button } from "./ui/button";
10
11 /** The thread pin shortcut, which pins the highlighted row in a project list. */
12 export function isProjectPinShortcut(
13 event: KeyboardEvent,
14 keybindings: ResolvedKeybindingsConfig,
15 ): boolean {
16 return (
17 resolveShortcutCommand(event.nativeEvent, keybindings, {
18 platform: navigator.platform,
19 context: { modelPickerOpen: false, editableFocus: true },
20 }) === "thread.pin"
21 );
22 }
23
24 /**
25 * Pin toggle for a project row in a menu or list. A pinned project always shows its pin;
26 * an unpinned one shows it only on the highlighted row. Keyboard users get a shortcut
27 * from the list that hosts it, so the button stays out of the tab order.
28 */
29 export function ProjectPinButton(props: {
30 readonly name: string;
31 readonly pinned: boolean;
32 readonly onToggle: () => void;
33 readonly shortcutLabel?: string | null;
34 }) {
35 const gt = useGT();
36 const action = props.pinned
37 ? gt("Unpin {name}", { name: props.name })
38 : gt("Pin {name}", { name: props.name });
39 return (
40 <span
41 className={cn(
42 "group/pin ml-auto flex",
43 !props.pinned && "opacity-0 in-data-highlighted:opacity-100 pointer-coarse:opacity-100",
44 )}
45 >
46 <Button
47 size="icon-xs"
48 variant="ghost-muted"
49 tabIndex={-1}
50 aria-hidden="true"
51 title={
52 props.shortcutLabel
53 ? gt("{action} ({shortcut})", { action, shortcut: props.shortcutLabel })
54 : action
55 }
56 onPointerDown={(event) => event.stopPropagation()}
57 onMouseDown={(event) => event.preventDefault()}
58 onClick={(event) => {
59 event.preventDefault();
60 event.stopPropagation();
61 props.onToggle();
62 }}
63 >
64 {props.pinned ? (
65 <>
66 <PinIcon className="size-3.5 group-hover/pin:hidden" />
67 <PinOffIcon className="hidden size-3.5 group-hover/pin:block" />
68 </>
69 ) : (
70 <PinIcon className="size-3.5" />
71 )}
72 </Button>
73 </span>
74 );
75 }