Add async note loading and proper initial loading
This commit is contained in:
parent
a705d8cd3f
commit
24870a5769
1 changed files with 19 additions and 11 deletions
|
|
@ -50,12 +50,18 @@ export default class EntrySelector extends React.Component {
|
||||||
this.loadNotes()
|
this.loadNotes()
|
||||||
const { store } = this.context
|
const { store } = this.context
|
||||||
store.subscribe(this.stateChanged)
|
store.subscribe(this.stateChanged)
|
||||||
|
this.oldSelection = this.props.navigation.selection
|
||||||
}
|
}
|
||||||
|
|
||||||
stateChanged = () => {
|
stateChanged = () => {
|
||||||
const { store } = this.context
|
const { store } = this.context
|
||||||
var selection = store.getState().navigation.selection
|
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(){
|
static get childContextTypes(){
|
||||||
|
|
@ -70,21 +76,23 @@ export default class EntrySelector extends React.Component {
|
||||||
|
|
||||||
loadNotes = () => {
|
loadNotes = () => {
|
||||||
var notebook = this.props.navigation.selection
|
var notebook = this.props.navigation.selection
|
||||||
var notes = utils.loadNotes(notebook)
|
if(!utils.isEmpty(notebook)){
|
||||||
this.state.notes = notes
|
var notes = utils.loadNotes(notebook)
|
||||||
|
notes.sort(utils.compareNotes())
|
||||||
|
this.state.notes = notes
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
reloadNotes = (selection) => {
|
reloadNotes = (selection) => {
|
||||||
var notebook = selection || this.props.navigation.selection
|
this.setState({notes: []}, ()=>{
|
||||||
|
var notebook = selection || this.props.navigation.selection
|
||||||
var notes = utils.loadNotes(notebook)
|
utils.loadNotesAsync(notebook, (notes) => {
|
||||||
this.setState({notes: notes})
|
notes.sort(utils.compareNotes())
|
||||||
|
this.setState({notes: notes})
|
||||||
|
})
|
||||||
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
blank(){
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
createNotePath = (note, callback) => {
|
createNotePath = (note, callback) => {
|
||||||
mkdirp(path.join(note.path, 'resources'), (err) => {
|
mkdirp(path.join(note.path, 'resources'), (err) => {
|
||||||
if(err){
|
if(err){
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue