refs #4653 Add a shortcut key to post
This commit is contained in:
parent
a845f4b773
commit
49f0cd2937
|
@ -12,7 +12,7 @@ import {
|
||||||
Textarea,
|
Textarea,
|
||||||
ToggleSwitch
|
ToggleSwitch
|
||||||
} from 'flowbite-react'
|
} 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 { FormattedMessage, useIntl } from 'react-intl'
|
||||||
import { FaEnvelope, FaFaceLaughBeam, FaGlobe, FaListCheck, FaLock, FaLockOpen, FaPaperPlane, FaPaperclip, FaXmark } from 'react-icons/fa6'
|
import { FaEnvelope, FaFaceLaughBeam, FaGlobe, FaListCheck, FaLock, FaLockOpen, FaPaperPlane, FaPaperclip, FaXmark } from 'react-icons/fa6'
|
||||||
import { Entity, MegalodonInterface } from 'megalodon'
|
import { Entity, MegalodonInterface } from 'megalodon'
|
||||||
|
@ -54,6 +54,7 @@ export default function Compose(props: Props) {
|
||||||
const { formatMessage } = useIntl()
|
const { formatMessage } = useIntl()
|
||||||
const uploaderRef = useRef(null)
|
const uploaderRef = useRef(null)
|
||||||
const showToast = useToast()
|
const showToast = useToast()
|
||||||
|
const textareaRef = useRef<HTMLTextAreaElement>(null)
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (!cw) {
|
if (!cw) {
|
||||||
|
@ -116,6 +117,23 @@ export default function Compose(props: Props) {
|
||||||
setPoll(null)
|
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 = () => {
|
const selectFile = () => {
|
||||||
if (uploaderRef.current) {
|
if (uploaderRef.current) {
|
||||||
uploaderRef.current.click()
|
uploaderRef.current.click()
|
||||||
|
@ -188,6 +206,7 @@ export default function Compose(props: Props) {
|
||||||
rows={3}
|
rows={3}
|
||||||
value={body}
|
value={body}
|
||||||
onChange={ev => setBody(ev.target.value)}
|
onChange={ev => setBody(ev.target.value)}
|
||||||
|
ref={textareaRef}
|
||||||
/>
|
/>
|
||||||
<Flowbite theme={{ theme: customTheme }}>
|
<Flowbite theme={{ theme: customTheme }}>
|
||||||
<Dropdown
|
<Dropdown
|
||||||
|
|
Loading…
Reference in New Issue