You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-09-16 08:56:40 +02:00
Fixed note order in RN
This commit is contained in:
@@ -23,6 +23,12 @@ class Checkbox extends Component {
|
|||||||
this.state = { checked: this.props.checked };
|
this.state = { checked: this.props.checked };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
componentWillReceiveProps(newProps) {
|
||||||
|
if ('checked' in newProps) {
|
||||||
|
this.setState({ checked: newProps.checked });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
onPress() {
|
onPress() {
|
||||||
let newChecked = !this.state.checked;
|
let newChecked = !this.state.checked;
|
||||||
this.setState({ checked: newChecked });
|
this.setState({ checked: newChecked });
|
||||||
|
@@ -5,6 +5,7 @@ import { Log } from 'lib/log.js';
|
|||||||
import { _ } from 'lib/locale.js';
|
import { _ } from 'lib/locale.js';
|
||||||
import { Checkbox } from 'lib/components/checkbox.js';
|
import { Checkbox } from 'lib/components/checkbox.js';
|
||||||
import { Note } from 'lib/models/note.js';
|
import { Note } from 'lib/models/note.js';
|
||||||
|
import { time } from 'lib/time-utils.js';
|
||||||
|
|
||||||
class ItemListComponent extends Component {
|
class ItemListComponent extends Component {
|
||||||
|
|
||||||
@@ -34,7 +35,7 @@ class ItemListComponent extends Component {
|
|||||||
|
|
||||||
async todoCheckbox_change(itemId, checked) {
|
async todoCheckbox_change(itemId, checked) {
|
||||||
let note = await Note.load(itemId);
|
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) {}
|
listView_itemLongPress(itemId) {}
|
||||||
@@ -49,10 +50,15 @@ class ItemListComponent extends Component {
|
|||||||
this.listView_itemLongPress(item.id);
|
this.listView_itemLongPress(item.id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const checkboxStyle = {};
|
||||||
|
if (!Number(item.is_todo)) checkboxStyle.display = 'none';
|
||||||
|
|
||||||
|
const checkboxChecked = !!Number(item.todo_completed);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
|
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
|
||||||
<View style={{flexDirection: 'row', paddingLeft: 10, paddingTop:5, paddingBottom:5 }}>
|
<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>
|
</View>
|
||||||
</TouchableHighlight>
|
</TouchableHighlight>
|
||||||
);
|
);
|
||||||
|
@@ -69,6 +69,25 @@ class FolderScreenComponent extends BaseScreenComponent {
|
|||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
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 (
|
return (
|
||||||
<View style={this.styles().screen}>
|
<View style={this.styles().screen}>
|
||||||
<ScreenHeader navState={this.props.navigation.state} />
|
<ScreenHeader navState={this.props.navigation.state} />
|
||||||
|
@@ -5,7 +5,14 @@ import { Log } from 'lib/log.js'
|
|||||||
class NotesScreenUtils {
|
class NotesScreenUtils {
|
||||||
|
|
||||||
static openNoteList(folderId) {
|
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({
|
this.dispatch({
|
||||||
type: 'NOTES_UPDATE_ALL',
|
type: 'NOTES_UPDATE_ALL',
|
||||||
notes: notes,
|
notes: notes,
|
||||||
|
@@ -58,6 +58,15 @@ class Note extends BaseItem {
|
|||||||
return output;
|
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() {
|
static previewFields() {
|
||||||
return ['id', 'title', 'body', 'is_todo', 'todo_completed', 'parent_id', 'updated_time', 'sync_time'];
|
return ['id', 'title', 'body', 'is_todo', 'todo_completed', 'parent_id', 'updated_time', 'sync_time'];
|
||||||
}
|
}
|
||||||
|
@@ -44,6 +44,10 @@ let defaultState = {
|
|||||||
screens: {},
|
screens: {},
|
||||||
loading: true,
|
loading: true,
|
||||||
historyCanGoBack: false,
|
historyCanGoBack: false,
|
||||||
|
notesOrder: {
|
||||||
|
orderBy: 'updated_time',
|
||||||
|
orderByDir: 'DESC',
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
const initialRoute = {
|
const initialRoute = {
|
||||||
@@ -161,6 +165,7 @@ const reducer = (state = defaultState, action) => {
|
|||||||
|
|
||||||
if (!found) newNotes.push(action.note);
|
if (!found) newNotes.push(action.note);
|
||||||
|
|
||||||
|
newNotes = Note.sortNotes(newNotes, state.notesOrder);
|
||||||
newState = Object.assign({}, state);
|
newState = Object.assign({}, state);
|
||||||
newState.notes = newNotes;
|
newState.notes = newNotes;
|
||||||
break;
|
break;
|
||||||
@@ -288,6 +293,7 @@ async function initialize(dispatch, backButtonHandler) {
|
|||||||
|
|
||||||
BaseModel.dispatch = dispatch;
|
BaseModel.dispatch = dispatch;
|
||||||
NotesScreenUtils.dispatch = dispatch;
|
NotesScreenUtils.dispatch = dispatch;
|
||||||
|
NotesScreenUtils.store = store;
|
||||||
FoldersScreenUtils.dispatch = dispatch;
|
FoldersScreenUtils.dispatch = dispatch;
|
||||||
BaseModel.db_ = db;
|
BaseModel.db_ = db;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user