From 3d089d072861c6879551786c1856331e5d66865d Mon Sep 17 00:00:00 2001
From: Michael An <2331806369@qq.com>
Date: Tue, 16 Jul 2024 17:00:14 +0800
Subject: [PATCH 1/2] fix rename page logic
---
.../wiki2/wiki-right-header/page-title.js | 60 ++++++++++++++++---
1 file changed, 53 insertions(+), 7 deletions(-)
diff --git a/frontend/src/pages/wiki2/wiki-right-header/page-title.js b/frontend/src/pages/wiki2/wiki-right-header/page-title.js
index 56527f62f6..62991526c9 100644
--- a/frontend/src/pages/wiki2/wiki-right-header/page-title.js
+++ b/frontend/src/pages/wiki2/wiki-right-header/page-title.js
@@ -1,4 +1,4 @@
-import React, { useCallback, useEffect, useState } from 'react';
+import React, { useCallback, useEffect, useState, useRef } from 'react';
import PropTypes from 'prop-types';
import classnames from 'classnames';
import { Input } from 'reactstrap';
@@ -16,18 +16,55 @@ const propTypes = {
const PageTitle = ({ currentPageConfig, onUpdatePage }) => {
const [isShowController, setIsShowController] = useState(false);
+ const [pageName, setPageName] = useState(currentPageConfig.name);
+ const isChineseInput = useRef(false);
+ const isTyping = useRef(false);
+ const timer = useRef(null);
- const handleRenameDocument = useCallback((e) => {
- const { nativeEvent: { isComposing } } = e;
- if (isComposing) return;
+ useEffect(() => {
+ if (pageName !== currentPageConfig.name && isTyping.current === false) {
+ setPageName(currentPageConfig.name);
+ }
+ // eslint-disable-next-line react-hooks/exhaustive-deps
+ }, [currentPageConfig.name]);
+ const onKeyDown = useCallback(() => {
+ isTyping.current = true;
+ if (timer.current) {
+ clearTimeout(timer.current);
+ timer.current = null;
+ }
+ }, []);
+
+ const onKeyUp = useCallback(() => {
+ timer.current = setTimeout(() => {
+ isTyping.current = false;
+ }, 500);
+ }, []);
+
+ const onCompositionStart = useCallback(() => {
+ isChineseInput.current = true;
+ }, []);
+
+ const onCompositionEnd = useCallback((e) => {
+ isChineseInput.current = false;
const newName = e.target.value.trim();
- const { id, name, icon } = currentPageConfig;
- if (newName === name) return;
+ const { id, icon } = currentPageConfig;
const pageConfig = { name: newName, icon };
onUpdatePage && onUpdatePage(id, pageConfig);
}, [currentPageConfig, onUpdatePage]);
+ const onChange = useCallback((e) => {
+ setPageName(e.target.value);
+ if (isChineseInput.current === false) {
+ const newName = e.target.value.trim();
+ if (newName === pageName) return;
+ const { id, icon } = currentPageConfig;
+ const pageConfig = { name: newName, icon };
+ onUpdatePage && onUpdatePage(id, pageConfig);
+ }
+ }, [currentPageConfig, onUpdatePage, pageName]);
+
const onMouseEnter = useCallback(() => {
setIsShowController(true);
}, []);
@@ -79,7 +116,16 @@ const PageTitle = ({ currentPageConfig, onUpdatePage }) => {
)}
-
+
);
};
From b31c2177e2d774e0b35ae249322aa9b347bfc32f Mon Sep 17 00:00:00 2001
From: Michael An <2331806369@qq.com>
Date: Tue, 16 Jul 2024 17:18:09 +0800
Subject: [PATCH 2/2] change end typing indent
---
frontend/src/pages/wiki2/wiki-right-header/page-title.js | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/frontend/src/pages/wiki2/wiki-right-header/page-title.js b/frontend/src/pages/wiki2/wiki-right-header/page-title.js
index 62991526c9..83e8988126 100644
--- a/frontend/src/pages/wiki2/wiki-right-header/page-title.js
+++ b/frontend/src/pages/wiki2/wiki-right-header/page-title.js
@@ -39,7 +39,7 @@ const PageTitle = ({ currentPageConfig, onUpdatePage }) => {
const onKeyUp = useCallback(() => {
timer.current = setTimeout(() => {
isTyping.current = false;
- }, 500);
+ }, 2000);
}, []);
const onCompositionStart = useCallback(() => {