1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 17:56:25 +00:00

right click to delete a note

This commit is contained in:
Dick Choi
2016-09-10 14:25:45 +09:00
parent 2b85aa1b88
commit 9f4dd909a8

View File

@@ -4,6 +4,10 @@ import styles from './NoteList.styl'
import moment from 'moment' import moment from 'moment'
import _ from 'lodash' import _ from 'lodash'
import ee from 'browser/main/lib/eventEmitter' import ee from 'browser/main/lib/eventEmitter'
import dataApi from 'browser/main/lib/dataApi'
const { remote } = require('electron')
const { Menu, MenuItem, dialog } = remote
class NoteList extends React.Component { class NoteList extends React.Component {
constructor (props) { constructor (props) {
@@ -213,17 +217,58 @@ class NoteList extends React.Component {
: [] : []
} }
handleNoteClick (uniqueKey) { handleNoteClick (e, uniqueKey) {
return (e) => { let { router } = this.context
let { router } = this.context let { location } = this.props
let { location } = this.props
router.push({ router.push({
pathname: location.pathname, pathname: location.pathname,
query: { query: {
key: uniqueKey key: uniqueKey
} }
}) })
}
handleNoteContextMenu (e, uniqueKey) {
let menu = new Menu()
menu.append(new MenuItem({
label: 'Delete Note',
click: (e) => this.handleDeleteNote(e, uniqueKey)
}))
menu.popup()
}
handleDeleteNote (e, uniqueKey) {
let index = dialog.showMessageBox(remote.getCurrentWindow(), {
type: 'warning',
message: 'Delete a note',
detail: 'This work cannot be undone.',
buttons: ['Confirm', 'Cancel']
})
if (index === 0) {
let { dispatch, location } = this.props
let splitted = uniqueKey.split('-')
let storageKey = splitted.shift()
let noteKey = splitted.shift()
dataApi
.deleteNote(storageKey, noteKey)
.then((data) => {
let dispatchHandler = () => {
dispatch({
type: 'DELETE_NOTE',
storageKey: data.storageKey,
noteKey: data.noteKey
})
}
if (location.query.key === uniqueKey) {
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
} else {
dispatchHandler()
}
})
} }
} }
@@ -254,7 +299,8 @@ class NoteList extends React.Component {
: 'item' : 'item'
} }
key={note.storage + '-' + note.key} key={note.storage + '-' + note.key}
onClick={(e) => this.handleNoteClick(note.storage + '-' + note.key)(e)} onClick={(e) => this.handleNoteClick(e, note.storage + '-' + note.key)}
onContextMenu={(e) => this.handleNoteContextMenu(e, note.storage + '-' + note.key)}
> >
<div styleName='item-border'/> <div styleName='item-border'/>
<div styleName='item-info'> <div styleName='item-info'>