From 24870a576959e26862ecdd91829b467fb13095e4 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Tue, 15 Mar 2016 08:15:53 -0600 Subject: [PATCH] Add async note loading and proper initial loading --- app/components/EntrySelector.jsx | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/app/components/EntrySelector.jsx b/app/components/EntrySelector.jsx index 4a46806..ac64cee 100644 --- a/app/components/EntrySelector.jsx +++ b/app/components/EntrySelector.jsx @@ -50,12 +50,18 @@ export default class EntrySelector extends React.Component { this.loadNotes() const { store } = this.context store.subscribe(this.stateChanged) + this.oldSelection = this.props.navigation.selection } stateChanged = () => { const { store } = this.context var selection = store.getState().navigation.selection - this.reloadNotes(selection) + var selectionDiffers = utils.differs(this.oldSelection, selection) + + if(selectionDiffers){ + this.reloadNotes(selection) + this.oldSelection = selection + } }; static get childContextTypes(){ @@ -70,21 +76,23 @@ export default class EntrySelector extends React.Component { loadNotes = () => { var notebook = this.props.navigation.selection - var notes = utils.loadNotes(notebook) - this.state.notes = notes + if(!utils.isEmpty(notebook)){ + var notes = utils.loadNotes(notebook) + notes.sort(utils.compareNotes()) + this.state.notes = notes + } } reloadNotes = (selection) => { - var notebook = selection || this.props.navigation.selection - - var notes = utils.loadNotes(notebook) - this.setState({notes: notes}) + this.setState({notes: []}, ()=>{ + var notebook = selection || this.props.navigation.selection + utils.loadNotesAsync(notebook, (notes) => { + notes.sort(utils.compareNotes()) + this.setState({notes: notes}) + }) + }) }; - blank(){ - - } - createNotePath = (note, callback) => { mkdirp(path.join(note.path, 'resources'), (err) => { if(err){