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

View File

@@ -8,6 +8,10 @@
overflow: hidden; overflow: hidden;
display: block; display: block;
} }
.wiki-nav-content-highlight a {
text-decoration: none;
color: #eb8205;
}
.wiki-nav-content a:hover { .wiki-nav-content a:hover {
text-decoration: none; text-decoration: none;
color: #eb8205; color: #eb8205;