MCPcopy Create free account
hub / github.com/winfunc/opcode / applyTemplate

Function applyTemplate

src/components/HooksEditor.tsx:405–439  ·  view source on GitHub ↗
(template: HookTemplate)

Source from the content-addressed store, hash-verified

403 };
404
405 const applyTemplate = (template: HookTemplate) => {
406 if (matcherEvents.includes(template.event as any)) {
407 // For events with matchers
408 const newMatcher: EditableHookMatcher = {
409 id: HooksManager.generateId(),
410 matcher: template.matcher,
411 hooks: template.commands.map(cmd => ({
412 id: HooksManager.generateId(),
413 type: 'command' as const,
414 command: cmd
415 })),
416 expanded: true
417 };
418
419 setEditableHooks(prev => ({
420 ...prev,
421 [template.event]: [...(prev[template.event as 'PreToolUse' | 'PostToolUse'] as EditableHookMatcher[]), newMatcher]
422 }));
423 } else {
424 // For direct events
425 const newCommands: EditableHookCommand[] = template.commands.map(cmd => ({
426 id: HooksManager.generateId(),
427 type: 'command' as const,
428 command: cmd
429 }));
430
431 setEditableHooks(prev => ({
432 ...prev,
433 [template.event]: [...(prev[template.event as 'Notification' | 'Stop' | 'SubagentStop'] as EditableHookCommand[]), ...newCommands]
434 }));
435 }
436
437 setSelectedEvent(template.event);
438 setShowTemplateDialog(false);
439 };
440
441 const validateHooks = async () => {
442 if (!hooks) {

Callers 1

HooksEditorFunction · 0.85

Calls 1

generateIdMethod · 0.80

Tested by

no test coverage detected