Add confirmation dialog

This commit is contained in:
Thomas Nordquist
2019-07-17 09:14:10 +02:00
parent 094831f037
commit 1cef529ac7
6 changed files with 147 additions and 8 deletions

View File

@@ -3,11 +3,28 @@ import { AppState } from '../reducers'
import { Dispatch } from 'redux'
import { makePublishEvent, rendererEvents } from '../../../events'
import { moveSelectionUpOrDownwards } from './visibleTreeTraversal'
import { globalActions } from '.'
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => (
export const clearTopic = (topic: q.TreeNode<any>, recursive: boolean, subtopicClearLimit = 50) => async (
dispatch: Dispatch<any>,
getState: () => AppState
) => {
if (recursive) {
const topicCount = topic.childTopicCount()
const deleteLimitMessage =
topicCount > subtopicClearLimit ? ` You can only delete ${subtopicClearLimit} child topics at once.` : ''
const childTopicsMessage = topicCount > 0 ? ` and ${topicCount} child ${topicCount === 1 ? 'topic' : 'topics'}` : ''
const confirmed = await dispatch(
globalActions.requestConfirmation(
'Confirm delete',
`Do you want to delete "${topic.path()}"${childTopicsMessage}?${deleteLimitMessage}`
)
)
if (!confirmed) {
return
}
}
dispatch(moveSelectionUpOrDownwards('next'))
const { connectionId } = getState().connection