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 = { ctx.body = {
data: await presentAtlas(atlas, true), data: await presentAtlas(atlas, true),
tree: newTree,
}; };
}); });

View File

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

View File

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

View File

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

View File

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