From d7db307f8a669ed99d2fc28813ec29dcf2bd652f Mon Sep 17 00:00:00 2001 From: kangfenmao Date: Thu, 26 Sep 2024 22:45:59 +0800 Subject: [PATCH] feat: edit message --- .../src/components/Popups/TextEditPopup.tsx | 98 +++++++++++++++++++ src/renderer/src/i18n/index.ts | 1 + .../src/pages/home/Messages/Message.tsx | 9 +- .../pages/home/Messages/MessageMenubar.tsx | 19 +++- .../src/pages/home/Messages/Messages.tsx | 17 +++- 5 files changed, 137 insertions(+), 7 deletions(-) create mode 100644 src/renderer/src/components/Popups/TextEditPopup.tsx diff --git a/src/renderer/src/components/Popups/TextEditPopup.tsx b/src/renderer/src/components/Popups/TextEditPopup.tsx new file mode 100644 index 0000000000..bb83d95651 --- /dev/null +++ b/src/renderer/src/components/Popups/TextEditPopup.tsx @@ -0,0 +1,98 @@ +import { Modal, ModalProps } from 'antd' +import TextArea from 'antd/es/input/TextArea' +import { TextAreaProps } from 'antd/lib/input' +import { TextAreaRef } from 'antd/lib/input/TextArea' +import { useEffect, useRef, useState } from 'react' +import { useTranslation } from 'react-i18next' + +import { TopView } from '../TopView' + +interface ShowParams { + text: string + textareaProps?: TextAreaProps + modalProps?: ModalProps +} + +interface Props extends ShowParams { + resolve: (data: any) => void +} + +const PopupContainer: React.FC = ({ text, textareaProps, modalProps, resolve }) => { + const [open, setOpen] = useState(true) + const { t } = useTranslation() + const [textValue, setTextValue] = useState(text) + const textareaRef = useRef(null) + + const onOk = () => { + setOpen(false) + resolve(textValue) + } + + const onCancel = () => { + setOpen(false) + } + + const onClose = () => { + resolve(null) + } + + const resizeTextArea = () => { + const textArea = textareaRef.current?.resizableTextArea?.textArea + const maxHeight = innerHeight * 0.6 + if (textArea) { + textArea.style.height = 'auto' + textArea.style.height = textArea?.scrollHeight > maxHeight ? maxHeight + 'px' : `${textArea?.scrollHeight}px` + } + } + + useEffect(() => { + setTimeout(resizeTextArea, 0) + }, []) + + return ( + +