1
0
mirror of https://github.com/BoostIo/Boostnote synced 2025-12-13 09:46:22 +00:00

DELETE_NOTE

This commit is contained in:
Dick Choi
2016-09-01 00:02:16 +09:00
parent 52efc23984
commit 0d573651a3
5 changed files with 170 additions and 241 deletions

View File

@@ -11,19 +11,17 @@ import ee from 'browser/main/lib/eventEmitter'
const electron = require('electron') const electron = require('electron')
const { remote } = electron const { remote } = electron
const Menu = remote.Menu const { Menu, MenuItem, dialog } = remote
const MenuItem = remote.MenuItem
class MarkdownNoteDetail extends React.Component { class MarkdownNoteDetail extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
this.state = { this.state = {
isMovingNote: false,
note: Object.assign({ note: Object.assign({
title: '', title: '',
content: '', content: ''
isMovingNote: false,
isDeleting: false
}, props.note) }, props.note)
} }
this.dispatchTimer = null this.dispatchTimer = null
@@ -37,8 +35,7 @@ class MarkdownNoteDetail extends React.Component {
if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) { if (nextProps.note.key !== this.props.note.key && !this.isMovingNote) {
if (this.saveQueue != null) this.saveNow() if (this.saveQueue != null) this.saveNow()
this.setState({ this.setState({
note: Object.assign({}, nextProps.note), note: Object.assign({}, nextProps.note)
isDeleting: false
}, () => { }, () => {
this.refs.content.reload() this.refs.content.reload()
this.refs.tags.reset() this.refs.tags.reset()
@@ -188,34 +185,28 @@ class MarkdownNoteDetail extends React.Component {
} }
handleDeleteMenuClick (e) { handleDeleteMenuClick (e) {
this.setState({ let index = dialog.showMessageBox(remote.getCurrentWindow(), {
isDeleting: true type: 'warning',
}, () => { message: 'Delete a note',
this.refs.deleteConfirmButton.focus() detail: 'This work cannot be undone.',
}) buttons: ['Confirm', 'Cancel']
}
handleDeleteConfirmButtonClick (e) {
let { note, dispatch } = this.props
dataApi
.removeNote(note.storage, note.folder, note.key)
.then(() => {
let dispatchHandler = () => {
dispatch({
type: 'REMOVE_NOTE',
note: note
})
}
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
ee.emit('list:focus')
})
}
handleDeleteCancelButtonClick (e) {
this.setState({
isDeleting: false
}) })
if (index === 0) {
let { note, dispatch } = this.props
dataApi
.deleteNote(note.storage, note.key)
.then((data) => {
let dispatchHandler = () => {
dispatch({
type: 'DELETE_NOTE',
storageKey: data.storageKey,
noteKey: data.noteKey
})
}
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
})
}
} }
handleDeleteKeyDown (e) { handleDeleteKeyDown (e) {
@@ -231,69 +222,50 @@ class MarkdownNoteDetail extends React.Component {
style={this.props.style} style={this.props.style}
styleName='root' styleName='root'
> >
{this.state.isDeleting <div styleName='info'>
? <div styleName='info'> <div styleName='info-left'>
<div styleName='info-delete' <div styleName='info-left-top'>
tabIndex='-1' <FolderSelect styleName='info-left-top-folderSelect'
onKeyDown={(e) => this.handleDeleteKeyDown(e)} value={this.state.note.storage + '-' + this.state.note.folder}
> ref='folder'
data={data}
<span styleName='info-delete-message'> onChange={(e) => this.handleFolderChange(e)}
Are you sure to delete this note? />
</span> </div>
<button styleName='info-delete-confirmButton' <div styleName='info-left-bottom'>
onClick={(e) => this.handleDeleteConfirmButtonClick(e)} <TagSelect
ref='deleteConfirmButton' styleName='info-left-bottom-tagSelect'
>Confirm</button> ref='tags'
<button styleName='info-delete-cancelButton' value={this.state.note.tags}
onClick={(e) => this.handleDeleteCancelButtonClick(e)} onChange={(e) => this.handleChange(e)}
>Cancel</button>
</div>
</div>
: <div styleName='info'>
<div styleName='info-left'>
<div styleName='info-left-top'>
<FolderSelect styleName='info-left-top-folderSelect'
value={this.state.note.storage + '-' + this.state.note.folder}
ref='folder'
data={data}
onChange={(e) => this.handleFolderChange(e)}
/>
</div>
<div styleName='info-left-bottom'>
<TagSelect
styleName='info-left-bottom-tagSelect'
ref='tags'
value={this.state.note.tags}
onChange={(e) => this.handleChange(e)}
/>
</div>
</div>
<div styleName='info-right'>
<StarButton styleName='info-right-button'
onClick={(e) => this.handleStarButtonClick(e)}
isActive={note.isStarred}
/> />
<button styleName='info-right-button'
onClick={(e) => this.handleShareButtonClick(e)}
disabled
>
<i className='fa fa-share-alt fa-fw'/>
<span styleName='info-right-button-tooltip'
style={{right: 20}}
>Share Note</span>
</button>
<button styleName='info-right-button'
onClick={(e) => this.handleContextButtonClick(e)}
>
<i className='fa fa-ellipsis-v'/>
<span styleName='info-right-button-tooltip'
style={{right: 5}}
>More Options</span>
</button>
</div> </div>
</div> </div>
} <div styleName='info-right'>
<StarButton styleName='info-right-button'
onClick={(e) => this.handleStarButtonClick(e)}
isActive={note.isStarred}
/>
<button styleName='info-right-button'
onClick={(e) => this.handleShareButtonClick(e)}
disabled
>
<i className='fa fa-share-alt fa-fw'/>
<span styleName='info-right-button-tooltip'
style={{right: 20}}
>Share Note</span>
</button>
<button styleName='info-right-button'
onClick={(e) => this.handleContextButtonClick(e)}
>
<i className='fa fa-ellipsis-v'/>
<span styleName='info-right-button-tooltip'
style={{right: 5}}
>More Options</span>
</button>
</div>
</div>
<div styleName='body'> <div styleName='body'>
<MarkdownEditor <MarkdownEditor
ref='content' ref='content'

View File

@@ -12,34 +12,6 @@ $info-height = 75px
border-bottom $ui-border border-bottom $ui-border
background-color $ui-backgroundColor background-color $ui-backgroundColor
.info-delete
height 80px
display flex
.info-delete-message
height 80px
line-height 80px
padding 0 25px
overflow ellipsis
flex 1
.info-delete-confirmButton
margin 25px 5px 0
width 80px
height 30px
border-radius 2px
border none
colorDangerButton()
.info-delete-cancelButton
width 80px
height 30px
margin 25px 5px 0
border $ui-border
border-radius 2px
color $ui-text-color
colorDefaultButton()
.info-left .info-left
float left float left
padding 0 5px padding 0 5px

View File

@@ -24,21 +24,20 @@ function detectModeByFilename (filename) {
const electron = require('electron') const electron = require('electron')
const { remote } = electron const { remote } = electron
const Menu = remote.Menu const { Menu, MenuItem, dialog } = remote
const MenuItem = remote.MenuItem
class SnippetNoteDetail extends React.Component { class SnippetNoteDetail extends React.Component {
constructor (props) { constructor (props) {
super(props) super(props)
this.state = { this.state = {
isMovingNote: false,
snippetIndex: 0, snippetIndex: 0,
note: Object.assign({ note: Object.assign({
description: '' description: ''
}, props.note, { }, props.note, {
snippets: props.note.snippets.map((snippet) => Object.assign({}, snippet)) snippets: props.note.snippets.map((snippet) => Object.assign({}, snippet))
}), })
isDeleting: false
} }
} }
@@ -56,8 +55,7 @@ class SnippetNoteDetail extends React.Component {
}) })
this.setState({ this.setState({
snippetIndex: 0, snippetIndex: 0,
note: nextNote, note: nextNote
isDeleting: false
}, () => { }, () => {
let { snippets } = this.state.note let { snippets } = this.state.note
snippets.forEach((snippet, index) => { snippets.forEach((snippet, index) => {
@@ -211,33 +209,28 @@ class SnippetNoteDetail extends React.Component {
} }
handleDeleteMenuClick (e) { handleDeleteMenuClick (e) {
this.setState({ let index = dialog.showMessageBox(remote.getCurrentWindow(), {
isDeleting: true type: 'warning',
}, () => { message: 'Delete a note',
this.refs.deleteConfirmButton.focus() detail: 'This work cannot be undone.',
}) buttons: ['Confirm', 'Cancel']
}
handleDeleteConfirmButtonClick (e) {
let { note, dispatch } = this.props
dataApi
.removeNote(note.storage, note.folder, note.key)
.then(() => {
let dispatchHandler = () => {
dispatch({
type: 'REMOVE_NOTE',
note: note
})
}
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
})
}
handleDeleteCancelButtonClick (e) {
this.setState({
isDeleting: false
}) })
if (index === 0) {
let { note, dispatch } = this.props
dataApi
.deleteNote(note.storage, note.key)
.then((data) => {
let dispatchHandler = () => {
dispatch({
type: 'DELETE_NOTE',
storageKey: data.storageKey,
noteKey: data.noteKey
})
}
ee.once('list:moved', dispatchHandler)
ee.emit('list:next')
})
}
} }
handleTabPlusButtonClick (e) { handleTabPlusButtonClick (e) {
@@ -423,68 +416,49 @@ class SnippetNoteDetail extends React.Component {
style={this.props.style} style={this.props.style}
styleName='root' styleName='root'
> >
{this.state.isDeleting <div styleName='info'>
? <div styleName='info'> <div styleName='info-left'>
<div styleName='info-delete' <div styleName='info-left-top'>
tabIndex='-1' <FolderSelect styleName='info-left-top-folderSelect'
onKeyDown={(e) => this.handleDeleteKeyDown(e)} value={this.state.note.storage + '-' + this.state.note.folder}
> ref='folder'
<span styleName='info-delete-message'> data={data}
Are you sure to delete this note? onChange={(e) => this.handleFolderChange(e)}
</span> />
<button styleName='info-delete-confirmButton' </div>
onClick={(e) => this.handleDeleteConfirmButtonClick(e)} <div styleName='info-left-bottom'>
ref='deleteConfirmButton' <TagSelect
>Confirm</button> styleName='info-left-bottom-tagSelect'
<button styleName='info-delete-cancelButton' ref='tags'
onClick={(e) => this.handleDeleteCancelButtonClick(e)} value={this.state.note.tags}
>Cancel</button> onChange={(e) => this.handleChange(e)}
</div>
</div>
: <div styleName='info'>
<div styleName='info-left'>
<div styleName='info-left-top'>
<FolderSelect styleName='info-left-top-folderSelect'
value={this.state.note.storage + '-' + this.state.note.folder}
ref='folder'
data={data}
onChange={(e) => this.handleFolderChange(e)}
/>
</div>
<div styleName='info-left-bottom'>
<TagSelect
styleName='info-left-bottom-tagSelect'
ref='tags'
value={this.state.note.tags}
onChange={(e) => this.handleChange(e)}
/>
</div>
</div>
<div styleName='info-right'>
<StarButton styleName='info-right-button'
onClick={(e) => this.handleStarButtonClick(e)}
isActive={note.isStarred}
/> />
<button styleName='info-right-button'
onClick={(e) => this.handleShareButtonClick(e)}
disabled
>
<i className='fa fa-share-alt fa-fw'/>
<span styleName='info-right-button-tooltip'
style={{right: 20}}
>Share Note</span>
</button>
<button styleName='info-right-button'
onClick={(e) => this.handleContextButtonClick(e)}
>
<i className='fa fa-ellipsis-v'/>
<span styleName='info-right-button-tooltip'
style={{right: 5}}
>More Options</span>
</button>
</div> </div>
</div> </div>
} <div styleName='info-right'>
<StarButton styleName='info-right-button'
onClick={(e) => this.handleStarButtonClick(e)}
isActive={note.isStarred}
/>
<button styleName='info-right-button'
onClick={(e) => this.handleShareButtonClick(e)}
disabled
>
<i className='fa fa-share-alt fa-fw'/>
<span styleName='info-right-button-tooltip'
style={{right: 20}}
>Share Note</span>
</button>
<button styleName='info-right-button'
onClick={(e) => this.handleContextButtonClick(e)}
>
<i className='fa fa-ellipsis-v'/>
<span styleName='info-right-button-tooltip'
style={{right: 5}}
>More Options</span>
</button>
</div>
</div>
<div styleName='body'> <div styleName='body'>
<div styleName='body-description'> <div styleName='body-description'>

View File

@@ -12,34 +12,6 @@ $info-height = 75px
border-bottom $ui-border border-bottom $ui-border
background-color $ui-backgroundColor background-color $ui-backgroundColor
.info-delete
height 80px
display flex
.info-delete-message
height 80px
line-height 80px
padding 0 25px
overflow ellipsis
flex 1
.info-delete-confirmButton
margin 25px 5px 0
width 80px
height 30px
border-radius 2px
border none
colorDangerButton()
.info-delete-cancelButton
width 80px
height 30px
margin 25px 5px 0
border $ui-border
border-radius 2px
color $ui-text-color
colorDefaultButton()
.info-left .info-left
float left float left
padding 0 5px padding 0 5px

View File

@@ -263,7 +263,46 @@ function data (state = defaultDataMap(), action) {
} }
case 'DELETE_NOTE': case 'DELETE_NOTE':
{ {
let uniqueKey = action.storageKey + '-' + action.noteKey
let targetNote = state.noteMap.get(uniqueKey)
state = Object.assign({}, state)
// From storageNoteMap
state.storeageNoteMap = new Map(state.storeageNoteMap)
let noteSet = state.storeageNoteMap.get(targetNote.storage)
noteSet = new Set(noteSet)
noteSet.delete(uniqueKey)
state.storeageNoteMap.set(targetNote.storage, noteSet)
if (targetNote != null) {
// From isStarred
if (targetNote.isStarred) {
state.starredSet = new Set(state.starredSet)
state.starredSet.delete(uniqueKey)
}
// From folderNoteMap
let folderKey = targetNote.storage + '-' + targetNote.folder
state.folderNoteMap = new Map(state.folderNoteMap)
let folderSet = state.folderNoteMap.get(folderKey)
folderSet = new Set(folderSet)
folderSet.delete(uniqueKey)
state.folderNoteMap.set(folderKey, folderSet)
// From tagMap
if (targetNote.tags.length > 0) {
state.tagNoteMap = new Map(state.tagNoteMap)
targetNote.tags.forEach((tag) => {
let noteSet = state.tagNoteMap.get(tag)
noteSet = new Set(noteSet)
noteSet.delete(uniqueKey)
state.tagNoteMap.set(tag, noteSet)
})
}
}
state.noteMap = new Map(state.noteMap)
state.noteMap.delete(uniqueKey)
return state return state
} }
} }