mirror of
https://github.com/laurent22/joplin.git
synced 2024-12-24 10:27:10 +02:00
Fixed note order in RN
This commit is contained in:
parent
62c9a66c47
commit
93791f1e46
@ -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 });
|
||||
|
@ -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 (
|
||||
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
|
||||
<View style={{flexDirection: 'row', paddingLeft: 10, paddingTop:5, paddingBottom:5 }}>
|
||||
{ !!Number(item.is_todo) && <Checkbox checked={!!Number(item.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(item.id, checked) }}/> }<Text>{item.title}</Text>
|
||||
<Checkbox style={checkboxStyle} checked={checkboxChecked} onChange={(checked) => { this.todoCheckbox_change(item.id, checked) }}/><Text>{item.title}</Text>
|
||||
</View>
|
||||
</TouchableHighlight>
|
||||
);
|
||||
|
@ -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 <ActionButton style={{display:'none'}}/>;
|
||||
|
||||
// let toggled = this.state.mode == 'edit';
|
||||
|
||||
// return <ActionButton isToggle={true} buttons={buttons} toggled={toggled} />
|
||||
// }
|
||||
|
||||
return (
|
||||
<View style={this.styles().screen}>
|
||||
<ScreenHeader navState={this.props.navigation.state} />
|
||||
|
@ -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,
|
||||
|
@ -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'];
|
||||
}
|
||||
|
@ -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;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user