Fixes to tree

This commit is contained in:
Jori Lallo 2016-06-26 22:15:15 -07:00
parent 6fef3137a1
commit e967033b28
5 changed files with 16 additions and 7 deletions

View File

@ -74,7 +74,6 @@ router.post('atlases.updateNavigationTree', auth(), async (ctx) => {
ctx.body = {
data: await presentAtlas(atlas, true),
tree: newTree,
};
});

View File

@ -76,12 +76,15 @@ var Node = React.createClass({
placeholder: index.id === dragging,
rootNode: this.props.rootNode,
})} style={style}>
<div className={ styles.inner } ref="inner" onMouseDown={this.handleMouseDown}>
<div
className={ styles.inner }
ref="inner"
onMouseDown={this.props.rootNode ? (e) => e.stopPropagation() : this.handleMouseDown}
>
{!this.props.rootNode && this.renderCollapse()}
<span
className={ cx(styles.nodeLabel, { rootLabel: this.props.rootNode }) }
onClick={() => { history.push(node.url) }}
onMouseDown={this.props.rootNode ? function(e){e.stopPropagation()} : undefined}
>
{ node.title }
</span>

View File

@ -230,7 +230,8 @@ module.exports = React.createClass({
tree: tree
});
this.change(tree);
// Don't push updates as collapsing is separated from store state
// this.change(tree);
},
// buildTreeNumbering(tree) {

View File

@ -1,4 +1,6 @@
import React from 'react';
import { toJS } from 'mobx';
import _isEqual from 'lodash/isEqual';
import { Link } from 'react-router';
import { observer } from 'mobx-react';
@ -65,8 +67,10 @@ class DocumentScene extends React.Component {
}
handleChange = (tree) => {
console.log(tree);
store.updateNavigationTree(tree);
// Only update when tree changes, otherwise link clicks toggle tree handleChanges changes
if (!_isEqual(toJS(tree), toJS(store.document.atlas.navigationTree))) {
store.updateNavigationTree(tree);
}
}
render() {
@ -115,7 +119,7 @@ class DocumentScene extends React.Component {
<div className={ styles.sidebar }>
<Tree
paddingLeft={10}
tree={ doc.atlas.navigationTree }
tree={ toJS(doc.atlas.navigationTree) }
onChange={this.handleChange}
isNodeCollapsed={this.isNodeCollapsed}
renderNode={this.renderNode}

View File

@ -51,6 +51,8 @@ const store = new class DocumentSceneStore {
id: this.document.atlas.id,
tree: tree,
});
const { data } = res;
this.document.atlas = data;
} catch (e) {
console.error("Something went wrong");
}