MCPcopy Create free account
hub / github.com/Microck/opencode-studio / CommandsPage

Function CommandsPage

client-next/src/app/commands/page.tsx:27–286  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

25}
26
27export default function CommandsPage() {
28 const [commands, setCommands] = useState<CommandEntry[]>([]);
29 const [loading, setLoading] = useState(true);
30 const [addOpen, setAddOpen] = useState(false);
31 const [newName, setNewName] = useState("");
32 const [newTemplate, setNewTemplate] = useState("");
33 const [editOpen, setEditOpen] = useState(false);
34 const [editingCmd, setEditingCmd] = useState<{ originalName: string, name: string, template: string } | null>(null);
35
36 const fetchCommands = async () => {
37 try {
38 setLoading(true);
39 const data = await getCommands();
40 const entries = Object.entries(data).map(([name, value]) => ({
41 name,
42 template: value.template,
43 }));
44 setCommands(entries);
45 } catch (err: any) {
46 toast.error("Failed to load commands");
47 console.error(err);
48 } finally {
49 setLoading(false);
50 }
51 };
52
53 useEffect(() => {
54 fetchCommands();
55 }, []);
56
57 const handleAdd = async () => {
58 if (!newName.trim()) {
59 toast.error("Command name is required");
60 return;
61 }
62 if (!newTemplate.trim()) {
63 toast.error("Template is required");
64 return;
65 }
66 if (commands.some(c => c.name === newName.trim())) {
67 toast.error("Command already exists");
68 return;
69 }
70
71 try {
72 await saveCommand(newName.trim(), newTemplate);
73 toast.success(`Command "${newName}" created`);
74 setNewName("");
75 setNewTemplate("");
76 setAddOpen(false);
77 fetchCommands();
78 } catch {
79 toast.error("Failed to create command");
80 }
81 };
82
83
84

Callers

nothing calls this directly

Calls 3

fetchCommandsFunction · 0.85
openEditFunction · 0.85
handleDeleteFunction · 0.70

Tested by

no test coverage detected