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: