2022-03-23 15:25:28 +00:00
|
|
|
import * as React from 'react';
|
2023-12-24 02:06:57 +00:00
|
|
|
import { TreeView, TreeItem } from '@mui/x-tree-view';
|
2022-03-23 15:25:28 +00:00
|
|
|
import ExpandMoreIcon from '@mui/icons-material/ExpandMore';
|
|
|
|
import ChevronRightIcon from '@mui/icons-material/ChevronRight';
|
2023-12-24 02:06:57 +00:00
|
|
|
import { useRouter } from 'next/router'
|
|
|
|
import { styled } from '@mui/material/styles';
|
2023-12-26 01:27:55 +00:00
|
|
|
import { Divider } from '@mui/material';
|
2022-04-19 04:39:51 +00:00
|
|
|
|
2023-12-24 02:06:57 +00:00
|
|
|
const TCTreeItem = styled(TreeItem)(({ theme }) => ({
|
|
|
|
'& .MuiTreeItem-content': {
|
|
|
|
'& .MuiTreeItem-label': {
|
|
|
|
fontSize: '1rem',
|
|
|
|
paddingLeft: '6px',
|
|
|
|
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif,',
|
|
|
|
lineHeight: 2.0,
|
2022-04-19 04:39:51 +00:00
|
|
|
},
|
2023-12-24 02:06:57 +00:00
|
|
|
},
|
2022-04-19 04:39:51 +00:00
|
|
|
}))
|
|
|
|
|
2022-03-23 15:25:28 +00:00
|
|
|
|
|
|
|
export default function FolderTree(props) {
|
2023-12-24 02:06:57 +00:00
|
|
|
const renderTree = (nodes) => (
|
|
|
|
<TCTreeItem key={nodes.id} nodeId={nodes.id} label={nodes.name}>
|
|
|
|
{Array.isArray(nodes.children)
|
|
|
|
? nodes.children.map((node) => renderTree(node))
|
|
|
|
: null}
|
|
|
|
</TCTreeItem>
|
|
|
|
);
|
2022-03-23 15:25:28 +00:00
|
|
|
|
2023-12-24 02:06:57 +00:00
|
|
|
const router = useRouter()
|
|
|
|
// const childrenNodeIds = props.tree.children.map(aNode => {return aNode.id})
|
|
|
|
const expandedNodes = [props.tree.id]
|
|
|
|
return (
|
2023-12-26 01:27:55 +00:00
|
|
|
<>
|
|
|
|
<a href='http://localhost:3000'>{"<-"} Back To Portfolio</a>
|
|
|
|
<Divider />
|
|
|
|
<TreeView
|
|
|
|
aria-label="rich object"
|
|
|
|
defaultCollapseIcon={<ExpandMoreIcon />}
|
|
|
|
defaultExpanded={expandedNodes}
|
|
|
|
defaultExpandIcon={<ChevronRightIcon />}
|
|
|
|
onNodeSelect={(event, nodIds) => {
|
|
|
|
const currentNode = props.flattenNodes.find(aNode => {
|
|
|
|
return aNode.id === nodIds
|
|
|
|
})
|
|
|
|
if (currentNode != null && currentNode.routePath != null) {
|
|
|
|
router.push(currentNode.routePath)
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
sx={{ flexGrow: 1, maxWidth: 400, overflowY: 'auto' }}
|
|
|
|
>
|
|
|
|
{renderTree(props.tree)}
|
|
|
|
</TreeView>
|
|
|
|
</>
|
2023-12-24 02:06:57 +00:00
|
|
|
);
|
2022-03-23 15:25:28 +00:00
|
|
|
}
|