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 { 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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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) {}
|
||||
|
@ -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() {
|
||||
|
@ -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 {
|
||||
|
||||
|
@ -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) {
|
||||
|
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 { 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() {
|
||||
|
@ -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) {
|
||||
// ??
|
||||
}
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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) {
|
||||
|
@ -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,
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -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 { 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);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user