@@ -11,11 +11,13 @@ import {
1111 ViewVerticalIcon ,
1212} from "@radix-ui/react-icons" ;
1313import { Flex , Text } from "@radix-ui/themes" ;
14+ import { track } from "@renderer/lib/analytics" ;
1415import { useNavigationStore } from "@stores/navigationStore" ;
1516import { useRegisteredFoldersStore } from "@stores/registeredFoldersStore" ;
1617import { useThemeStore } from "@stores/themeStore" ;
1718import { useCallback , useEffect , useRef } from "react" ;
1819import { useHotkeys } from "react-hotkeys-hook" ;
20+ import { ANALYTICS_EVENTS , type CommandMenuAction } from "@/types/analytics" ;
1921
2022interface CommandMenuProps {
2123 open : boolean ;
@@ -32,15 +34,31 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
3234
3335 const close = useCallback ( ( ) => onOpenChange ( false ) , [ onOpenChange ] ) ;
3436
37+ const trackAction = useCallback ( ( action : CommandMenuAction ) => {
38+ track ( ANALYTICS_EVENTS . COMMAND_MENU_ACTION , { action_type : action } ) ;
39+ } , [ ] ) ;
40+
3541 const runAndClose = useCallback (
36- < T extends unknown [ ] > ( fn : ( ...args : T ) => void ) =>
42+ < T extends unknown [ ] > (
43+ fn : ( ...args : T ) => void ,
44+ action ?: CommandMenuAction ,
45+ ) =>
3746 ( ...args : T ) => {
47+ if ( action ) {
48+ trackAction ( action ) ;
49+ }
3850 fn ( ...args ) ;
3951 close ( ) ;
4052 } ,
41- [ close ] ,
53+ [ close , trackAction ] ,
4254 ) ;
4355
56+ useEffect ( ( ) => {
57+ if ( open ) {
58+ track ( ANALYTICS_EVENTS . COMMAND_MENU_OPENED ) ;
59+ }
60+ } , [ open ] ) ;
61+
4462 useHotkeys ( "escape" , close , {
4563 enabled : open ,
4664 enableOnContentEditable : true ,
@@ -107,14 +125,14 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
107125 < Command . Group heading = "Navigation" >
108126 < Command . Item
109127 value = "Home"
110- onSelect = { runAndClose ( navigateToTaskInput ) }
128+ onSelect = { runAndClose ( navigateToTaskInput , "home" ) }
111129 >
112130 < HomeIcon className = "mr-3 h-3 w-3 text-gray-11" />
113131 < Text size = "1" > Home</ Text >
114132 </ Command . Item >
115133 < Command . Item
116134 value = "Settings"
117- onSelect = { runAndClose ( navigateToSettings ) }
135+ onSelect = { runAndClose ( navigateToSettings , "settings" ) }
118136 >
119137 < GearIcon className = "mr-3 h-3 w-3 text-gray-11" />
120138 < Text size = "1" > Settings</ Text >
@@ -124,7 +142,7 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
124142 < Command . Group heading = "Actions" >
125143 < Command . Item
126144 value = "Toggle theme dark light mode"
127- onSelect = { runAndClose ( toggleDarkMode ) }
145+ onSelect = { runAndClose ( toggleDarkMode , "toggle-theme" ) }
128146 >
129147 { isDarkMode ? (
130148 < SunIcon className = "mr-3 h-3 w-3 text-gray-11" />
@@ -135,21 +153,24 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
135153 </ Command . Item >
136154 < Command . Item
137155 value = "Toggle left sidebar"
138- onSelect = { runAndClose ( toggleLeftSidebar ) }
156+ onSelect = { runAndClose ( toggleLeftSidebar , "toggle-left-sidebar" ) }
139157 >
140158 < ViewVerticalIcon className = "mr-3 h-3 w-3 text-gray-11" />
141159 < Text size = "1" > Toggle left sidebar</ Text >
142160 </ Command . Item >
143161 < Command . Item
144162 value = "Toggle right sidebar"
145- onSelect = { runAndClose ( toggleRightSidebar ) }
163+ onSelect = { runAndClose (
164+ toggleRightSidebar ,
165+ "toggle-right-sidebar" ,
166+ ) }
146167 >
147168 < ViewVerticalIcon className = "mr-3 h-3 w-3 rotate-180 text-gray-11" />
148169 < Text size = "1" > Toggle right sidebar</ Text >
149170 </ Command . Item >
150171 < Command . Item
151172 value = "Create new task"
152- onSelect = { runAndClose ( navigateToTaskInput ) }
173+ onSelect = { runAndClose ( navigateToTaskInput , "new-task" ) }
153174 >
154175 < FileTextIcon className = "mr-3 h-3 w-3 text-gray-11" />
155176 < Text size = "1" > New task</ Text >
@@ -162,7 +183,10 @@ export function CommandMenu({ open, onOpenChange }: CommandMenuProps) {
162183 < Command . Item
163184 key = { folder . id }
164185 value = { `New task in ${ folder . name } folder ${ folder . path } ` }
165- onSelect = { runAndClose ( ( ) => navigateToTaskInput ( folder . id ) ) }
186+ onSelect = { runAndClose (
187+ ( ) => navigateToTaskInput ( folder . id ) ,
188+ "new-task" ,
189+ ) }
166190 >
167191 < FileTextIcon className = "mr-3 h-3 w-3 text-gray-11" />
168192 < Text size = "1" >
0 commit comments