feat(setting): 上传图片时按下回车快速提交图片

issue #10
pull/14/head
shikelong 5 years ago
parent 67bd890cf9
commit 647cefee3d

@ -2,9 +2,11 @@ import Cropper from 'react-easy-crop';
import type { Area } from 'react-easy-crop/types'; import type { Area } from 'react-easy-crop/types';
import _isNil from 'lodash/isNil'; import _isNil from 'lodash/isNil';
import { showToasts, t } from 'tailchat-shared'; import { showToasts, t } from 'tailchat-shared';
import React, { useRef, useState } from 'react'; import React, { useState } from 'react';
import { Button } from 'antd'; import { Button } from 'antd';
import { ModalWrapper } from '../Modal'; import { ModalWrapper } from '../Modal';
import { useGlobalKeyDown } from '@/hooks/useGlobalKeyDown';
import { isEnterHotkey } from '@/utils/hot-key';
const createImage = (url: string): Promise<HTMLImageElement> => const createImage = (url: string): Promise<HTMLImageElement> =>
new Promise((resolve, reject) => { new Promise((resolve, reject) => {
@ -105,6 +107,12 @@ export const ModalAvatarCropper: React.FC<{
const [zoom, setZoom] = useState(1); const [zoom, setZoom] = useState(1);
const [area, setArea] = useState<Area>({ width: 0, height: 0, x: 0, y: 0 }); const [area, setArea] = useState<Area>({ width: 0, height: 0, x: 0, y: 0 });
useGlobalKeyDown((e) => {
if (isEnterHotkey(e)) {
handleConfirm();
}
});
const handleConfirm = async () => { const handleConfirm = async () => {
const blobUrl = await getCroppedImg( const blobUrl = await getCroppedImg(
await createImage(props.imageUrl), await createImage(props.imageUrl),

Loading…
Cancel
Save