-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(#28): add invoke request shortcut in empty response view
- Loading branch information
Showing
4 changed files
with
104 additions
and
50 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
export * from './collections'; | ||
export * from './protocols'; | ||
export * from './use-shortcuts'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import React from 'react'; | ||
|
||
import { AppContext } from '@context'; | ||
|
||
export enum ShortcutsGroup { | ||
WELCOME = 'welcome', | ||
RESPONSE = 'response', | ||
} | ||
|
||
const shortcuts = [ | ||
{ | ||
key: { | ||
darwin: '⌘+K', | ||
other: 'Ctrl+K', | ||
}, | ||
description: 'Open command bar', | ||
groups: [ShortcutsGroup.WELCOME], | ||
}, | ||
{ | ||
key: { | ||
darwin: '⌘+Shift+C', | ||
other: 'Ctrl+Shift+C', | ||
}, | ||
description: 'Create new collection', | ||
groups: [ShortcutsGroup.WELCOME], | ||
}, | ||
{ | ||
key: { | ||
darwin: '⌘+Shift+S', | ||
other: 'Ctrl+Shift+S', | ||
}, | ||
description: 'Synchronize collections', | ||
groups: [ShortcutsGroup.WELCOME], | ||
}, | ||
{ | ||
key: { | ||
darwin: '⌘+T', | ||
other: 'Ctrl+T', | ||
}, | ||
description: 'New gRPC tab', | ||
groups: [ShortcutsGroup.WELCOME], | ||
}, | ||
{ | ||
key: { | ||
darwin: '⌘+Enter', | ||
other: 'Ctrl+Enter', | ||
}, | ||
description: 'Invoke request', | ||
groups: [ShortcutsGroup.RESPONSE], | ||
}, | ||
]; | ||
|
||
export function useShortcuts() { | ||
const context = React.useContext(AppContext); | ||
|
||
const shortcutsMemoized = React.useMemo( | ||
() => | ||
shortcuts.map((shortcut) => ({ | ||
key: context?.platform.os === 'darwin' ? shortcut.key.darwin : shortcut.key.other, | ||
description: shortcut.description, | ||
groups: shortcut.groups, | ||
})), | ||
[context?.platform.os] | ||
); | ||
|
||
function getShortcuts(group: ShortcutsGroup) { | ||
return shortcutsMemoized.filter((shortcut) => shortcut.groups.includes(group)); | ||
} | ||
|
||
return { getShortcuts }; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters