diff --git a/ReactNativeClient/lib/components/checkbox.js b/ReactNativeClient/lib/components/checkbox.js index d192fadb1..4942c83b7 100644 --- a/ReactNativeClient/lib/components/checkbox.js +++ b/ReactNativeClient/lib/components/checkbox.js @@ -23,6 +23,12 @@ class Checkbox extends Component { this.state = { checked: this.props.checked }; } + componentWillReceiveProps(newProps) { + if ('checked' in newProps) { + this.setState({ checked: newProps.checked }); + } + } + onPress() { let newChecked = !this.state.checked; this.setState({ checked: newChecked }); diff --git a/ReactNativeClient/lib/components/item-list.js b/ReactNativeClient/lib/components/item-list.js index 21d8bee6f..e3e3edf73 100644 --- a/ReactNativeClient/lib/components/item-list.js +++ b/ReactNativeClient/lib/components/item-list.js @@ -5,6 +5,7 @@ import { Log } from 'lib/log.js'; import { _ } from 'lib/locale.js'; import { Checkbox } from 'lib/components/checkbox.js'; import { Note } from 'lib/models/note.js'; +import { time } from 'lib/time-utils.js'; class ItemListComponent extends Component { @@ -34,7 +35,7 @@ class ItemListComponent extends Component { async todoCheckbox_change(itemId, checked) { let note = await Note.load(itemId); - await Note.save({ id: note.id, todo_completed: checked }); + await Note.save({ id: note.id, todo_completed: checked ? time.unixMs() : 0 }); } listView_itemLongPress(itemId) {} @@ -49,10 +50,15 @@ class ItemListComponent extends Component { this.listView_itemLongPress(item.id); } + const checkboxStyle = {}; + if (!Number(item.is_todo)) checkboxStyle.display = 'none'; + + const checkboxChecked = !!Number(item.todo_completed); + return ( - { !!Number(item.is_todo) && { this.todoCheckbox_change(item.id, checked) }}/> }{item.title} + { this.todoCheckbox_change(item.id, checked) }}/>{item.title} ); diff --git a/ReactNativeClient/lib/components/screens/folder.js b/ReactNativeClient/lib/components/screens/folder.js index 94644a757..f31cd9764 100644 --- a/ReactNativeClient/lib/components/screens/folder.js +++ b/ReactNativeClient/lib/components/screens/folder.js @@ -69,6 +69,25 @@ class FolderScreenComponent extends BaseScreenComponent { } render() { + // const renderActionButton = () => { + // let buttons = []; + + // buttons.push({ + // title: _('Save'), + // icon: 'md-checkmark', + // onPress: () => { + // this.saveFolderButton_press(); + // return false; + // }, + // }); + + // if (this.state.mode == 'edit' && !this.isModified()) return ; + + // let toggled = this.state.mode == 'edit'; + + // return + // } + return ( diff --git a/ReactNativeClient/lib/components/screens/notes-utils.js b/ReactNativeClient/lib/components/screens/notes-utils.js index 9a445b912..c71240e93 100644 --- a/ReactNativeClient/lib/components/screens/notes-utils.js +++ b/ReactNativeClient/lib/components/screens/notes-utils.js @@ -5,7 +5,14 @@ import { Log } from 'lib/log.js' class NotesScreenUtils { static openNoteList(folderId) { - return Note.previews(folderId).then((notes) => { + const state = this.store.getState(); + + let options = { + orderBy: state.notesOrder.orderBy, + orderByDir: state.notesOrder.orderByDir, + }; + + return Note.previews(folderId, options).then((notes) => { this.dispatch({ type: 'NOTES_UPDATE_ALL', notes: notes, diff --git a/ReactNativeClient/lib/models/note.js b/ReactNativeClient/lib/models/note.js index a2459763c..dfec2df7b 100644 --- a/ReactNativeClient/lib/models/note.js +++ b/ReactNativeClient/lib/models/note.js @@ -58,6 +58,15 @@ class Note extends BaseItem { return output; } + static sortNotes(notes, order) { + return notes.sort((a, b) => { + let r = -1; + if (a[order.orderBy] < b[order.orderBy]) r = +1; + if (order.orderByDir == 'ASC') r = -r; + return r; + }); + } + static previewFields() { return ['id', 'title', 'body', 'is_todo', 'todo_completed', 'parent_id', 'updated_time', 'sync_time']; } diff --git a/ReactNativeClient/root.js b/ReactNativeClient/root.js index b59f5d30f..b5e52c517 100644 --- a/ReactNativeClient/root.js +++ b/ReactNativeClient/root.js @@ -44,6 +44,10 @@ let defaultState = { screens: {}, loading: true, historyCanGoBack: false, + notesOrder: { + orderBy: 'updated_time', + orderByDir: 'DESC', + }, }; const initialRoute = { @@ -161,6 +165,7 @@ const reducer = (state = defaultState, action) => { if (!found) newNotes.push(action.note); + newNotes = Note.sortNotes(newNotes, state.notesOrder); newState = Object.assign({}, state); newState.notes = newNotes; break; @@ -288,6 +293,7 @@ async function initialize(dispatch, backButtonHandler) { BaseModel.dispatch = dispatch; NotesScreenUtils.dispatch = dispatch; + NotesScreenUtils.store = store; FoldersScreenUtils.dispatch = dispatch; BaseModel.db_ = db;