1
0
mirror of https://github.com/laurent22/joplin.git synced 2024-12-12 08:54:00 +02:00
joplin/ElectronClient/app/gui/NoteList.jsx

70 lines
1.9 KiB
React
Raw Normal View History

2017-11-04 18:40:34 +02:00
const { ItemList } = require('./ItemList.min.js');
const React = require('react');
const { connect } = require('react-redux');
2017-11-08 19:51:55 +02:00
const { themeStyle } = require('../theme.js');
const { _ } = require('lib/locale.js');
const { bridge } = require('electron').remote.require('./bridge');
const Menu = bridge().Menu;
const MenuItem = bridge().MenuItem;
2017-11-04 18:40:34 +02:00
class NoteListComponent extends React.Component {
2017-11-08 19:51:55 +02:00
itemContextMenu(event) {
const noteId = event.target.getAttribute('data-id');
if (!noteId) throw new Error('No data-id on element');
const menu = new Menu()
2017-11-08 23:22:24 +02:00
menu.append(new MenuItem({label: _('Delete'), click: async () => {
2017-11-08 19:51:55 +02:00
const ok = bridge().showConfirmMessageBox(_('Delete note?'));
if (!ok) return;
await Note.delete(noteId);
}}))
menu.popup(bridge().window());
}
itemRenderer(index, item, theme) {
2017-11-05 20:36:27 +02:00
const onClick = (item) => {
2017-11-05 01:27:13 +02:00
this.props.dispatch({
2017-11-08 23:22:24 +02:00
type: 'NOTE_SELECT',
id: item.id,
2017-11-05 01:27:13 +02:00
});
}
2017-11-08 19:51:55 +02:00
const style = {
height: this.props.itemHeight,
display: 'block',
cursor: 'pointer',
backgroundColor: index % 2 === 0 ? theme.backgroundColor : theme.oddBackgroundColor,
fontWeight: this.props.selectedNoteId === item.id ? 'bold' : 'normal',
};
return <a data-id={item.id} onContextMenu={(event) => this.itemContextMenu(event)} href="#" style={style} onClick={() => { onClick(item) }} key={index}>{item.title}</a>
2017-11-04 18:40:34 +02:00
}
render() {
2017-11-08 19:51:55 +02:00
const theme = themeStyle(this.props.theme);
2017-11-04 18:40:34 +02:00
return (
<ItemList
itemHeight={this.props.itemHeight}
style={this.props.style}
className={"note-list"}
items={this.props.notes}
2017-11-08 19:51:55 +02:00
itemRenderer={ (index, item) => { return this.itemRenderer(index, item, theme) } }
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-08 19:51:55 +02:00
theme: state.settings.theme,
2017-11-04 18:40:34 +02:00
};
};
const NoteList = connect(mapStateToProps)(NoteListComponent);
module.exports = { NoteList };