mirror of
https://github.com/laurent22/joplin.git
synced 2024-11-27 08:21:03 +02:00
Got RN working again
This commit is contained in:
parent
f0a8cbe95d
commit
8adb5a71c5
@ -6,12 +6,12 @@ import { ItemListComponent } from 'lib/components/item-list.js';
|
|||||||
import { Note } from 'lib/models/note.js';
|
import { Note } from 'lib/models/note.js';
|
||||||
import { Folder } from 'lib/models/folder.js';
|
import { Folder } from 'lib/models/folder.js';
|
||||||
import { _ } from 'lib/locale.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 {
|
class FolderListComponent extends ItemListComponent {
|
||||||
|
|
||||||
listView_itemPress(folderId) {
|
listView_itemPress(folderId) {
|
||||||
NoteFolderService.openNoteList(folderId);
|
NotesScreenUtils.openNoteList(folderId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -4,7 +4,6 @@ import { ListView, Text, TouchableHighlight, Switch, View } from 'react-native';
|
|||||||
import { Log } from 'lib/log.js';
|
import { Log } from 'lib/log.js';
|
||||||
import { _ } from 'lib/locale.js';
|
import { _ } from 'lib/locale.js';
|
||||||
import { Checkbox } from 'lib/components/checkbox.js';
|
import { Checkbox } from 'lib/components/checkbox.js';
|
||||||
import { NoteFolderService } from 'lib/services/note-folder-service.js';
|
|
||||||
import { Note } from 'lib/models/note.js';
|
import { Note } from 'lib/models/note.js';
|
||||||
|
|
||||||
class ItemListComponent extends Component {
|
class ItemListComponent extends Component {
|
||||||
@ -33,14 +32,9 @@ class ItemListComponent extends Component {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
todoCheckbox_change(itemId, checked) {
|
async todoCheckbox_change(itemId, checked) {
|
||||||
NoteFolderService.setField('note', itemId, 'todo_completed', checked);
|
let note = await Note.load(itemId);
|
||||||
|
await Note.save({ id: note.id, todo_completed: checked });
|
||||||
// Note.load(itemId).then((oldNote) => {
|
|
||||||
// let newNote = Object.assign({}, oldNote);
|
|
||||||
// newNote.todo_completed = checked;
|
|
||||||
// return NoteFolderService.save('note', newNote, oldNote);
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
listView_itemPress(itemId) {}
|
listView_itemPress(itemId) {}
|
||||||
|
@ -3,8 +3,8 @@ import { View, Button, TextInput } from 'react-native';
|
|||||||
import { connect } from 'react-redux'
|
import { connect } from 'react-redux'
|
||||||
import { Log } from 'lib/log.js'
|
import { Log } from 'lib/log.js'
|
||||||
import { Folder } from 'lib/models/folder.js'
|
import { Folder } from 'lib/models/folder.js'
|
||||||
|
import { BaseModel } from 'lib/base-model.js'
|
||||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||||
import { NoteFolderService } from 'lib/services/note-folder-service.js';
|
|
||||||
|
|
||||||
class FolderScreenComponent extends React.Component {
|
class FolderScreenComponent extends React.Component {
|
||||||
|
|
||||||
@ -41,18 +41,15 @@ class FolderScreenComponent extends React.Component {
|
|||||||
this.folderComponent_change('title', text);
|
this.folderComponent_change('title', text);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveFolderButton_press() {
|
async saveFolderButton_press() {
|
||||||
console.warn('CHANGE NOT TESTED');
|
let toSave = {
|
||||||
let toSave = BaseModel.diffObjects(this.originalFolder, this.state.folder);
|
title: this.state.folder.title,
|
||||||
toSave.id = this.state.folder.id;
|
};
|
||||||
Folder.save(toSave).then((folder) => {
|
|
||||||
this.originalFolder = Object.assign({}, folder);
|
if (this.originalFolder) toSave.id = this.originalFolder.id;
|
||||||
this.setState({ folder: folder });
|
|
||||||
});
|
this.originalFolder = await Folder.save(toSave);
|
||||||
// NoteFolderService.save('folder', this.state.folder, this.originalFolder).then((folder) => {
|
this.setState({ folder: this.originalFolder });
|
||||||
// this.originalFolder = Object.assign({}, folder);
|
|
||||||
// this.setState({ folder: folder });
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -4,7 +4,6 @@ import { connect } from 'react-redux'
|
|||||||
import { Log } from 'lib/log.js'
|
import { Log } from 'lib/log.js'
|
||||||
import { Folder } from 'lib/models/folder.js'
|
import { Folder } from 'lib/models/folder.js'
|
||||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||||
import { NoteFolderService } from 'lib/services/note-folder-service.js';
|
|
||||||
|
|
||||||
class LoadingScreenComponent extends React.Component {
|
class LoadingScreenComponent extends React.Component {
|
||||||
|
|
||||||
|
@ -5,7 +5,6 @@ import { Log } from 'lib/log.js'
|
|||||||
import { Note } from 'lib/models/note.js'
|
import { Note } from 'lib/models/note.js'
|
||||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||||
import { Checkbox } from 'lib/components/checkbox.js'
|
import { Checkbox } from 'lib/components/checkbox.js'
|
||||||
import { NoteFolderService } from 'lib/services/note-folder-service.js';
|
|
||||||
import { _ } from 'lib/locale.js';
|
import { _ } from 'lib/locale.js';
|
||||||
|
|
||||||
class NoteScreenComponent extends React.Component {
|
class NoteScreenComponent extends React.Component {
|
||||||
@ -17,17 +16,14 @@ class NoteScreenComponent extends React.Component {
|
|||||||
constructor() {
|
constructor() {
|
||||||
super();
|
super();
|
||||||
this.state = { note: Note.new() }
|
this.state = { note: Note.new() }
|
||||||
this.originalNote = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
componentWillMount() {
|
componentWillMount() {
|
||||||
if (!this.props.noteId) {
|
if (!this.props.noteId) {
|
||||||
let note = this.props.itemType == 'todo' ? Note.newTodo(this.props.folderId) : Note.new(this.props.folderId);
|
let note = this.props.itemType == 'todo' ? Note.newTodo(this.props.folderId) : Note.new(this.props.folderId);
|
||||||
Log.info(note);
|
|
||||||
this.setState({ note: note });
|
this.setState({ note: note });
|
||||||
} else {
|
} else {
|
||||||
Note.load(this.props.noteId).then((note) => {
|
Note.load(this.props.noteId).then((note) => {
|
||||||
this.originalNote = Object.assign({}, note);
|
|
||||||
this.setState({ note: note });
|
this.setState({ note: note });
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -49,23 +45,11 @@ class NoteScreenComponent extends React.Component {
|
|||||||
this.noteComponent_change('body', text);
|
this.noteComponent_change('body', text);
|
||||||
}
|
}
|
||||||
|
|
||||||
saveNoteButton_press() {
|
async saveNoteButton_press() {
|
||||||
|
|
||||||
console.warn('CHANGE NOT TESTED');
|
|
||||||
|
|
||||||
let isNew = !this.state.note.id;
|
let isNew = !this.state.note.id;
|
||||||
let toSave = BaseModel.diffObjects(this.originalNote, this.state.note);
|
let note = await Note.save(this.state.note);
|
||||||
toSave.id = this.state.note.id;
|
this.setState({ note: note });
|
||||||
Note.save(toSave).then((note) => {
|
if (isNew) Note.updateGeolocation(note.id);
|
||||||
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 });
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
deleteNote_onPress(noteId) {
|
deleteNote_onPress(noteId) {
|
||||||
|
24
ReactNativeClient/lib/components/screens/notes-utils.js
Normal file
24
ReactNativeClient/lib/components/screens/notes-utils.js
Normal file
@ -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 }
|
@ -2,7 +2,7 @@ import { connect } from 'react-redux'
|
|||||||
import { Button } from 'react-native';
|
import { Button } from 'react-native';
|
||||||
import { Log } from 'lib/log.js';
|
import { Log } from 'lib/log.js';
|
||||||
import { Note } from 'lib/models/note.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 React = require('react');
|
||||||
const {
|
const {
|
||||||
@ -46,7 +46,7 @@ class SideMenuContentComponent extends Component {
|
|||||||
type: 'SIDE_MENU_CLOSE',
|
type: 'SIDE_MENU_CLOSE',
|
||||||
});
|
});
|
||||||
|
|
||||||
NoteFolderService.openNoteList(folder.id);
|
NotesScreenUtils.openNoteList(folder.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -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) {
|
setDebugMode(v) {
|
||||||
// ??
|
// ??
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@ import SQLite from 'react-native-sqlite-storage';
|
|||||||
class DatabaseDriverReactNative {
|
class DatabaseDriverReactNative {
|
||||||
|
|
||||||
open(options) {
|
open(options) {
|
||||||
|
//SQLite.DEBUG(true);
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
SQLite.openDatabase({ name: options.name }, (db) => {
|
SQLite.openDatabase({ name: options.name }, (db) => {
|
||||||
this.db_ = db;
|
this.db_ = db;
|
||||||
@ -13,6 +14,10 @@ class DatabaseDriverReactNative {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sqliteErrorToJsError(error, sql = null, params = null) {
|
||||||
|
return error;
|
||||||
|
}
|
||||||
|
|
||||||
setDebugMode(v) {
|
setDebugMode(v) {
|
||||||
//SQLite.DEBUG(v);
|
//SQLite.DEBUG(v);
|
||||||
}
|
}
|
||||||
|
@ -122,12 +122,7 @@ class Database {
|
|||||||
// so that it prints a stacktrace when passed to
|
// so that it prints a stacktrace when passed to
|
||||||
// console.error()
|
// console.error()
|
||||||
sqliteErrorToJsError(error, sql = null, params = null) {
|
sqliteErrorToJsError(error, sql = null, params = null) {
|
||||||
let msg = [error.toString()];
|
return this.driver().sqliteErrorToJsError(error, sql, params);
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setLogger(l) {
|
setLogger(l) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import fs from 'fs-extra';
|
// import fs from 'fs-extra';
|
||||||
import { _ } from 'lib/locale.js';
|
import { _ } from 'lib/locale.js';
|
||||||
|
|
||||||
class Logger {
|
class Logger {
|
||||||
@ -67,7 +67,8 @@ class Logger {
|
|||||||
serializedObject = object;
|
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({
|
// this.fileAppendQueue_.push({
|
||||||
// path: t.path,
|
// path: t.path,
|
||||||
|
@ -32,17 +32,19 @@ class Resource extends BaseItem {
|
|||||||
return filename(path);
|
return filename(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// RNFIX: Temporary disabled for React Native
|
||||||
|
|
||||||
static content(resource) {
|
static content(resource) {
|
||||||
// TODO: node-only, and should probably be done with streams
|
// // TODO: node-only, and should probably be done with streams
|
||||||
const fs = require('fs-extra');
|
// const fs = require('fs-extra');
|
||||||
return fs.readFile(this.fullPath(resource));
|
// return fs.readFile(this.fullPath(resource));
|
||||||
}
|
}
|
||||||
|
|
||||||
static setContent(resource, content) {
|
static setContent(resource, content) {
|
||||||
// TODO: node-only, and should probably be done with streams
|
// // TODO: node-only, and should probably be done with streams
|
||||||
const fs = require('fs-extra');
|
// const fs = require('fs-extra');
|
||||||
let buffer = new Buffer(content);
|
// let buffer = new Buffer(content);
|
||||||
return fs.writeFile(this.fullPath(resource), buffer);
|
// return fs.writeFile(this.fullPath(resource), buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -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 };
|
|
@ -13,6 +13,7 @@ import { BaseModel } from 'lib/base-model.js'
|
|||||||
import { Database } from 'lib/database.js'
|
import { Database } from 'lib/database.js'
|
||||||
import { ItemList } from 'lib/components/item-list.js'
|
import { ItemList } from 'lib/components/item-list.js'
|
||||||
import { NotesScreen } from 'lib/components/screens/notes.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 { NoteScreen } from 'lib/components/screens/note.js'
|
||||||
import { FolderScreen } from 'lib/components/screens/folder.js'
|
import { FolderScreen } from 'lib/components/screens/folder.js'
|
||||||
import { FoldersScreen } from 'lib/components/screens/folders.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 { MenuContext } from 'react-native-popup-menu';
|
||||||
import { SideMenu } from 'lib/components/side-menu.js';
|
import { SideMenu } from 'lib/components/side-menu.js';
|
||||||
import { SideMenuContent } from 'lib/components/side-menu-content.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';
|
import { DatabaseDriverReactNative } from 'lib/database-driver-react-native';
|
||||||
|
|
||||||
let defaultState = {
|
let defaultState = {
|
||||||
@ -193,38 +193,16 @@ class AppComponent extends React.Component {
|
|||||||
//db.setDebugMode(false);
|
//db.setDebugMode(false);
|
||||||
|
|
||||||
BaseModel.dispatch = this.props.dispatch;
|
BaseModel.dispatch = this.props.dispatch;
|
||||||
|
NotesScreenUtils.dispatch = this.props.dispatch;
|
||||||
BaseModel.db_ = db;
|
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.');
|
Log.info('Database is ready.');
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
Log.info('Loading settings...');
|
Log.info('Loading settings...');
|
||||||
return Setting.load();
|
return Setting.load();
|
||||||
}).then(() => {
|
}).then(() => {
|
||||||
let user = Setting.object('user');
|
Setting.setConstant('appId', 'net.cozic.joplin-android');
|
||||||
|
|
||||||
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,
|
|
||||||
// });
|
|
||||||
|
|
||||||
Log.info('Loading folders...');
|
Log.info('Loading folders...');
|
||||||
|
|
||||||
@ -238,33 +216,10 @@ class AppComponent extends React.Component {
|
|||||||
Log.warn('Cannot load folders', error);
|
Log.warn('Cannot load folders', error);
|
||||||
});
|
});
|
||||||
}).then((folders) => {
|
}).then((folders) => {
|
||||||
let folder = folders[0];
|
this.props.dispatch({
|
||||||
|
type: 'Navigation/NAVIGATE',
|
||||||
if (!folder) throw new Error('No default folder is defined');
|
routeName: 'Folders',
|
||||||
|
});
|
||||||
//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_;
|
|
||||||
|
|
||||||
|
|
||||||
}).catch((error) => {
|
}).catch((error) => {
|
||||||
Log.error('Initialization error:', error);
|
Log.error('Initialization error:', error);
|
||||||
});
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user