mirror of
https://github.com/BoostIo/Boostnote
synced 2025-12-16 03:06:27 +00:00
show confirmation dialog when deleting snippet with content
This commit is contained in:
@@ -247,25 +247,37 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTabButtonClick (index) {
|
handleTabButtonClick (e, index) {
|
||||||
return (e) => {
|
this.setState({
|
||||||
this.setState({
|
snippetIndex: index
|
||||||
snippetIndex: index
|
})
|
||||||
})
|
}
|
||||||
|
|
||||||
|
handleTabDeleteButtonClick (e, index) {
|
||||||
|
if (this.state.note.snippets.length > 1) {
|
||||||
|
if (this.state.note.snippets[index].content.trim().length > 0) {
|
||||||
|
let dialogIndex = dialog.showMessageBox(remote.getCurrentWindow(), {
|
||||||
|
type: 'warning',
|
||||||
|
message: 'Delete a snippet',
|
||||||
|
detail: 'This work cannot be undone.',
|
||||||
|
buttons: ['Confirm', 'Cancel']
|
||||||
|
})
|
||||||
|
if (dialogIndex === 0) {
|
||||||
|
this.deleteSnippetByIndex(index)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
this.deleteSnippetByIndex(index)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleTabDeleteButtonClick (index) {
|
deleteSnippetByIndex (index) {
|
||||||
return (e) => {
|
let snippets = this.state.note.snippets.slice()
|
||||||
if (this.state.note.snippets.length > 1) {
|
snippets.splice(index, 1)
|
||||||
let snippets = this.state.note.snippets.slice()
|
this.state.note.snippets = snippets
|
||||||
snippets.splice(index, 1)
|
this.setState({
|
||||||
this.state.note.snippets = snippets
|
note: this.state.note
|
||||||
this.setState({
|
})
|
||||||
note: this.state.note
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
handleNameInputChange (e, index) {
|
handleNameInputChange (e, index) {
|
||||||
@@ -344,7 +356,7 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
key={index}
|
key={index}
|
||||||
>
|
>
|
||||||
<button styleName='tabList-item-button'
|
<button styleName='tabList-item-button'
|
||||||
onClick={(e) => this.handleTabButtonClick(index)(e)}
|
onClick={(e) => this.handleTabButtonClick(e, index)}
|
||||||
>
|
>
|
||||||
{snippet.name.trim().length > 0
|
{snippet.name.trim().length > 0
|
||||||
? snippet.name
|
? snippet.name
|
||||||
@@ -355,7 +367,7 @@ class SnippetNoteDetail extends React.Component {
|
|||||||
</button>
|
</button>
|
||||||
{note.snippets.length > 1 &&
|
{note.snippets.length > 1 &&
|
||||||
<button styleName='tabList-item-deleteButton'
|
<button styleName='tabList-item-deleteButton'
|
||||||
onClick={(e) => this.handleTabDeleteButtonClick(index)(e)}
|
onClick={(e) => this.handleTabDeleteButtonClick(e, index)}
|
||||||
>
|
>
|
||||||
<i className='fa fa-times'/>
|
<i className='fa fa-times'/>
|
||||||
</button>
|
</button>
|
||||||
|
|||||||
Reference in New Issue
Block a user