1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-15 09:04:04 +02:00
joplin/ReactNativeClient/lib/components/item-list.js

77 lines
2.2 KiB
JavaScript
Raw Normal View History

2017-05-09 22:46:54 +02:00
import React, { Component } from 'react';
import { connect } from 'react-redux'
2017-05-16 21:12:37 +02:00
import { ListView, Text, TouchableHighlight, Switch, View } from 'react-native';
2017-06-24 20:06:28 +02:00
import { Log } from 'lib/log.js';
import { _ } from 'lib/locale.js';
import { Checkbox } from 'lib/components/checkbox.js';
import { NoteFolderService } from 'lib/services/note-folder-service.js';
import { Note } from 'lib/models/note.js';
2017-05-09 22:46:54 +02:00
class ItemListComponent extends Component {
constructor() {
super();
2017-05-15 22:50:14 +02:00
const ds = new ListView.DataSource({
rowHasChanged: (r1, r2) => { return r1 !== r2; }
});
this.state = {
dataSource: ds,
items: [],
selectedItemIds: [],
};
2017-05-09 22:46:54 +02:00
}
2017-05-16 21:12:37 +02:00
componentWillMount() {
const newDataSource = this.state.dataSource.cloneWithRows(this.props.items);
this.state = { dataSource: newDataSource };
}
2017-05-09 22:46:54 +02:00
componentWillReceiveProps(newProps) {
// https://stackoverflow.com/questions/38186114/react-native-redux-and-listview
2017-05-15 22:50:14 +02:00
this.setState({
2017-05-24 22:18:09 +02:00
dataSource: this.state.dataSource.cloneWithRows(newProps.items),
2017-05-15 22:50:14 +02:00
});
}
2017-05-15 21:46:34 +02:00
todoCheckbox_change(itemId, checked) {
NoteFolderService.setField('note', itemId, 'todo_completed', checked);
// Note.load(itemId).then((oldNote) => {
// let newNote = Object.assign({}, oldNote);
// newNote.todo_completed = checked;
// return NoteFolderService.save('note', newNote, oldNote);
// });
2017-05-24 22:51:50 +02:00
}
2017-06-06 22:01:43 +02:00
listView_itemPress(itemId) {}
2017-05-15 22:50:14 +02:00
2017-05-09 22:46:54 +02:00
render() {
2017-05-15 22:50:14 +02:00
let renderRow = (item) => {
2017-05-09 22:46:54 +02:00
let onPress = () => {
2017-05-15 22:50:14 +02:00
this.listView_itemPress(item.id);
}
let onLongPress = () => {
this.listView_itemLongPress(item.id);
2017-05-09 22:46:54 +02:00
}
2017-05-24 22:51:50 +02:00
2017-05-09 22:46:54 +02:00
return (
2017-05-15 22:50:14 +02:00
<TouchableHighlight onPress={onPress} onLongPress={onLongPress}>
2017-05-24 22:51:50 +02:00
<View style={{flexDirection: 'row'}}>
{ !!Number(item.is_todo) && <Checkbox checked={!!Number(item.todo_completed)} onChange={(checked) => { this.todoCheckbox_change(item.id, checked) }}/> }<Text>{item.title} [{item.id}]</Text>
2017-05-16 21:12:37 +02:00
</View>
2017-05-09 22:46:54 +02:00
</TouchableHighlight>
);
}
2017-05-12 21:54:06 +02:00
// `enableEmptySections` is to fix this warning: https://github.com/FaridSafi/react-native-gifted-listview/issues/39
2017-05-09 22:46:54 +02:00
return (
<ListView
dataSource={this.state.dataSource}
renderRow={renderRow}
2017-05-12 21:54:06 +02:00
enableEmptySections={true}
2017-05-09 22:46:54 +02:00
/>
);
}
}
2017-05-15 21:10:00 +02:00
export { ItemListComponent };