From 42879ed09d34228f8cf90c783c338c3312f7cc6e Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Thu, 7 Nov 2024 10:24:30 +0800 Subject: [PATCH 1/2] =?UTF-8?q?perf:=20=E5=88=A0=E9=99=A4=E8=B0=83?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81=EF=BC=8C=E5=90=88=E5=B9=B6=20onChan?= =?UTF-8?q?ge=20=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/LexicalEditor/Index.jsx | 25 +++---------------------- 1 file changed, 3 insertions(+), 22 deletions(-) diff --git a/src/components/LexicalEditor/Index.jsx b/src/components/LexicalEditor/Index.jsx index cc0a69b..b0cfa13 100644 --- a/src/components/LexicalEditor/Index.jsx +++ b/src/components/LexicalEditor/Index.jsx @@ -87,38 +87,29 @@ function LexicalDefaultValuePlugin({ value = "" }= {}) { const nodes = $generateNodesFromDOM(editor, dom); if (clear) { root.clear(); - // $getRoot().clear(); - // $getRoot().select(); } - // const p = $createParagraphNode(); - // const _p = nodes.filter(n => n.__size !== 0).forEach((n) => { const paragraphNode = $createParagraphNode(); paragraphNode.append(n); - // p.append(paragraphNode); root.append(paragraphNode); }); - - // root.append(...nodes.filter(n => n)); }; - // 默认值设置只用初始化一次; - // 空值不更新 HTML; useEffect(() => { if (editor && !isEmpty(value)) { editor.update(() => { updateHTML(editor, value, true); }); } - }, [value]); + }, [editor, value]); return null; } function MyOnChangePlugin({ ignoreHistoryMergeTagChange = true, ignoreSelectionChange = true, onChange }) { const [editor] = useLexicalComposerContext(); useEffect(() => { - if (onChange) { + if (typeof onChange === 'function') { return editor.registerUpdateListener(({editorState, dirtyElements, dirtyLeaves, prevEditorState, tags}) => { if ( @@ -130,21 +121,11 @@ function MyOnChangePlugin({ ignoreHistoryMergeTagChange = true, ignoreSelectionC ) { return; } - // const editorStateJSON = editorState.toJSON(); - let html; - let textContent; editorState.read(() => { const root = $getRoot(); const textContent = root.getTextContent(); - // console.log('textContent', textContent); - const html = $generateHtmlFromNodes(editor); - // console.log('html', html); - - // setEditorContent(content); - if (typeof onChange === 'function') { - onChange({ editorStateJSON: editorState.toJSON(), editor, tags, htmlContent: html, textContent }); - } + onChange({ editorStateJSON: editorState.toJSON(), editor, tags, htmlContent: html, textContent }); }); }); } From 087e472dfae378a8594ee213eb950118046f7d17 Mon Sep 17 00:00:00 2001 From: Jimmy Liow Date: Thu, 7 Nov 2024 10:36:34 +0800 Subject: [PATCH 2/2] =?UTF-8?q?perf:=20=E6=B5=8B=E8=AF=95=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E4=BD=BF=E7=94=A8=20144=EF=BC=9B=E5=9B=BE=E6=96=87?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E6=88=90=E5=8A=9F=E5=90=8E=E5=85=B3=E9=97=AD?= =?UTF-8?q?=EF=BC=9B=E5=87=BA=E9=94=99=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/config.js | 2 +- src/stores/AuthStore.js | 2 +- src/views/accounts/SnippetList.jsx | 20 ++++++++++++++++++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/config.js b/src/config.js index 3128562..6b282e1 100644 --- a/src/config.js +++ b/src/config.js @@ -6,7 +6,7 @@ // export const WS_URL = 'wss://p9axztuwd7x8a7.mycht.cn/whatsapp_144'; // prod: Slave // debug: -export const API_HOST = 'http://202.103.68.157:8889/v2'; +export const API_HOST = 'http://202.103.68.144:8889/v2'; export const WS_URL = 'ws://202.103.68.157:8889'; // prod: // export const API_HOST = 'https://p9axztuwd7x8a7.mycht.cn/whatsapp_server'; diff --git a/src/stores/AuthStore.js b/src/stores/AuthStore.js index eb2e528..87046dc 100644 --- a/src/stores/AuthStore.js +++ b/src/stores/AuthStore.js @@ -51,7 +51,7 @@ const useAuthStore = create(devtools((set, get) => ({ setLoginStatus(200) const json = await fetchJSON( - 'http://202.103.68.157:889/dingtalk/dingtalkwork/WhatsAppAuth', + 'http://202.103.68.144:889/dingtalk/dingtalkwork/WhatsAppAuth', //`https://p9axztuwd7x8a7.mycht.cn/dingtalk/dingtalkwork/WhatsAppAuth`, { authCode }, ) diff --git a/src/views/accounts/SnippetList.jsx b/src/views/accounts/SnippetList.jsx index d4690a4..4a9513a 100644 --- a/src/views/accounts/SnippetList.jsx +++ b/src/views/accounts/SnippetList.jsx @@ -1,4 +1,4 @@ -import { Row, Col, Tag, List, Form, Input, Button, Space, Modal, Select, message } from 'antd' +import { App, Row, Col, Tag, List, Form, Input, Button, Space, Modal, Select, message } from 'antd' import { useState, useEffect } from 'react' import EditorInput from '../../components/EditorInput' import HtmlPreview from './HtmlPreview' @@ -25,12 +25,28 @@ function SnippetList() { const [loginUser] = useAuthStore((state) => [state.loginUser]) + const { notification } = App.useApp() const [isSnippetModalOpen, setSnippetModalOpen] = useState(false) const [isHtmlLoading, setHtmlLoading] = useState(false) const onSnippetFinish = (values) => { - console.log('onSnippetFinish:', values) saveOrUpdateSnippet(values) + .then(() => { + notification.info({ + message: 'Notification', + description: '图文保存成功', + placement: 'top', + }) + setSnippetModalOpen(false) + }) + .catch(ex => { + notification.error({ + message: 'Notification', + description: ex.message, + placement: 'top', + duration: 4, + }) + }) } const onSnippetFailed = (error) => {