()
| 38 | * Used by both the global shortcuts component and UI buttons to avoid duplication. |
| 39 | */ |
| 40 | export function useShortcutActions(): { shortcuts: ShortcutConfigs } { |
| 41 | const navigate = useNavigate(); |
| 42 | const location = useLocation(); |
| 43 | |
| 44 | const { |
| 45 | auth, |
| 46 | fetchNotifications, |
| 47 | isLoggedIn, |
| 48 | status, |
| 49 | settings, |
| 50 | updateSetting, |
| 51 | } = useAppContext(); |
| 52 | |
| 53 | const isOnFiltersRoute = location.pathname.startsWith('/filters'); |
| 54 | const isOnSettingsRoute = location.pathname.startsWith('/settings'); |
| 55 | const isLoading = status === 'loading'; |
| 56 | |
| 57 | const primaryAccountHostname = getPrimaryAccountHostname(auth); |
| 58 | |
| 59 | const shortcuts: ShortcutConfigs = useMemo(() => { |
| 60 | return { |
| 61 | home: { |
| 62 | key: 'h', |
| 63 | isAllowed: true, |
| 64 | action: () => navigate('/', { replace: true }), |
| 65 | }, |
| 66 | myNotifications: { |
| 67 | key: 'n', |
| 68 | isAllowed: isLoggedIn, |
| 69 | action: () => openGitHubNotifications(primaryAccountHostname), |
| 70 | }, |
| 71 | focusedMode: { |
| 72 | key: 'w', |
| 73 | isAllowed: isLoggedIn && !isLoading, |
| 74 | action: () => updateSetting('participating', !settings.participating), |
| 75 | }, |
| 76 | filters: { |
| 77 | key: 'f', |
| 78 | isAllowed: isLoggedIn, |
| 79 | action: () => { |
| 80 | if (isOnFiltersRoute) { |
| 81 | navigate('/', { replace: true }); |
| 82 | } else { |
| 83 | navigate('/filters'); |
| 84 | } |
| 85 | }, |
| 86 | }, |
| 87 | myIssues: { |
| 88 | key: 'i', |
| 89 | isAllowed: isLoggedIn, |
| 90 | action: () => openGitHubIssues(primaryAccountHostname), |
| 91 | }, |
| 92 | myPullRequests: { |
| 93 | key: 'p', |
| 94 | isAllowed: isLoggedIn, |
| 95 | action: () => openGitHubPulls(primaryAccountHostname), |
| 96 | }, |
| 97 | refresh: { |
no test coverage detected