Add keyboard shortcuts: new, escape, and hard break (#552)

* Add keyboard shortcuts: new, escape, and hard break

* Add preferences modal

* Remove code accidentally re-added due to rebase

* Fix incorrect copy and lint

* Put stuff back so diffs are clearer

* Re-add invite codes to settings

* Address comments

* Tune the copy

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>
This commit is contained in:
Ollie H 2023-05-02 21:00:18 -07:00 committed by GitHub
parent af905947bc
commit 95f8360d19
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 78 additions and 26 deletions

View file

@ -88,6 +88,30 @@ export const ComposePost = observer(function ComposePost({
autocompleteView.setup()
}, [autocompleteView])
const onEscape = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Escape') {
store.shell.openModal({
name: 'confirm',
title: 'Cancel draft',
onPressConfirm: onClose,
onPressCancel: () => {
store.shell.closeModal()
},
message: "Are you sure you'd like to cancel this draft?",
})
}
},
[store.shell, onClose],
)
useEffect(() => {
if (isDesktopWeb) {
window.addEventListener('keydown', onEscape)
return () => window.removeEventListener('keydown', onEscape)
}
}, [onEscape])
const onPressAddLinkCard = useCallback(
(uri: string) => {
setExtLink({uri, isLoading: true})

View file

@ -4,6 +4,7 @@ import {RichText} from '@atproto/api'
import {useEditor, EditorContent, JSONContent} from '@tiptap/react'
import {Document} from '@tiptap/extension-document'
import History from '@tiptap/extension-history'
import Hardbreak from '@tiptap/extension-hard-break'
import {Link} from '@tiptap/extension-link'
import {Mention} from '@tiptap/extension-mention'
import {Paragraph} from '@tiptap/extension-paragraph'
@ -72,6 +73,7 @@ export const TextInput = React.forwardRef(
}),
Text,
History,
Hardbreak,
],
editorProps: {
attributes: {