diff --git a/frontend/components/Layout/Layout.js b/frontend/components/Layout/Layout.js index 96e7ccac..001d4d96 100644 --- a/frontend/components/Layout/Layout.js +++ b/frontend/components/Layout/Layout.js @@ -9,6 +9,7 @@ import _ from 'lodash'; import keydown from 'react-keydown'; import Flex from 'components/Flex'; import { color, layout } from 'styles/constants'; +import { documentEditUrl, homeUrl, searchUrl } from 'utils/routeHelpers'; import { DropdownMenu, DropdownMenuItem } from 'components/DropdownMenu'; import { LoadingIndicatorBar } from 'components/LoadingIndicator'; @@ -51,15 +52,21 @@ type Props = { @observable modal = null; @keydown(['/', 't']) - search() { - if (this.props.auth.authenticated) - _.defer(() => this.props.history.push('/search')); + goToSearch(ev) { + ev.preventDefault(); + ev.stopPropagation(); + this.props.history.push(searchUrl()); } @keydown('d') - dashboard() { - if (this.props.auth.authenticated) - _.defer(() => this.props.history.push('/')); + goToDashboard() { + this.props.history.push(homeUrl()); + } + + @keydown('e') + goToEdit() { + if (!this.props.ui.activeDocument) return; + this.props.history.push(documentEditUrl(this.props.ui.activeDocument)); } handleLogout = () => { @@ -67,9 +74,9 @@ type Props = { }; @keydown('shift+/') - handleOpenKeyboardShortcuts = () => { + handleOpenKeyboardShortcuts() { this.modal = 'keyboard-shortcuts'; - }; + } handleCreateCollection = () => { this.modal = 'create-collection'; diff --git a/frontend/static/flatpages/keyboard.md b/frontend/static/flatpages/keyboard.md index 4855c385..8d0eeeb0 100644 --- a/frontend/static/flatpages/keyboard.md +++ b/frontend/static/flatpages/keyboard.md @@ -1,5 +1,5 @@ - `Cmd+Enter` - Save and exit document editor -- `Cmd+s` - Save document and continue editing +- `Cmd+S` - Save document and continue editing - `Cmd+Esc` - Cancel edit - `/` or `t` - Jump to search - `d` - Jump to dashboard diff --git a/frontend/utils/routeHelpers.js b/frontend/utils/routeHelpers.js index 45615041..8c43c22d 100644 --- a/frontend/utils/routeHelpers.js +++ b/frontend/utils/routeHelpers.js @@ -1,4 +1,5 @@ // @flow +import Document from 'models/Document'; export function homeUrl(): string { return '/dashboard'; @@ -12,7 +13,15 @@ export function newCollectionUrl(): string { return '/collections/new'; } -export function searchUrl(query: string): string { +export function documentUrl(doc: Document): string { + return doc.url; +} + +export function documentEditUrl(doc: Document): string { + return `${doc.url}/edit`; +} + +export function searchUrl(query?: string): string { if (query) return `/search/${query}`; return `/search`; }