2024-02-05 21:11:26 -05:00
|
|
|
import React, {useRef, useState} from 'react';
|
2024-01-12 00:13:58 -05:00
|
|
|
import {
|
|
|
|
UserOutlined,
|
|
|
|
} from '@ant-design/icons';
|
2024-02-05 21:11:26 -05:00
|
|
|
import {Layout, Avatar, Tabs} from 'antd';
|
2024-01-12 00:13:58 -05:00
|
|
|
import Hlexical from './Hlexical';
|
|
|
|
import ItemTree from "../../components/ItemTree";
|
|
|
|
import './index.less'
|
2024-02-03 20:29:00 -05:00
|
|
|
import {useSelector, useDispatch} from "react-redux";
|
2024-02-04 05:11:14 -05:00
|
|
|
import {addTableBarItem, removeTableBarItem, setActiveKey,updatedSavedFile} from "../../redux/tableBarItem_reducer"
|
2024-01-26 02:41:22 -05:00
|
|
|
|
2024-02-05 21:11:26 -05:00
|
|
|
const {Sider} = Layout;
|
2024-01-12 00:13:58 -05:00
|
|
|
const Note = () => {
|
2024-02-03 20:29:00 -05:00
|
|
|
const dispatch = useDispatch()
|
2024-01-12 00:13:58 -05:00
|
|
|
const [collapsed, setCollapsed] = useState(false);
|
|
|
|
// const {
|
|
|
|
// token: { colorBgContainer },
|
|
|
|
// } = theme.useToken();
|
|
|
|
const colorBgContainer = '#800080'
|
|
|
|
const newTabIndex = useRef(0);
|
2024-02-03 20:29:00 -05:00
|
|
|
|
2024-02-04 01:42:20 -05:00
|
|
|
const activeKey=useSelector(state => state.tableBarItem.activeKey);
|
|
|
|
const items = useSelector(state => state.tableBarItem.data)
|
2024-02-05 21:11:26 -05:00
|
|
|
let filePath = useSelector(state => state.dirMessage.data);
|
2024-01-12 00:13:58 -05:00
|
|
|
const onChange = (newActiveKey) => {
|
2024-02-03 20:29:00 -05:00
|
|
|
console.log("setActiveKey(newActiveKey)",newActiveKey)
|
2024-02-04 01:42:20 -05:00
|
|
|
dispatch(setActiveKey({"activeKey":newActiveKey}));
|
2024-01-12 00:13:58 -05:00
|
|
|
};
|
|
|
|
const add = () => {
|
|
|
|
const newActiveKey = `newTab${newTabIndex.current++}`;
|
2024-02-03 20:29:00 -05:00
|
|
|
dispatch(addTableBarItem(
|
|
|
|
{
|
|
|
|
label: 'New Tab',
|
2024-02-04 05:11:14 -05:00
|
|
|
// children: "",
|
2024-02-03 20:29:00 -05:00
|
|
|
key: newActiveKey,
|
2024-02-04 05:11:14 -05:00
|
|
|
activeKey:newActiveKey
|
2024-02-03 20:29:00 -05:00
|
|
|
}
|
|
|
|
));
|
2024-01-12 00:13:58 -05:00
|
|
|
};
|
|
|
|
const remove = (targetKey) => {
|
2024-02-03 22:08:49 -05:00
|
|
|
console.log("remove = (targetKey):",targetKey)
|
2024-01-12 00:13:58 -05:00
|
|
|
let newActiveKey = activeKey;
|
|
|
|
let lastIndex = -1;
|
|
|
|
items.forEach((item, i) => {
|
|
|
|
if (item.key === targetKey) {
|
|
|
|
lastIndex = i - 1;
|
|
|
|
}
|
|
|
|
});
|
2024-02-03 22:08:49 -05:00
|
|
|
dispatch(removeTableBarItem(targetKey));
|
2024-01-12 00:13:58 -05:00
|
|
|
const newPanes = items.filter((item) => item.key !== targetKey);
|
|
|
|
if (newPanes.length && newActiveKey === targetKey) {
|
|
|
|
if (lastIndex >= 0) {
|
|
|
|
newActiveKey = newPanes[lastIndex].key;
|
|
|
|
} else {
|
|
|
|
newActiveKey = newPanes[0].key;
|
|
|
|
}
|
|
|
|
}
|
2024-02-04 01:42:20 -05:00
|
|
|
dispatch(setActiveKey({"activeKey":newActiveKey}));
|
2024-01-12 00:13:58 -05:00
|
|
|
};
|
|
|
|
const onEdit = (targetKey, action) => {
|
|
|
|
if (action === 'add') {
|
|
|
|
add();
|
|
|
|
} else {
|
|
|
|
remove(targetKey);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Layout>
|
|
|
|
<Sider margin='5' collapsed='true'>
|
|
|
|
<div>
|
2024-01-25 02:26:23 -05:00
|
|
|
<Avatar size={60} src='http://localhost/20231114150555.jpg' icon={<UserOutlined/>}/>
|
2024-01-12 00:13:58 -05:00
|
|
|
</div>
|
|
|
|
<div>
|
2024-01-25 02:26:23 -05:00
|
|
|
<p style={{color: colorBgContainer, 'fontSize': 60}}>上善若水</p>
|
2024-01-12 00:13:58 -05:00
|
|
|
</div>
|
|
|
|
</Sider>
|
2024-01-25 02:26:23 -05:00
|
|
|
<Sider trigger={null} collapsedWidth={0} collapsible collapsed={collapsed}>
|
2024-02-05 21:11:26 -05:00
|
|
|
<ItemTree filePath={filePath}></ItemTree>
|
2024-01-12 00:13:58 -05:00
|
|
|
</Sider>
|
|
|
|
<Layout>
|
2024-01-23 04:27:34 -05:00
|
|
|
<Tabs
|
|
|
|
type="editable-card"
|
|
|
|
onChange={onChange}
|
|
|
|
activeKey={activeKey}
|
|
|
|
onEdit={onEdit}
|
2024-02-05 21:11:26 -05:00
|
|
|
items={items.map(item=>{
|
|
|
|
return {label:item.label,children: <div className="HlexicalName"><Hlexical filePath={item.children}/></div>,key:item.key}
|
|
|
|
})}
|
2024-01-23 04:27:34 -05:00
|
|
|
/>
|
|
|
|
</Layout>
|
2024-01-12 00:13:58 -05:00
|
|
|
</Layout>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
export default Note;
|