From a705d8cd3f9188a142775e282784b0d919a3ef95 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Tue, 15 Mar 2016 08:07:42 -0600 Subject: [PATCH] Fix navigation issues with deleting and clicking Deleting a notebook would only work on the first item because array.slice works differently than intended. When adding a new notebook, it now focuses on that notebook and loads the proper notes. Same when deleting a notebook. --- app/components/LibraryNav.jsx | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/app/components/LibraryNav.jsx b/app/components/LibraryNav.jsx index 1916772..45e5af2 100644 --- a/app/components/LibraryNav.jsx +++ b/app/components/LibraryNav.jsx @@ -200,10 +200,14 @@ export default class LibraryNav extends React.Component { addNotebookTapped = (callback) => { if(!utils.isFunction(callback)){ - callback = () => { + callback = (notebook) => { if(this.refs['textField0']){ this.refs['textField0'].focus() } + + this.refs.mainList.setIndex(-1) + this.refs.notebookList.setIndex(0) + this.props.updateSelection(notebook) } } @@ -235,7 +239,12 @@ export default class LibraryNav extends React.Component { this.props.updateSelection(item) } - item.clicked(i, item, type, ev) + // Process any callbacks attached to the menu + var clickedCallbacks = this.props.navigation.clickedCallbacks + for(var i=0; i { @@ -249,7 +258,7 @@ export default class LibraryNav extends React.Component { deleteTapped = (i, callback) => { var nbs = this.props.navigation.notebooks - var nb = nbs.slice(i, 1)[0] + var nb = nbs.slice(i, i+1)[0] rmdir(nb.path, (err)=>{ if(err){ @@ -259,6 +268,19 @@ export default class LibraryNav extends React.Component { if(utils.isFunction(callback)){ callback(nb, err) } + var newNbs = this.props.navigation.notebooks + var selection = null + + if(newNbs.length > i){ + selection = newNbs[i] + } + else if(newNbs.length > 0){ + selection = newNbs[newNbs.length-1] + } + + if(selection){ + this.props.updateSelection(selection) + } }) }) @@ -289,8 +311,9 @@ export default class LibraryNav extends React.Component { var x = nativeEvent.pageX var y = nativeEvent.pageY - this.props.updateContextMenu(this.contextMenuItems(i)) this.props.openContextMenu(x, y) + this.props.updateContextMenu(this.contextMenuItems(i)) + this.props.updateSelection(this.props.navigation.notebooks[i]) } else{ this.props.updateSelection(this.props.navigation.notebooks[i])