From 9adb97e9f6583a4450eec8b544bc12ed664a716e Mon Sep 17 00:00:00 2001 From: shixiaohua Date: Tue, 6 Feb 2024 10:11:26 +0800 Subject: [PATCH] =?UTF-8?q?feat:=E6=89=93=E5=BC=80=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E5=A4=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/App.js | 2 +- src/components/ItemTree/index.jsx | 11 +++++++---- src/pages/Note/index.jsx | 25 ++++++++----------------- 3 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/App.js b/src/App.js index fdd83a3..65345fc 100644 --- a/src/App.js +++ b/src/App.js @@ -9,7 +9,7 @@ import {useDispatch} from "react-redux"; function App() { let navigateFunction = useNavigate(); - let dispatch = useDispatch(); + const dispatch = useDispatch(); function nativeTo(path){ navigateFunction(path) } diff --git a/src/components/ItemTree/index.jsx b/src/components/ItemTree/index.jsx index 6e2d64a..5c2fa6b 100644 --- a/src/components/ItemTree/index.jsx +++ b/src/components/ItemTree/index.jsx @@ -87,14 +87,17 @@ const flushTree = (fileDirDate) => { } return defaultValueStateSet; } -const ItemTree = () => { - +const ItemTree = (prop) => { + console.log("prop.filePath:",prop.filePath) const [expandedKeys, setExpandedKeys] = useState([]); const [searchValue, setSearchValue] = useState(''); const dispatch = useDispatch() const [autoExpandParent, setAutoExpandParent] = useState(true); - let filePath = useSelector(state => state.dirMessage.data); - const [defaultValueState, setDefaultValueState] = useState(flushTree(filePath)); + // let filePath = useSelector(state => state.dirMessage.data); + const [defaultValueState, setDefaultValueState] = useState(flushTree(prop.filePath)); + useEffect(() => { + setDefaultValueState(flushTree(prop.filePath)) + }, [prop]); const onExpand = (newExpandedKeys) => { setExpandedKeys(newExpandedKeys); setAutoExpandParent(false); diff --git a/src/pages/Note/index.jsx b/src/pages/Note/index.jsx index 3ab2b4c..422db28 100644 --- a/src/pages/Note/index.jsx +++ b/src/pages/Note/index.jsx @@ -1,17 +1,15 @@ -import React, {useEffect, useRef, useState} from 'react'; +import React, {useRef, useState} from 'react'; import { UserOutlined, } from '@ant-design/icons'; -import {Layout, Menu, Button, theme, Avatar, Tabs} from 'antd'; +import {Layout, Avatar, Tabs} from 'antd'; import Hlexical from './Hlexical'; import ItemTree from "../../components/ItemTree"; import './index.less' -import {store} from "../../redux/store"; -import {isEmpty} from "../../utils/ObjectUtils"; import {useSelector, useDispatch} from "react-redux"; import {addTableBarItem, removeTableBarItem, setActiveKey,updatedSavedFile} from "../../redux/tableBarItem_reducer" -const {Header, Sider, Content} = Layout; +const {Sider} = Layout; const Note = () => { const dispatch = useDispatch() const [collapsed, setCollapsed] = useState(false); @@ -23,20 +21,13 @@ const Note = () => { const activeKey=useSelector(state => state.tableBarItem.activeKey); const items = useSelector(state => state.tableBarItem.data) - + let filePath = useSelector(state => state.dirMessage.data); const onChange = (newActiveKey) => { console.log("setActiveKey(newActiveKey)",newActiveKey) dispatch(setActiveKey({"activeKey":newActiveKey})); }; const add = () => { const newActiveKey = `newTab${newTabIndex.current++}`; - // const newPanes = [...items]; - // newPanes.push({ - // label: 'New Tab', - // children:
, - // key: newActiveKey, - // }); - // setItems(newPanes); dispatch(addTableBarItem( { label: 'New Tab', @@ -64,8 +55,6 @@ const Note = () => { newActiveKey = newPanes[0].key; } } - console.log("remove = (newActiveKey):",newActiveKey) - // setItems(newPanes); dispatch(setActiveKey({"activeKey":newActiveKey})); }; const onEdit = (targetKey, action) => { @@ -87,7 +76,7 @@ const Note = () => { - + { onChange={onChange} activeKey={activeKey} onEdit={onEdit} - items={items.map(item=>{return {label:item.label,children:
,key:item.key}})} + items={items.map(item=>{ + return {label:item.label,children:
,key:item.key} + })} />