2017-11-04 18:40:34 +02:00
|
|
|
const { ItemList } = require('./ItemList.min.js');
|
2017-11-05 02:17:48 +02:00
|
|
|
const React = require('react');
|
|
|
|
const { connect } = require('react-redux');
|
2017-11-04 18:40:34 +02:00
|
|
|
|
|
|
|
class NoteListComponent extends React.Component {
|
|
|
|
|
|
|
|
itemRenderer(index, item) {
|
2017-11-05 20:36:27 +02:00
|
|
|
const onClick = (item) => {
|
2017-11-05 01:27:13 +02:00
|
|
|
this.props.dispatch({
|
|
|
|
type: 'NOTES_SELECT',
|
|
|
|
noteId: item.id,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-11-04 18:40:34 +02:00
|
|
|
let classes = ['item'];
|
|
|
|
classes.push(index % 2 === 0 ? 'even' : 'odd');
|
2017-11-06 01:55:01 +02:00
|
|
|
if (this.props.selectedNoteId === item.id) classes.push('selected');
|
2017-11-05 20:36:27 +02:00
|
|
|
return <div onClick={() => { onClick(item) }} className={classes.join(' ')} key={index}>{item.title + ' ' + item.id.substr(0,4)}</div>
|
2017-11-04 18:40:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
return (
|
2017-11-04 21:46:37 +02:00
|
|
|
<ItemList
|
|
|
|
itemHeight={this.props.itemHeight}
|
|
|
|
style={this.props.style}
|
|
|
|
className={"note-list"}
|
|
|
|
items={this.props.notes}
|
|
|
|
itemRenderer={ (index, item) => { return this.itemRenderer(index, item) } }
|
2017-11-05 01:27:13 +02:00
|
|
|
></ItemList>
|
2017-11-04 18:40:34 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
const mapStateToProps = (state) => {
|
|
|
|
return {
|
2017-11-05 01:27:13 +02:00
|
|
|
notes: state.notes,
|
2017-11-06 01:55:01 +02:00
|
|
|
selectedNoteId: state.selectedNoteId,
|
2017-11-04 18:40:34 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
const NoteList = connect(mapStateToProps)(NoteListComponent);
|
|
|
|
|
|
|
|
module.exports = { NoteList };
|