Skip to content

Commit 0d57365

Browse files
committed
DELETE_NOTE
1 parent 52efc23 commit 0d57365

5 files changed

Lines changed: 168 additions & 239 deletions

File tree

browser/main/Detail/MarkdownNoteDetail.js

Lines changed: 65 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,17 @@ import ee from 'browser/main/lib/eventEmitter'
1111

1212
const electron = require('electron')
1313
const { remote } = electron
14-
const Menu = remote.Menu
15-
const MenuItem = remote.MenuItem
14+
const { Menu, MenuItem, dialog } = remote
1615

1716
class MarkdownNoteDetail extends React.Component {
1817
constructor (props) {
1918
super(props)
2019

2120
this.state = {
21+
isMovingNote: false,
2222
note: Object.assign({
2323
title: '',
24-
content: '',
25-
isMovingNote: false,
26-
isDeleting: false
24+
content: ''
2725
}, props.note)
2826
}
2927
this.dispatchTimer = null
@@ -37,8 +35,7 @@ class MarkdownNoteDetail extends React.Component {
3735
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
3836
if (this.saveQueue != null) this.saveNow()
3937
this.setState({
40-
note: Object.assign({}, nextProps.note),
41-
isDeleting: false
38+
note: Object.assign({}, nextProps.note)
4239
}, () => {
4340
this.refs.content.reload()
4441
this.refs.tags.reset()
@@ -188,34 +185,28 @@ class MarkdownNoteDetail extends React.Component {
188185
}
189186

190187
handleDeleteMenuClick (e) {
191-
this.setState({
192-
isDeleting: true
193-
}, () => {
194-
this.refs.deleteConfirmButton.focus()
195-
})
196-
}
197-
198-
handleDeleteConfirmButtonClick (e) {
199-
let { note, dispatch } = this.props
200-
dataApi
201-
.removeNote(note.storage, note.folder, note.key)
202-
.then(() => {
203-
let dispatchHandler = () => {
204-
dispatch({
205-
type: 'REMOVE_NOTE',
206-
note: note
207-
})
208-
}
209-
ee.once('list:moved', dispatchHandler)
210-
ee.emit('list:next')
211-
ee.emit('list:focus')
212-
})
213-
}
214-
215-
handleDeleteCancelButtonClick (e) {
216-
this.setState({
217-
isDeleting: false
188+
let index = dialog.showMessageBox(remote.getCurrentWindow(), {
189+
type: 'warning',
190+
message: 'Delete a note',
191+
detail: 'This work cannot be undone.',
192+
buttons: ['Confirm', 'Cancel']
218193
})
194+
if (index === 0) {
195+
let { note, dispatch } = this.props
196+
dataApi
197+
.deleteNote(note.storage, note.key)
198+
.then((data) => {
199+
let dispatchHandler = () => {
200+
dispatch({
201+
type: 'DELETE_NOTE',
202+
storageKey: data.storageKey,
203+
noteKey: data.noteKey
204+
})
205+
}
206+
ee.once('list:moved', dispatchHandler)
207+
ee.emit('list:next')
208+
})
209+
}
219210
}
220211

221212
handleDeleteKeyDown (e) {
@@ -231,69 +222,50 @@ class MarkdownNoteDetail extends React.Component {
231222
style={this.props.style}
232223
styleName='root'
233224
>
234-
{this.state.isDeleting
235-
? <div styleName='info'>
236-
<div styleName='info-delete'
237-
tabIndex='-1'
238-
onKeyDown={(e) => this.handleDeleteKeyDown(e)}
239-
>
240-
241-
<span styleName='info-delete-message'>
242-
Are you sure to delete this note?
243-
</span>
244-
<button styleName='info-delete-confirmButton'
245-
onClick={(e) => this.handleDeleteConfirmButtonClick(e)}
246-
ref='deleteConfirmButton'
247-
>Confirm</button>
248-
<button styleName='info-delete-cancelButton'
249-
onClick={(e) => this.handleDeleteCancelButtonClick(e)}
250-
>Cancel</button>
251-
</div>
252-
</div>
253-
: <div styleName='info'>
254-
<div styleName='info-left'>
255-
<div styleName='info-left-top'>
256-
<FolderSelect styleName='info-left-top-folderSelect'
257-
value={this.state.note.storage + '-' + this.state.note.folder}
258-
ref='folder'
259-
data={data}
260-
onChange={(e) => this.handleFolderChange(e)}
261-
/>
262-
</div>
263-
<div styleName='info-left-bottom'>
264-
<TagSelect
265-
styleName='info-left-bottom-tagSelect'
266-
ref='tags'
267-
value={this.state.note.tags}
268-
onChange={(e) => this.handleChange(e)}
269-
/>
270-
</div>
225+
<div styleName='info'>
226+
<div styleName='info-left'>
227+
<div styleName='info-left-top'>
228+
<FolderSelect styleName='info-left-top-folderSelect'
229+
value={this.state.note.storage + '-' + this.state.note.folder}
230+
ref='folder'
231+
data={data}
232+
onChange={(e) => this.handleFolderChange(e)}
233+
/>
271234
</div>
272-
<div styleName='info-right'>
273-
<StarButton styleName='info-right-button'
274-
onClick={(e) => this.handleStarButtonClick(e)}
275-
isActive={note.isStarred}
235+
<div styleName='info-left-bottom'>
236+
<TagSelect
237+
styleName='info-left-bottom-tagSelect'
238+
ref='tags'
239+
value={this.state.note.tags}
240+
onChange={(e) => this.handleChange(e)}
276241
/>
277-
<button styleName='info-right-button'
278-
onClick={(e) => this.handleShareButtonClick(e)}
279-
disabled
280-
>
281-
<i className='fa fa-share-alt fa-fw'/>
282-
<span styleName='info-right-button-tooltip'
283-
style={{right: 20}}
284-
>Share Note</span>
285-
</button>
286-
<button styleName='info-right-button'
287-
onClick={(e) => this.handleContextButtonClick(e)}
288-
>
289-
<i className='fa fa-ellipsis-v'/>
290-
<span styleName='info-right-button-tooltip'
291-
style={{right: 5}}
292-
>More Options</span>
293-
</button>
294242
</div>
295243
</div>
296-
}
244+
<div styleName='info-right'>
245+
<StarButton styleName='info-right-button'
246+
onClick={(e) => this.handleStarButtonClick(e)}
247+
isActive={note.isStarred}
248+
/>
249+
<button styleName='info-right-button'
250+
onClick={(e) => this.handleShareButtonClick(e)}
251+
disabled
252+
>
253+
<i className='fa fa-share-alt fa-fw'/>
254+
<span styleName='info-right-button-tooltip'
255+
style={{right: 20}}
256+
>Share Note</span>
257+
</button>
258+
<button styleName='info-right-button'
259+
onClick={(e) => this.handleContextButtonClick(e)}
260+
>
261+
<i className='fa fa-ellipsis-v'/>
262+
<span styleName='info-right-button-tooltip'
263+
style={{right: 5}}
264+
>More Options</span>
265+
</button>
266+
</div>
267+
</div>
268+
297269
<div styleName='body'>
298270
<MarkdownEditor
299271
ref='content'

browser/main/Detail/MarkdownNoteDetail.styl

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,6 @@ $info-height = 75px
1212
border-bottom $ui-border
1313
background-color $ui-backgroundColor
1414

15-
.info-delete
16-
height 80px
17-
display flex
18-
19-
.info-delete-message
20-
height 80px
21-
line-height 80px
22-
padding 0 25px
23-
overflow ellipsis
24-
flex 1
25-
26-
.info-delete-confirmButton
27-
margin 25px 5px 0
28-
width 80px
29-
height 30px
30-
border-radius 2px
31-
border none
32-
colorDangerButton()
33-
34-
.info-delete-cancelButton
35-
width 80px
36-
height 30px
37-
margin 25px 5px 0
38-
border $ui-border
39-
border-radius 2px
40-
color $ui-text-color
41-
colorDefaultButton()
42-
4315
.info-left
4416
float left
4517
padding 0 5px

0 commit comments

Comments
 (0)