in FriendlyPix/FPCommentViewController.swift [73:96]
func deleteComment(_ indexPath: IndexPath) {
requestWorkItem?.perform()
let commentID = comments[indexPath.item].commentID
let comment = comments.remove(at: indexPath.item)
collectionView?.deleteItems(at: [indexPath])
requestWorkItem = DispatchWorkItem { [weak self] in
self?.commentsRef.child(commentID).removeValue()
}
DispatchQueue.main.asyncAfter(deadline: .now() + .seconds(4),
execute: requestWorkItem!)
let action = MDCSnackbarMessageAction()
action.handler = {
self.requestWorkItem?.cancel()
let index = min(indexPath.item, self.comments.count)
self.comments.insert(comment, at: index)
self.collectionView?.insertItems(at: [IndexPath(item: index, section: 1)])
}
action.title = "Undo"
commentDeleteText.action = action
mdcSnackBarmanager.show(commentDeleteText)
}