MCPcopy Index your code
hub / github.com/winfunc/opcode / SlashCommandPicker

Function SlashCommandPicker

src/components/SlashCommandPicker.tsx:75–565  ·  view source on GitHub ↗
({
  projectPath,
  onSelect,
  onClose,
  initialQuery = "",
  className,
})

Source from the content-addressed store, hash-verified

73 * />
74 */
75export const SlashCommandPicker: React.FC<SlashCommandPickerProps> = ({
76 projectPath,
77 onSelect,
78 onClose,
79 initialQuery = "",
80 className,
81}) => {
82 const [commands, setCommands] = useState<SlashCommand[]>([]);
83 const [filteredCommands, setFilteredCommands] = useState<SlashCommand[]>([]);
84 const [isLoading, setIsLoading] = useState(true);
85 const [error, setError] = useState<string | null>(null);
86 const [selectedIndex, setSelectedIndex] = useState(0);
87 const [searchQuery, setSearchQuery] = useState(initialQuery);
88 const [activeTab, setActiveTab] = useState<string>("custom");
89
90 const commandListRef = useRef<HTMLDivElement>(null);
91
92 // Analytics tracking
93 const trackEvent = useTrackEvent();
94 const slashCommandFeatureTracking = useFeatureAdoptionTracking('slash_commands');
95
96 // Load commands on mount or when project path changes
97 useEffect(() => {
98 loadCommands();
99 }, [projectPath]);
100
101 // Filter commands based on search query and active tab
102 useEffect(() => {
103 if (!commands.length) {
104 setFilteredCommands([]);
105 return;
106 }
107
108 const query = searchQuery.toLowerCase();
109 let filteredByTab: SlashCommand[];
110
111 // Filter by active tab
112 if (activeTab === "default") {
113 // Show default/built-in commands
114 filteredByTab = commands.filter(cmd => cmd.scope === "default");
115 } else {
116 // Show all custom commands (both user and project)
117 filteredByTab = commands.filter(cmd => cmd.scope !== "default");
118 }
119
120 // Then filter by search query
121 let filtered: SlashCommand[];
122 if (!query) {
123 filtered = filteredByTab;
124 } else {
125 filtered = filteredByTab.filter(cmd => {
126 // Match against command name
127 if (cmd.name.toLowerCase().includes(query)) return true;
128
129 // Match against full command
130 if (cmd.full_command.toLowerCase().includes(query)) return true;
131
132 // Match against namespace

Callers

nothing calls this directly

Calls 6

useTrackEventFunction · 0.90
cnFunction · 0.90
handleCommandClickFunction · 0.85
loadCommandsFunction · 0.70
getCommandIconFunction · 0.70

Tested by

no test coverage detected