From cb6ef5f81c2fe5104067beb886e6cc367ce412b8 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Tue, 5 Mar 2024 12:28:40 +0800 Subject: [PATCH] Fix the library select and mark read/unread shortcuts --- .../components/templates/PrimaryLayout.tsx | 37 ++++++++++++++++++- .../templates/homeFeed/HomeFeedContainer.tsx | 4 +- .../keyboardShortcuts/navigationShortcuts.ts | 4 +- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/packages/web/components/templates/PrimaryLayout.tsx b/packages/web/components/templates/PrimaryLayout.tsx index ee734c9ad..d05103af8 100644 --- a/packages/web/components/templates/PrimaryLayout.tsx +++ b/packages/web/components/templates/PrimaryLayout.tsx @@ -4,13 +4,16 @@ import { ReactNode, useEffect, useState, useCallback } from 'react' import { useGetViewerQuery } from '../../lib/networking/queries/useGetViewerQuery' import { navigationCommands } from '../../lib/keyboardShortcuts/navigationShortcuts' import { useKeyboardShortcuts } from '../../lib/keyboardShortcuts/useKeyboardShortcuts' -import { useRouter } from 'next/router' +import { NextRouter, useRouter } from 'next/router' import { ConfirmationModal } from '../patterns/ConfirmationModal' import { KeyboardShortcutListModal } from './KeyboardShortcutListModal' import { setupAnalytics } from '../../lib/analytics' import { primaryCommands } from '../../lib/keyboardShortcuts/navigationShortcuts' import { logout } from '../../lib/logout' import { useApplyLocalTheme } from '../../lib/hooks/useApplyLocalTheme' +import { updateTheme } from '../../lib/themeUpdater' +import { Priority, useRegisterActions } from 'kbar' +import { ThemeId } from '../tokens/stitches.config' type PrimaryLayoutProps = { children: ReactNode @@ -42,6 +45,38 @@ export function PrimaryLayout(props: PrimaryLayoutProps): JSX.Element { }) ) + useRegisterActions( + [ + { + id: 'home', + section: 'Navigation', + name: 'Go to Home (Library) ', + shortcut: ['g h'], + keywords: 'go home', + perform: () => router?.push('/home'), + }, + { + id: 'lightTheme', + section: 'Preferences', + name: 'Change theme (light) ', + shortcut: ['v', 'l'], + keywords: 'light theme', + priority: Priority.LOW, + perform: () => updateTheme(ThemeId.Light), + }, + { + id: 'darkTheme', + section: 'Preferences', + name: 'Change theme (dark) ', + shortcut: ['v', 'd'], + keywords: 'dark theme', + priority: Priority.LOW, + perform: () => updateTheme(ThemeId.Dark), + }, + ], + [router] + ) + // Attempt to identify the user if they are logged in. useEffect(() => { setupAnalytics(viewerData?.me) diff --git a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx index ec632bf71..4defd0381 100644 --- a/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx +++ b/packages/web/components/templates/homeFeed/HomeFeedContainer.tsx @@ -635,7 +635,7 @@ export function HomeFeedContainer(): JSX.Element { createAction({ section: 'Library', name: 'Mark item as read', - shortcut: ['m', 'r'], + shortcut: ['-'], perform: () => { handleCardAction('mark-read', activeItem) }, @@ -643,7 +643,7 @@ export function HomeFeedContainer(): JSX.Element { createAction({ section: 'Library', name: 'Mark item as unread', - shortcut: ['m', 'u'], + shortcut: ['_'], perform: () => handleCardAction('mark-unread', activeItem), }), ] diff --git a/packages/web/lib/keyboardShortcuts/navigationShortcuts.ts b/packages/web/lib/keyboardShortcuts/navigationShortcuts.ts index d49b72f61..f525c5d5f 100644 --- a/packages/web/lib/keyboardShortcuts/navigationShortcuts.ts +++ b/packages/web/lib/keyboardShortcuts/navigationShortcuts.ts @@ -35,9 +35,9 @@ export function searchBarCommands( callback: () => setTimeout(() => actionHandler('focusSearchBar'), 0), }, { - shortcutKeys: ['x'], + shortcutKeys: ['c', 's'], actionDescription: 'Clear search bar', - shortcutKeyDescription: 'x', + shortcutKeyDescription: 'c then s', callback: () => actionHandler('clearSearch'), }, ]