import React, { useEffectEvent, useRef, useState } from 'react'; import { Layout, theme, Breadcrumb, Button, Space, Tree } from 'antd'; import Graph, { type GraphHandle } from './components/Graph'; import type { BreadcrumbItemType } from 'antd/es/breadcrumb/Breadcrumb'; import { useKeysdownStore } from './stores/ArrayStore'; import { MenuFoldOutlined, MenuUnfoldOutlined, SaveOutlined, FolderOpenOutlined, } from '@ant-design/icons'; import { saveConceptSketch } from './utils/saveGraph'; import { loadConceptSketch } from './utils/loadGraph'; import { useGraphLayersTreeStore } from './stores/TreeStore'; const { Header, Content, Sider } = Layout; const App: React.FC = () => { const { token: { colorBgContainer }, } = theme.useToken(); const [graphLevel, setGraphLevel] = useState([]) const [collapsed, setCollapsed] = useState(true); const addKey = useKeysdownStore(state => state.add); const removeKey = useKeysdownStore(state => state.remove); const onKeydown = useEffectEvent((key: string) => { addKey(key); }); const onKeyUp = useEffectEvent((key: string) => { removeKey(key); }) document.addEventListener('keydown', (ev) => { onKeydown(ev.key) }); document.addEventListener('keyup', (ev) => { onKeyUp(ev.key); }); const treeData = useGraphLayersTreeStore(store => store.tree); const nodesFlatById = useGraphLayersTreeStore(store => store.nodesFlatById); const parentIdByChildId = useGraphLayersTreeStore(store => store.parentIdByChildId); const graphRef = useRef(null); function buildPathToNode(nodeId: string) { const path: Array<{ id: string; name: string | undefined }> = []; let current: string | undefined = nodeId; while (current && nodesFlatById.has(current)) { const node = nodesFlatById.get(current)!; path.unshift({ id: current, name: node.title as string | undefined }); current = parentIdByChildId.get(current); } return [{ id: 'main', name: 'Main' }, ...path]; } return (
{ const nodeId = keys[0] as string; if (!nodeId) return; graphRef.current?.navigateTo(nodeId, buildPathToNode(nodeId)); }} />
); }; export default App;