From 8265aa95736df61ae7de77d76e715f3a4167a27b Mon Sep 17 00:00:00 2001 From: Tai Nguyen Date: Thu, 5 Jul 2018 16:06:57 +0700 Subject: [PATCH 1/2] Set folderList default is empty array --- app/views/DropboxNoteList.js | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/app/views/DropboxNoteList.js b/app/views/DropboxNoteList.js index 4455f74..8b4f9b9 100644 --- a/app/views/DropboxNoteList.js +++ b/app/views/DropboxNoteList.js @@ -25,7 +25,7 @@ import DropboxNoteModal from './note/DropboxNoteModal' const js2coffee = require('js2coffee/dist/js2coffee') const DROPBOX_ACCESS_TOKEN = 'DROPBOX:ACCESS_TOKEN' - +const bootNoteFolder = '/Apps/boostnote-mobile' const styles = { noteListWrap: { marginTop: 0, @@ -159,7 +159,7 @@ export default class DropboxNoteList extends Component { method: 'POST', headers: { 'Authorization': `Bearer ${token}`, - 'Dropbox-API-Arg': `{"path": "/boostnote.json"}` + 'Dropbox-API-Arg': `{"path": "${bootNoteFolder}/boostnote.json"}` } }) .then((response) => { @@ -167,7 +167,7 @@ export default class DropboxNoteList extends Component { }) .then((responseJson) => { this.setState({ - folderList: responseJson.folders + folderList: responseJson.folders || [] }) }) @@ -180,7 +180,7 @@ export default class DropboxNoteList extends Component { 'Content-Type': 'application/json' }, body: JSON.stringify({ - path: '/notes', + path: `${bootNoteFolder}/notes`, recursive: false, include_media_info: false, include_deleted: false, @@ -192,7 +192,6 @@ export default class DropboxNoteList extends Component { .then((response) => response.json()) .then((responseJson) => { const noteList = [] - if (responseJson.error_summary && responseJson.error_summary.startsWith('path/not_found/')) { this.props.setIsConnectedToDropbox(true) } @@ -240,12 +239,12 @@ export default class DropboxNoteList extends Component { }) const response = CoffeeScript.eval(responseCson) + if (response.type !== 'MARKDOWN_NOTE' || response.isTrashed) { // Do nothing // Parse not trashed markdown only now return } - const notesOfFolder = noteList .filter(folder => { return folder.folderKey === response.folder @@ -260,7 +259,7 @@ export default class DropboxNoteList extends Component { notesOfFolder.sort((a, b) => { return a.updatedAt < b.updatedAt ? 1 : -1 }) - + this.setState({ noteList: noteList }) @@ -336,7 +335,7 @@ export default class DropboxNoteList extends Component { } createNewNote () { - const folderChooseMenu = this.state.folderList.map(folder => folder.name) + const folderChooseMenu = (this.state.folderList || []).map(folder => folder.name) folderChooseMenu.push('Cancel') if (this.actionSheet !== null) { this.actionSheet._root.showActionSheet( From 8cff41a548bec801a444a8c40fca436d6ef18490 Mon Sep 17 00:00:00 2001 From: Tai Nguyen Date: Thu, 5 Jul 2018 16:06:57 +0700 Subject: [PATCH 2/2] Update new note path --- app/views/DropboxNoteList.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/DropboxNoteList.js b/app/views/DropboxNoteList.js index 8b4f9b9..d2cbfe5 100644 --- a/app/views/DropboxNoteList.js +++ b/app/views/DropboxNoteList.js @@ -348,7 +348,7 @@ export default class DropboxNoteList extends Component { if (buttonIndex === this.state.folderList.length) { return } - const newNotePath = `"/notes/${makeRandomHex()}.cson"` + const newNotePath = `"${bootNoteFolder}/notes/${makeRandomHex()}.cson"` const newNoteJson = JSON.stringify({ type: 'MARKDOWN_NOTE', folder: this.state.folderList[buttonIndex].key,