refs #4653 Add a shortcut key to post

This commit is contained in:
AkiraFukushima 2023-12-16 00:48:49 +09:00
parent a845f4b773
commit 49f0cd2937
No known key found for this signature in database
GPG Key ID: B6E51BAC4DE1A957
1 changed files with 20 additions and 1 deletions

View File

@ -12,7 +12,7 @@ import {
Textarea,
ToggleSwitch
} from 'flowbite-react'
import { ChangeEvent, Dispatch, SetStateAction, useEffect, useRef, useState } from 'react'
import { ChangeEvent, Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'
import { FormattedMessage, useIntl } from 'react-intl'
import { FaEnvelope, FaFaceLaughBeam, FaGlobe, FaListCheck, FaLock, FaLockOpen, FaPaperPlane, FaPaperclip, FaXmark } from 'react-icons/fa6'
import { Entity, MegalodonInterface } from 'megalodon'
@ -54,6 +54,7 @@ export default function Compose(props: Props) {
const { formatMessage } = useIntl()
const uploaderRef = useRef(null)
const showToast = useToast()
const textareaRef = useRef<HTMLTextAreaElement>(null)
useEffect(() => {
if (!cw) {
@ -116,6 +117,23 @@ export default function Compose(props: Props) {
setPoll(null)
}
const handleKeyPress = useCallback(
(event: KeyboardEvent) => {
if (event.ctrlKey === true && event.key === 'Enter') {
post()
}
},
[post]
)
useEffect(() => {
textareaRef.current?.addEventListener('keydown', handleKeyPress)
return () => {
textareaRef.current?.removeEventListener('keydown', handleKeyPress)
}
}, [handleKeyPress])
const selectFile = () => {
if (uploaderRef.current) {
uploaderRef.current.click()
@ -188,6 +206,7 @@ export default function Compose(props: Props) {
rows={3}
value={body}
onChange={ev => setBody(ev.target.value)}
ref={textareaRef}
/>
<Flowbite theme={{ theme: customTheme }}>
<Dropdown