feat: add shortcut key support for posting
This commit is contained in:
@@ -38,13 +38,10 @@ export default function PostContent({
|
||||
const [mentions, setMentions] = useState<string[]>([])
|
||||
const canPost = !!text && !posting && !uploadingFiles
|
||||
|
||||
const post = async (e: React.MouseEvent) => {
|
||||
e.stopPropagation()
|
||||
const post = async (e?: React.MouseEvent) => {
|
||||
e?.stopPropagation()
|
||||
checkLogin(async () => {
|
||||
if (!canPost) {
|
||||
close()
|
||||
return
|
||||
}
|
||||
if (!canPost) return
|
||||
|
||||
setPosting(true)
|
||||
try {
|
||||
@@ -105,6 +102,7 @@ export default function PostContent({
|
||||
setText={setText}
|
||||
defaultContent={defaultContent}
|
||||
parentEvent={parentEvent}
|
||||
onSubmit={() => post()}
|
||||
/>
|
||||
<SendOnlyToSwitch
|
||||
parentEvent={parentEvent}
|
||||
|
||||
@@ -11,11 +11,11 @@ import { EditorContent, useEditor } from '@tiptap/react'
|
||||
import { Event } from 'nostr-tools'
|
||||
import { Dispatch, forwardRef, SetStateAction, useImperativeHandle } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { usePostEditor } from '../PostEditorProvider'
|
||||
import CustomMention from './CustomMention'
|
||||
import { FileHandler } from './FileHandler'
|
||||
import Preview from './Preview'
|
||||
import suggestion from './suggestion'
|
||||
import { usePostEditor } from '../PostEditorProvider'
|
||||
|
||||
export type TPostTextareaHandle = {
|
||||
appendText: (text: string) => void
|
||||
@@ -28,8 +28,9 @@ const PostTextarea = forwardRef<
|
||||
setText: Dispatch<SetStateAction<string>>
|
||||
defaultContent?: string
|
||||
parentEvent?: Event
|
||||
onSubmit?: () => void
|
||||
}
|
||||
>(({ text = '', setText, defaultContent, parentEvent }, ref) => {
|
||||
>(({ text = '', setText, defaultContent, parentEvent, onSubmit }, ref) => {
|
||||
const { t } = useTranslation()
|
||||
const { setUploadingFiles } = usePostEditor()
|
||||
const editor = useEditor({
|
||||
@@ -54,6 +55,15 @@ const PostTextarea = forwardRef<
|
||||
attributes: {
|
||||
class:
|
||||
'border rounded-lg p-3 min-h-52 focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring'
|
||||
},
|
||||
handleKeyDown: (_view, event) => {
|
||||
// Handle Ctrl+Enter or Cmd+Enter for submit
|
||||
if ((event.ctrlKey || event.metaKey) && event.key === 'Enter') {
|
||||
event.preventDefault()
|
||||
onSubmit?.()
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
},
|
||||
content: postContentCache.getPostCache({ defaultContent, parentEvent }),
|
||||
|
||||
Reference in New Issue
Block a user