Fix the library select and mark read/unread shortcuts

This commit is contained in:
Jackson Harper
2024-03-05 12:28:40 +08:00
parent 9b64d47618
commit cb6ef5f81c
3 changed files with 40 additions and 5 deletions

View File

@ -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)

View File

@ -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),
}),
]

View File

@ -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'),
},
]