mirror of
https://github.com/standardnotes/app
synced 2026-07-14 00:03:20 -04:00
* wip: command palette * use code instead of key * show recent items above commands * refactor * fix command * add placeholder * Tab/Shift-Tab to switch tabs * Fix test * Add menu item to general account menu * if shortcut_id is available, use that as the id * make toggle fn more stable * small naming changes * fix name * Close open modals and popovers when opening command palette * use stable ids + make sure selectedNotesCount only changes when the count actually changes * display all commands, even ones in recents list
37 lines
953 B
TypeScript
37 lines
953 B
TypeScript
import { ReactNode, createContext, useContext, memo } from 'react'
|
|
|
|
import { observer } from 'mobx-react-lite'
|
|
import { KeyboardService } from '@standardnotes/ui-services'
|
|
|
|
const KeyboardServiceContext = createContext<KeyboardService | undefined>(undefined)
|
|
|
|
export const useKeyboardService = () => {
|
|
const value = useContext(KeyboardServiceContext)
|
|
|
|
if (!value) {
|
|
throw new Error('Component must be a child of <KeyboardServiceProvider />')
|
|
}
|
|
|
|
return value
|
|
}
|
|
|
|
type ChildrenProps = {
|
|
children: ReactNode
|
|
}
|
|
|
|
type ProviderProps = {
|
|
service: KeyboardService
|
|
} & ChildrenProps
|
|
|
|
const MemoizedChildren = memo(({ children }: ChildrenProps) => <>{children}</>)
|
|
|
|
const KeyboardServiceProvider = ({ service, children }: ProviderProps) => {
|
|
return (
|
|
<KeyboardServiceContext.Provider value={service}>
|
|
<MemoizedChildren children={children} />
|
|
</KeyboardServiceContext.Provider>
|
|
)
|
|
}
|
|
|
|
export default observer(KeyboardServiceProvider)
|