diff --git a/ReactNativeClient/lib/components/folder-list.js b/ReactNativeClient/lib/components/folder-list.js index 1df823143d..0b5aa9702b 100644 --- a/ReactNativeClient/lib/components/folder-list.js +++ b/ReactNativeClient/lib/components/folder-list.js @@ -6,12 +6,12 @@ import { ItemListComponent } from 'lib/components/item-list.js'; import { Note } from 'lib/models/note.js'; import { Folder } from 'lib/models/folder.js'; import { _ } from 'lib/locale.js'; -import { NoteFolderService } from 'lib/services/note-folder-service.js'; +import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js' class FolderListComponent extends ItemListComponent { listView_itemPress(folderId) { - NoteFolderService.openNoteList(folderId); + NotesScreenUtils.openNoteList(folderId); } } diff --git a/ReactNativeClient/lib/components/item-list.js b/ReactNativeClient/lib/components/item-list.js index 06f0a27fb9..5fc1ffd994 100644 --- a/ReactNativeClient/lib/components/item-list.js +++ b/ReactNativeClient/lib/components/item-list.js @@ -4,7 +4,6 @@ import { ListView, Text, TouchableHighlight, Switch, View } from 'react-native'; import { Log } from 'lib/log.js'; import { _ } from 'lib/locale.js'; import { Checkbox } from 'lib/components/checkbox.js'; -import { NoteFolderService } from 'lib/services/note-folder-service.js'; import { Note } from 'lib/models/note.js'; class ItemListComponent extends Component { @@ -33,14 +32,9 @@ class ItemListComponent extends Component { }); } - todoCheckbox_change(itemId, checked) { - NoteFolderService.setField('note', itemId, 'todo_completed', checked); - - // Note.load(itemId).then((oldNote) => { - // let newNote = Object.assign({}, oldNote); - // newNote.todo_completed = checked; - // return NoteFolderService.save('note', newNote, oldNote); - // }); + async todoCheckbox_change(itemId, checked) { + let note = await Note.load(itemId); + await Note.save({ id: note.id, todo_completed: checked }); } listView_itemPress(itemId) {} diff --git a/ReactNativeClient/lib/components/screens/folder.js b/ReactNativeClient/lib/components/screens/folder.js index bb4902c3ad..fa07df42c3 100644 --- a/ReactNativeClient/lib/components/screens/folder.js +++ b/ReactNativeClient/lib/components/screens/folder.js @@ -3,8 +3,8 @@ import { View, Button, TextInput } from 'react-native'; import { connect } from 'react-redux' import { Log } from 'lib/log.js' import { Folder } from 'lib/models/folder.js' +import { BaseModel } from 'lib/base-model.js' import { ScreenHeader } from 'lib/components/screen-header.js'; -import { NoteFolderService } from 'lib/services/note-folder-service.js'; class FolderScreenComponent extends React.Component { @@ -41,18 +41,15 @@ class FolderScreenComponent extends React.Component { this.folderComponent_change('title', text); } - saveFolderButton_press() { - console.warn('CHANGE NOT TESTED'); - let toSave = BaseModel.diffObjects(this.originalFolder, this.state.folder); - toSave.id = this.state.folder.id; - Folder.save(toSave).then((folder) => { - this.originalFolder = Object.assign({}, folder); - this.setState({ folder: folder }); - }); - // NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => { - // this.originalFolder = Object.assign({}, folder); - // this.setState({ folder: folder }); - // }); + async saveFolderButton_press() { + let toSave = { + title: this.state.folder.title, + }; + + if (this.originalFolder) toSave.id = this.originalFolder.id; + + this.originalFolder = await Folder.save(toSave); + this.setState({ folder: this.originalFolder }); } render() { diff --git a/ReactNativeClient/lib/components/screens/loading.js b/ReactNativeClient/lib/components/screens/loading.js index 6a93ab7228..d1285dd535 100644 --- a/ReactNativeClient/lib/components/screens/loading.js +++ b/ReactNativeClient/lib/components/screens/loading.js @@ -4,7 +4,6 @@ import { connect } from 'react-redux' import { Log } from 'lib/log.js' import { Folder } from 'lib/models/folder.js' import { ScreenHeader } from 'lib/components/screen-header.js'; -import { NoteFolderService } from 'lib/services/note-folder-service.js'; class LoadingScreenComponent extends React.Component { diff --git a/ReactNativeClient/lib/components/screens/note.js b/ReactNativeClient/lib/components/screens/note.js index d80dba8952..f87d560c01 100644 --- a/ReactNativeClient/lib/components/screens/note.js +++ b/ReactNativeClient/lib/components/screens/note.js @@ -5,7 +5,6 @@ import { Log } from 'lib/log.js' import { Note } from 'lib/models/note.js' import { ScreenHeader } from 'lib/components/screen-header.js'; import { Checkbox } from 'lib/components/checkbox.js' -import { NoteFolderService } from 'lib/services/note-folder-service.js'; import { _ } from 'lib/locale.js'; class NoteScreenComponent extends React.Component { @@ -17,17 +16,14 @@ class NoteScreenComponent extends React.Component { constructor() { super(); this.state = { note: Note.new() } - this.originalNote = null; } componentWillMount() { if (!this.props.noteId) { let note = this.props.itemType == 'todo' ? Note.newTodo(this.props.folderId) : Note.new(this.props.folderId); - Log.info(note); this.setState({ note: note }); } else { Note.load(this.props.noteId).then((note) => { - this.originalNote = Object.assign({}, note); this.setState({ note: note }); }); } @@ -49,23 +45,11 @@ class NoteScreenComponent extends React.Component { this.noteComponent_change('body', text); } - saveNoteButton_press() { - - console.warn('CHANGE NOT TESTED'); - + async saveNoteButton_press() { let isNew = !this.state.note.id; - let toSave = BaseModel.diffObjects(this.originalNote, this.state.note); - toSave.id = this.state.note.id; - Note.save(toSave).then((note) => { - this.originalNote = Object.assign({}, note); - this.setState({ note: note }); - if (isNew) return Note.updateGeolocation(note.id); - }); - - // NoteFolderService.save('note', this.state.note, this.originalNote).then((note) => { - // this.originalNote = Object.assign({}, note); - // this.setState({ note: note }); - // }); + let note = await Note.save(this.state.note); + this.setState({ note: note }); + if (isNew) Note.updateGeolocation(note.id); } deleteNote_onPress(noteId) { diff --git a/ReactNativeClient/lib/components/screens/notes-utils.js b/ReactNativeClient/lib/components/screens/notes-utils.js new file mode 100644 index 0000000000..99c7fad61c --- /dev/null +++ b/ReactNativeClient/lib/components/screens/notes-utils.js @@ -0,0 +1,24 @@ +import { Note } from 'lib/models/note.js' + +class NotesScreenUtils { + + static openNoteList(folderId) { + return Note.previews(folderId).then((notes) => { + this.dispatch({ + type: 'NOTES_UPDATE_ALL', + notes: notes, + }); + + this.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Notes', + folderId: folderId, + }); + }).catch((error) => { + Log.warn('Cannot load notes from ' + folderId, error); + }); + } + +} + +export { NotesScreenUtils } \ No newline at end of file diff --git a/ReactNativeClient/lib/components/side-menu-content.js b/ReactNativeClient/lib/components/side-menu-content.js index ecca4faa5c..5dbf66df82 100644 --- a/ReactNativeClient/lib/components/side-menu-content.js +++ b/ReactNativeClient/lib/components/side-menu-content.js @@ -2,7 +2,7 @@ import { connect } from 'react-redux' import { Button } from 'react-native'; import { Log } from 'lib/log.js'; import { Note } from 'lib/models/note.js'; -import { NoteFolderService } from 'lib/services/note-folder-service.js'; +import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js' const React = require('react'); const { @@ -46,7 +46,7 @@ class SideMenuContentComponent extends Component { type: 'SIDE_MENU_CLOSE', }); - NoteFolderService.openNoteList(folder.id); + NotesScreenUtils.openNoteList(folder.id); } render() { diff --git a/ReactNativeClient/lib/database-driver-node.js b/ReactNativeClient/lib/database-driver-node.js index e850b015f2..4bab53c06c 100644 --- a/ReactNativeClient/lib/database-driver-node.js +++ b/ReactNativeClient/lib/database-driver-node.js @@ -15,6 +15,15 @@ class DatabaseDriverNode { }); } + sqliteErrorToJsError(error, sql = null, params = null) { + let msg = [error.toString()]; + if (sql) msg.push(sql); + if (params) msg.push(params); + let output = new Error(msg.join(': ')); + if (error.code) output.code = error.code; + return output; + } + setDebugMode(v) { // ?? } diff --git a/ReactNativeClient/lib/database-driver-react-native.js b/ReactNativeClient/lib/database-driver-react-native.js index 43f9b38cdc..0fddc06aa9 100644 --- a/ReactNativeClient/lib/database-driver-react-native.js +++ b/ReactNativeClient/lib/database-driver-react-native.js @@ -3,6 +3,7 @@ import SQLite from 'react-native-sqlite-storage'; class DatabaseDriverReactNative { open(options) { + //SQLite.DEBUG(true); return new Promise((resolve, reject) => { SQLite.openDatabase({ name: options.name }, (db) => { this.db_ = db; @@ -13,6 +14,10 @@ class DatabaseDriverReactNative { }); } + sqliteErrorToJsError(error, sql = null, params = null) { + return error; + } + setDebugMode(v) { //SQLite.DEBUG(v); } diff --git a/ReactNativeClient/lib/database.js b/ReactNativeClient/lib/database.js index 76fe7b48c0..6ab51996c3 100644 --- a/ReactNativeClient/lib/database.js +++ b/ReactNativeClient/lib/database.js @@ -122,12 +122,7 @@ class Database { // so that it prints a stacktrace when passed to // console.error() sqliteErrorToJsError(error, sql = null, params = null) { - let msg = [error.toString()]; - if (sql) msg.push(sql); - if (params) msg.push(params); - let output = new Error(msg.join(': ')); - if (error.code) output.code = error.code; - return output; + return this.driver().sqliteErrorToJsError(error, sql, params); } setLogger(l) { diff --git a/ReactNativeClient/lib/logger.js b/ReactNativeClient/lib/logger.js index fbc630b861..a1f6c2115b 100644 --- a/ReactNativeClient/lib/logger.js +++ b/ReactNativeClient/lib/logger.js @@ -1,5 +1,5 @@ import moment from 'moment'; -import fs from 'fs-extra'; +// import fs from 'fs-extra'; import { _ } from 'lib/locale.js'; class Logger { @@ -67,7 +67,8 @@ class Logger { serializedObject = object; } - fs.appendFileSync(t.path, line + serializedObject + "\n"); + // RNFIX: Temporary disabled for React Native + // fs.appendFileSync(t.path, line + serializedObject + "\n"); // this.fileAppendQueue_.push({ // path: t.path, diff --git a/ReactNativeClient/lib/models/resource.js b/ReactNativeClient/lib/models/resource.js index ee48802060..e61434b53c 100644 --- a/ReactNativeClient/lib/models/resource.js +++ b/ReactNativeClient/lib/models/resource.js @@ -32,17 +32,19 @@ class Resource extends BaseItem { return filename(path); } + // RNFIX: Temporary disabled for React Native + static content(resource) { - // TODO: node-only, and should probably be done with streams - const fs = require('fs-extra'); - return fs.readFile(this.fullPath(resource)); + // // TODO: node-only, and should probably be done with streams + // const fs = require('fs-extra'); + // return fs.readFile(this.fullPath(resource)); } static setContent(resource, content) { - // TODO: node-only, and should probably be done with streams - const fs = require('fs-extra'); - let buffer = new Buffer(content); - return fs.writeFile(this.fullPath(resource), buffer); + // // TODO: node-only, and should probably be done with streams + // const fs = require('fs-extra'); + // let buffer = new Buffer(content); + // return fs.writeFile(this.fullPath(resource), buffer); } } diff --git a/ReactNativeClient/lib/services/note-folder-service.js b/ReactNativeClient/lib/services/note-folder-service.js deleted file mode 100644 index 4848801eeb..0000000000 --- a/ReactNativeClient/lib/services/note-folder-service.js +++ /dev/null @@ -1,29 +0,0 @@ -import { BaseModel } from 'lib/base-model.js'; -import { BaseItem } from 'lib/models/base-item.js'; -import { Note } from 'lib/models/note.js'; -import { Folder } from 'lib/models/folder.js'; -import { Log } from 'lib/log.js'; -import { time } from 'lib/time-utils.js'; - -class NoteFolderService { - - static openNoteList(folderId) { - return Note.previews(folderId).then((notes) => { - this.dispatch({ - type: 'NOTES_UPDATE_ALL', - notes: notes, - }); - - this.dispatch({ - type: 'Navigation/NAVIGATE', - routeName: 'Notes', - folderId: folderId, - }); - }).catch((error) => { - Log.warn('Cannot load notes', error); - }); - } - -} - -export { NoteFolderService }; \ No newline at end of file diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index a679594994..9172b64209 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -13,6 +13,7 @@ import { BaseModel } from 'lib/base-model.js' import { Database } from 'lib/database.js' import { ItemList } from 'lib/components/item-list.js' import { NotesScreen } from 'lib/components/screens/notes.js' +import { NotesScreenUtils } from 'lib/components/screens/notes-utils.js' import { NoteScreen } from 'lib/components/screens/note.js' import { FolderScreen } from 'lib/components/screens/folder.js' import { FoldersScreen } from 'lib/components/screens/folders.js' @@ -23,7 +24,6 @@ import { Synchronizer } from 'lib/synchronizer.js' import { MenuContext } from 'react-native-popup-menu'; import { SideMenu } from 'lib/components/side-menu.js'; import { SideMenuContent } from 'lib/components/side-menu-content.js'; -//import { NoteFolderService } from 'lib/services/note-folder-service.js'; import { DatabaseDriverReactNative } from 'lib/database-driver-react-native'; let defaultState = { @@ -193,38 +193,16 @@ class AppComponent extends React.Component { //db.setDebugMode(false); BaseModel.dispatch = this.props.dispatch; + NotesScreenUtils.dispatch = this.props.dispatch; BaseModel.db_ = db; - //NoteFolderService.dispatch = this.props.dispatch; - db.open({ name: '/storage/emulated/0/Download/joplin-42.sqlite' }).then(() => { + db.open({ name: '/storage/emulated/0/Download/joplin-43.sqlite' }).then(() => { Log.info('Database is ready.'); }).then(() => { Log.info('Loading settings...'); return Setting.load(); }).then(() => { - let user = Setting.object('user'); - - if (!user || !user.session) { - user = { - email: 'laurent@cozic.net', - session: "02d0e9ca42cbbc2d35efb1bc790b9eec", - } - Setting.setObject('user', user); - this.props.dispatch({ - type: 'USER_SET', - user: user, - }); - } - - Setting.setValue('sync.lastRevId', '123456'); - - Log.info('Client ID', Setting.value('clientId')); - Log.info('User', user); - - // this.props.dispatch({ - // type: 'USER_SET', - // user: user, - // }); + Setting.setConstant('appId', 'net.cozic.joplin-android'); Log.info('Loading folders...'); @@ -238,33 +216,10 @@ class AppComponent extends React.Component { Log.warn('Cannot load folders', error); }); }).then((folders) => { - let folder = folders[0]; - - if (!folder) throw new Error('No default folder is defined'); - - //return NoteFolderService.openNoteList(folder.id); - - // this.props.dispatch({ - // type: 'Navigation/NAVIGATE', - // routeName: 'Notes', - // folderId: folder.id, - // }); - }).then(() => { - - var Dropbox = require('dropbox'); - var dropboxApi = new Dropbox({ accessToken: '' }); - // dbx.filesListFolder({path: '/Joplin/Laurent.4e847cc'}) - // .then(function(response) { - // //console.log('DROPBOX RESPONSE', response); - // console.log('DROPBOX RESPONSE', response.entries.length, response.has_more); - // }) - // .catch(function(error) { - // console.log('DROPBOX ERROR', error); - // }); - - // return this.api_; - - + this.props.dispatch({ + type: 'Navigation/NAVIGATE', + routeName: 'Folders', + }); }).catch((error) => { Log.error('Initialization error:', error); });