Skip to content
This repository was archived by the owner on Feb 21, 2020. It is now read-only.

Boostnote app Crashes when adding note to Dropbox #199

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 8 additions & 9 deletions app/views/DropboxNoteList.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -159,15 +159,15 @@ 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) => {
return response.json()
})
.then((responseJson) => {
this.setState({
folderList: responseJson.folders
folderList: responseJson.folders || []
})
})

Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -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
Expand All @@ -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
})
Expand Down Expand Up @@ -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(
Expand All @@ -349,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,
Expand Down