1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-24 10:27:10 +02:00

Better handling of todos in RN

This commit is contained in:
Laurent Cozic 2017-07-15 18:08:54 +01:00
parent e3db1e028a
commit 62c9a66c47
2 changed files with 41 additions and 14 deletions

View File

@ -8,6 +8,7 @@ import { BaseModel } from 'lib/base-model.js'
import { ActionButton } from 'lib/components/action-button.js'; import { ActionButton } from 'lib/components/action-button.js';
import Icon from 'react-native-vector-icons/Ionicons'; import Icon from 'react-native-vector-icons/Ionicons';
import { ScreenHeader } from 'lib/components/screen-header.js'; import { ScreenHeader } from 'lib/components/screen-header.js';
import { time } from 'lib/time-utils.js';
import { Checkbox } from 'lib/components/checkbox.js' import { Checkbox } from 'lib/components/checkbox.js'
import { _ } from 'lib/locale.js'; import { _ } from 'lib/locale.js';
import marked from 'lib/marked.js'; import marked from 'lib/marked.js';
@ -179,7 +180,22 @@ class NoteScreenComponent extends BaseScreenComponent {
]; ];
} }
todoCheckbox_change(checked) { async todoCheckbox_change(checked) {
let note = Object.assign({}, this.state.note);
const todoCompleted = checked ? time.unixMs() : 0;
if (note.id) {
note = await Note.save({ id: note.id, todo_completed: todoCompleted });
this.setState({
lastSavedNote: Object.assign({}, note),
note: note,
});
} else {
note.todo_completed = todoCompleted;
this.setState({ note: note });
}
} }
@ -187,15 +203,6 @@ class NoteScreenComponent extends BaseScreenComponent {
const note = this.state.note; const note = this.state.note;
const isTodo = !!Number(note.is_todo); const isTodo = !!Number(note.is_todo);
const folder = this.state.folder; const folder = this.state.folder;
let todoComponents = null;
if (note.is_todo) {
todoComponents = (
<View>
<Button title="test" onPress={this.saveNoteButton_press} />
</View>
);
}
let bodyComponent = null; let bodyComponent = null;
if (this.state.mode == 'view') { if (this.state.mode == 'view') {
@ -305,7 +312,6 @@ class NoteScreenComponent extends BaseScreenComponent {
{ isTodo && <Checkbox checked={!!Number(note.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(checked) }} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={(text) => this.title_changeText(text)} /> { isTodo && <Checkbox checked={!!Number(note.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(checked) }} /> }<TextInput style={{flex:1}} value={note.title} onChangeText={(text) => this.title_changeText(text)} />
</View> </View>
{ bodyComponent } { bodyComponent }
{ todoComponents }
{ actionButtonComp } { actionButtonComp }
{ this.state.showNoteMetadata && <Text>{this.state.noteMetadata}</Text> } { this.state.showNoteMetadata && <Text>{this.state.noteMetadata}</Text> }
<DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/> <DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>

View File

@ -57,6 +57,13 @@ defaultState.route = initialRoute;
let navHistory = []; let navHistory = [];
navHistory.push(initialRoute); navHistory.push(initialRoute);
function historyCanGoBackTo(route) {
if (route.routeName == 'Note' && !route.noteId) return false;
if (route.routeName == 'Folder' && !route.folderId) return false;
return true;
}
const reducer = (state = defaultState, action) => { const reducer = (state = defaultState, action) => {
reg.logger().info('Reducer action', action.type); reg.logger().info('Reducer action', action.type);
@ -72,6 +79,16 @@ const reducer = (state = defaultState, action) => {
action = navHistory.pop(); // Current page action = navHistory.pop(); // Current page
action = navHistory.pop(); // Previous page action = navHistory.pop(); // Previous page
while (!historyCanGoBackTo(action)) {
if (!navHistory.length) {
action = null;
break;
}
action = navHistory.pop();
}
if (!action) action = Object.assign({}, initialRoute);
// Fall throught // Fall throught
case 'Navigation/NAVIGATE': case 'Navigation/NAVIGATE':
@ -248,7 +265,7 @@ async function initialize(dispatch, backButtonHandler) {
const mainLogger = new Logger(); const mainLogger = new Logger();
mainLogger.addTarget('database', { database: logDatabase, source: 'm' }); mainLogger.addTarget('database', { database: logDatabase, source: 'm' });
if (Setting.value('env') == 'env') mainLogger.addTarget('console'); if (Setting.value('env') == 'dev') mainLogger.addTarget('console');
mainLogger.setLevel(Logger.LEVEL_DEBUG); mainLogger.setLevel(Logger.LEVEL_DEBUG);
reg.setLogger(mainLogger); reg.setLogger(mainLogger);
@ -258,8 +275,12 @@ async function initialize(dispatch, backButtonHandler) {
const dbLogger = new Logger(); const dbLogger = new Logger();
dbLogger.addTarget('database', { database: logDatabase, source: 'm' }); dbLogger.addTarget('database', { database: logDatabase, source: 'm' });
if (Setting.value('env') == 'env') dbLogger.addTarget('console'); if (Setting.value('env') == 'dev') dbLogger.addTarget('console');
if (Setting.value('env') == 'dev') {
dbLogger.setLevel(Logger.LEVEL_DEBUG); // Set to LEVEL_DEBUG for full SQL queries
} else {
dbLogger.setLevel(Logger.LEVEL_INFO); dbLogger.setLevel(Logger.LEVEL_INFO);
}
let db = new JoplinDatabase(new DatabaseDriverReactNative()); let db = new JoplinDatabase(new DatabaseDriverReactNative());
db.setLogger(dbLogger); db.setLogger(dbLogger);