1
0
mirror of https://github.com/haiwen/seahub.git synced 2025-09-05 08:53:14 +00:00

wiki style change

This commit is contained in:
Michael An
2019-05-22 13:31:08 +08:00
parent ce057ab2d1
commit a778f2bd5f
2 changed files with 38 additions and 5 deletions

View File

@@ -38,6 +38,9 @@ class IndexContentViewer extends React.Component {
super(props);
this.links = [];
this.treeRoot = new TreeNode({ name: '', href: '' });
this.state = {
currentPath: '',
};
}
componentWillMount() {
@@ -79,6 +82,10 @@ class IndexContentViewer extends React.Component {
event.stopPropagation();
const link = this.getLink(event.target);
if (link) this.props.onLinkClick(link);
const currentPath = event.target.getAttribute('data-path');
if (currentPath) {
this.setState({ currentPath: currentPath });
}
}
getLink = (node) => {
@@ -146,11 +153,24 @@ class IndexContentViewer extends React.Component {
const newNodes = Utils.changeMarkdownNodes(value.document.nodes, this.changeInlineNode);
newNodes.map((node) => {
if (node.type === 'unordered_list' || node.type === 'ordered_list') {
this.treeRoot = this.transSlateToTree(node.nodes, this.treeRoot);
let treeRoot = this.transSlateToTree(node.nodes, this.treeRoot);
this.setNodePath(treeRoot, '/');
this.treeRoot = treeRoot;
}
});
}
setNodePath = (node, parentNodePath) => {
let name = node.name;
let path = parentNodePath === '/' ? parentNodePath + name : parentNodePath + '/' + name;
node.path = path;
if (node.children.length > 0) {
node.children.map(child => {
this.setNodePath(child, path);
});
}
}
// slateNodes is list items of an unordered list or ordered list, translate them to treeNode and add to parentTreeNode
transSlateToTree = (slateNodes, parentTreeNode) => {
let treeNodes = slateNodes.map((slateNode) => {
@@ -200,7 +220,7 @@ class IndexContentViewer extends React.Component {
render() {
return (
<div className="mx-2 o-hidden">
<FolderItem node={this.treeRoot} bindClickEvent={this.bindClickEvent}/>
<FolderItem node={this.treeRoot} bindClickEvent={this.bindClickEvent} currentPath={this.state.currentPath}/>
</div>
);
}
@@ -218,7 +238,7 @@ class FolderItem extends React.Component {
constructor(props) {
super(props);
this.state = {
expanded: true
expanded: false
};
}
@@ -229,8 +249,9 @@ class FolderItem extends React.Component {
}
renderLink = (node) => {
const className = node.path === this.props.currentPath ? 'wiki-nav-content wiki-nav-content-highlight' : 'wiki-nav-content'
if (node.href && node.name) {
return <div className="wiki-nav-content"><a href={node.href}>{node.name}</a></div>;
return <div className={className}><a href={node.href} data-path={node.path}>{node.name}</a></div>;
} else if (node.name) {
return <div className="wiki-nav-content"><span>{node.name}</span></div>;
} else {
@@ -238,6 +259,14 @@ class FolderItem extends React.Component {
}
}
componentDidMount() {
if (this.props.node && !this.props.node.parentNode) {
this.setState({ expanded: true }, () => {
this.props.bindClickEvent();
});
}
}
render() {
const { node } = this.props;
if (node.children.length > 0) {
@@ -254,7 +283,7 @@ class FolderItem extends React.Component {
{this.state.expanded && node.children.map((child, index) => {
return (
<div className="pl-4 position-relative" key={index}>
<FolderItem node={child} bindClickEvent={this.props.bindClickEvent}/>
<FolderItem node={child} bindClickEvent={this.props.bindClickEvent} currentPath={this.props.currentPath}/>
</div>
);
})}