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:
parent
e3db1e028a
commit
62c9a66c47
@ -8,6 +8,7 @@ import { BaseModel } from 'lib/base-model.js'
|
||||
import { ActionButton } from 'lib/components/action-button.js';
|
||||
import Icon from 'react-native-vector-icons/Ionicons';
|
||||
import { ScreenHeader } from 'lib/components/screen-header.js';
|
||||
import { time } from 'lib/time-utils.js';
|
||||
import { Checkbox } from 'lib/components/checkbox.js'
|
||||
import { _ } from 'lib/locale.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 isTodo = !!Number(note.is_todo);
|
||||
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;
|
||||
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)} />
|
||||
</View>
|
||||
{ bodyComponent }
|
||||
{ todoComponents }
|
||||
{ actionButtonComp }
|
||||
{ this.state.showNoteMetadata && <Text>{this.state.noteMetadata}</Text> }
|
||||
<DialogBox ref={dialogbox => { this.dialogbox = dialogbox }}/>
|
||||
|
@ -57,6 +57,13 @@ defaultState.route = initialRoute;
|
||||
let navHistory = [];
|
||||
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) => {
|
||||
reg.logger().info('Reducer action', action.type);
|
||||
|
||||
@ -72,6 +79,16 @@ const reducer = (state = defaultState, action) => {
|
||||
action = navHistory.pop(); // Current 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
|
||||
|
||||
case 'Navigation/NAVIGATE':
|
||||
@ -248,7 +265,7 @@ async function initialize(dispatch, backButtonHandler) {
|
||||
|
||||
const mainLogger = new Logger();
|
||||
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);
|
||||
|
||||
reg.setLogger(mainLogger);
|
||||
@ -258,8 +275,12 @@ async function initialize(dispatch, backButtonHandler) {
|
||||
|
||||
const dbLogger = new Logger();
|
||||
dbLogger.addTarget('database', { database: logDatabase, source: 'm' });
|
||||
if (Setting.value('env') == 'env') dbLogger.addTarget('console');
|
||||
dbLogger.setLevel(Logger.LEVEL_INFO);
|
||||
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);
|
||||
}
|
||||
|
||||
let db = new JoplinDatabase(new DatabaseDriverReactNative());
|
||||
db.setLogger(dbLogger);
|
||||
|
Loading…
Reference in New Issue
Block a user