feat(chat): upload image now support enter and esc key down event

pull/15/head
shikelong 3 years ago
parent 5d65912b4d
commit 0fec73f2a7

@ -13,6 +13,9 @@ export function uploadMessageImage(image: File): Promise<string> {
const key = openModal(
<ImageUploadPreviewer
imageUrl={imageLocalUrl}
onCancel={() => {
closeModal(key);
}}
onConfirm={async () => {
const fileInfo = await uploadFile(image);
const imageRemoteUrl = fileInfo.url;

@ -2,10 +2,13 @@ import { ModalWrapper } from '@/plugin/common';
import { Button } from '@/plugin/component';
import React from 'react';
import { t, useAsyncFn } from 'tailchat-shared';
import { useGlobalKeyDown } from '../../hooks/useGlobalKeyDown';
import { isEnterHotkey, isEscHotkey } from '../../utils/hot-key';
interface ImageUploadPreviewerProps {
imageUrl: string;
onConfirm: () => void;
onCancel: () => void;
}
export const ImageUploadPreviewer: React.FC<ImageUploadPreviewerProps> =
React.memo((props) => {
@ -17,6 +20,14 @@ export const ImageUploadPreviewer: React.FC<ImageUploadPreviewerProps> =
}
}, [props.onConfirm]);
useGlobalKeyDown((e) => {
if (isEnterHotkey(e)) {
handleConfirm();
} else if (isEscHotkey(e)) {
props.onCancel();
}
});
return (
<ModalWrapper style={{ maxHeight: '60vh', maxWidth: '60vw' }}>
<div className="flex">

Loading…
Cancel
Save