paste an image
This commit is contained in:
parent
dea18a9a9c
commit
71baabab46
@ -3,7 +3,7 @@ const electronConsole = electronRemote.getGlobal('console') as Console;
|
||||
import Logger from '../../../../logger/logger';
|
||||
const LOG = Logger.create(__filename, electronConsole);
|
||||
|
||||
import React, { FC, FormEvent, KeyboardEvent, RefObject, useCallback, useMemo, useRef, useState } from 'react';
|
||||
import React, { ClipboardEvent, FC, FormEvent, KeyboardEvent, RefObject, useCallback, useMemo, useRef, useState } from 'react';
|
||||
import { Channel } from '../../data-types';
|
||||
import CombinedGuild from '../../guild-combined';
|
||||
import BaseElements from '../require/base-elements';
|
||||
@ -54,7 +54,9 @@ export interface SendMessageProps {
|
||||
const SendMessage: FC<SendMessageProps> = (props: SendMessageProps) => {
|
||||
const { guild, channel } = props;
|
||||
|
||||
const isMounted = ReactHelper.useIsMountedRef();
|
||||
const contentEditableRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
const [ text, setText ] = useState<string>('');
|
||||
const [ enabled, setEnabled ] = useState<boolean>(true);
|
||||
|
||||
@ -96,6 +98,22 @@ const SendMessage: FC<SendMessageProps> = (props: SendMessageProps) => {
|
||||
}
|
||||
}, [ sendCallable ]);
|
||||
|
||||
const onPaste = useCallback((e: ClipboardEvent<HTMLDivElement>) => {
|
||||
for (const item of e.clipboardData.items) {
|
||||
if (item.kind === 'file') {
|
||||
e.preventDefault();
|
||||
(async () => {
|
||||
const file = item.getAsFile();
|
||||
if (!file) return;
|
||||
const buff = Buffer.from(await file.arrayBuffer());
|
||||
if (!isMounted) return;
|
||||
setAttachmentName(file.name);
|
||||
setAttachmentBuff(buff);
|
||||
})();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}, []);
|
||||
|
||||
const removeAttachment = useCallback(() => {
|
||||
setAttachmentBuff(null);
|
||||
@ -135,6 +153,7 @@ const SendMessage: FC<SendMessageProps> = (props: SendMessageProps) => {
|
||||
className={textInputClassName} contentEditable={contentEditableType}
|
||||
data-placeholder={`Message #${channel.name}`}
|
||||
onInput={onTextInput} onKeyDown={onTextKeyDown}
|
||||
onPaste={onPaste}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
Loading…
Reference in New Issue
Block a user