MCPcopy Create free account
hub / github.com/pingdotgg/t3code / ProjectScriptsControl

Function ProjectScriptsControl

apps/web/src/components/ProjectScriptsControl.tsx:114–526  ·  view source on GitHub ↗
({
  scripts,
  keybindings,
  preferredScriptId = null,
  onRunScript,
  onAddScript,
  onUpdateScript,
  onDeleteScript,
}: ProjectScriptsControlProps)

Source from the content-addressed store, hash-verified

112}
113
114export default function ProjectScriptsControl({
115 scripts,
116 keybindings,
117 preferredScriptId = null,
118 onRunScript,
119 onAddScript,
120 onUpdateScript,
121 onDeleteScript,
122}: ProjectScriptsControlProps) {
123 const addScriptFormId = React.useId();
124 const [editingScriptId, setEditingScriptId] = useState<string | null>(null);
125 const [dialogOpen, setDialogOpen] = useState(false);
126 const [name, setName] = useState("");
127 const [command, setCommand] = useState("");
128 const [icon, setIcon] = useState<ProjectScriptIcon>("play");
129 const [iconPickerOpen, setIconPickerOpen] = useState(false);
130 const [runOnWorktreeCreate, setRunOnWorktreeCreate] = useState(false);
131 const [keybinding, setKeybinding] = useState("");
132 const [previewUrl, setPreviewUrl] = useState("");
133 const [autoOpenPreview, setAutoOpenPreview] = useState(false);
134 const [validationError, setValidationError] = useState<string | null>(null);
135 const [deleteConfirmOpen, setDeleteConfirmOpen] = useState(false);
136
137 const primaryScript = useMemo(() => {
138 if (preferredScriptId) {
139 const preferred = scripts.find((script) => script.id === preferredScriptId);
140 if (preferred) return preferred;
141 }
142 return primaryProjectScript(scripts);
143 }, [preferredScriptId, scripts]);
144 const isEditing = editingScriptId !== null;
145 const dropdownItemClassName =
146 "data-highlighted:bg-transparent data-highlighted:text-foreground hover:bg-accent hover:text-accent-foreground focus-visible:bg-accent focus-visible:text-accent-foreground data-highlighted:hover:bg-accent data-highlighted:hover:text-accent-foreground data-highlighted:focus-visible:bg-accent data-highlighted:focus-visible:text-accent-foreground";
147
148 const captureKeybinding = (event: KeyboardEvent<HTMLInputElement>) => {
149 if (event.key === "Tab") return;
150 event.preventDefault();
151 if (event.key === "Backspace" || event.key === "Delete") {
152 setKeybinding("");
153 return;
154 }
155 const next = keybindingFromKeyboardEvent(event, navigator.platform);
156 if (!next) return;
157 setKeybinding(next);
158 };
159
160 const submitAddScript = async (event: FormEvent) => {
161 event.preventDefault();
162 const trimmedName = name.trim();
163 const trimmedCommand = command.trim();
164 if (trimmedName.length === 0) {
165 setValidationError("Name is required.");
166 return;
167 }
168 if (trimmedCommand.length === 0) {
169 setValidationError("Command is required.");
170 return;
171 }

Callers

nothing calls this directly

Calls 8

primaryProjectScriptFunction · 0.90
shortcutLabelForCommandFunction · 0.90
commandForProjectScriptFunction · 0.90
useStateFunction · 0.85
useMemoFunction · 0.85
useCallbackFunction · 0.85
openEditDialogFunction · 0.85
preventDefaultMethod · 0.80

Tested by

no test coverage detected