1
0
mirror of https://github.com/laurent22/joplin.git synced 2025-11-29 22:48:10 +02:00

Got RN working again

This commit is contained in:
Laurent Cozic
2017-07-05 22:29:00 +01:00
parent f0a8cbe95d
commit 8adb5a71c5
14 changed files with 80 additions and 144 deletions

View File

@@ -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);
}
}

View File

@@ -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) {}

View File

@@ -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() {

View File

@@ -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 {

View File

@@ -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) {

View 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 }

View File

@@ -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() {