Confirm deletion

This commit is contained in:
Justin Mazzocchi 2021-01-11 15:40:46 -08:00
parent 88c3fedd93
commit fab43da52f
No known key found for this signature in database
GPG Key ID: E223E6937AAFB01C
5 changed files with 37 additions and 2 deletions

View File

@ -157,7 +157,9 @@
"status.bookmark" = "Bookmark";
"status.content-warning-abbreviation" = "CW";
"status.delete" = "Delete";
"status.delete.confirm" = "Are you sure you want to delete this post?";
"status.delete-and-redraft" = "Delete & re-draft";
"status.delete-and-redraft.confirm" = "Are you sure you want to delete this post and re-draft it? Favorites and boosts will be lost, and replies to the original post will be orphaned.";
"status.mute" = "Mute conversation";
"status.pin" = "Pin on profile";
"status.pinned-post" = "Pinned post";

View File

@ -307,6 +307,8 @@ private extension TableViewController {
present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel)
case let .compose(inReplyToViewModel, redraft):
compose(inReplyToViewModel: inReplyToViewModel, redraft: redraft)
case let .confirmDelete(statusViewModel, redraft):
confirmDelete(statusViewModel: statusViewModel, redraft: redraft)
case let .report(reportViewModel):
report(reportViewModel: reportViewModel)
}
@ -389,6 +391,29 @@ private extension TableViewController {
present(navigationController, animated: true)
}
func confirmDelete(statusViewModel: StatusViewModel, redraft: Bool) {
let alertController = UIAlertController(
title: nil,
message: redraft
? NSLocalizedString("status.delete-and-redraft.confirm", comment: "")
: NSLocalizedString("status.delete.confirm", comment: ""),
preferredStyle: .alert)
let deleteAction = UIAlertAction(
title: redraft
? NSLocalizedString("status.delete-and-redraft", comment: "")
: NSLocalizedString("status.delete", comment: ""),
style: .destructive) { _ in
redraft ? statusViewModel.deleteAndRedraft() : statusViewModel.delete()
}
let cancelAction = UIAlertAction(title: NSLocalizedString("cancel", comment: ""), style: .cancel) { _ in }
alertController.addAction(deleteAction)
alertController.addAction(cancelAction)
present(alertController, animated: true)
}
func set(expandAllState: ExpandAllState) {
switch expandAllState {
case .hidden:

View File

@ -9,6 +9,7 @@ public enum CollectionItemEvent {
case navigation(Navigation)
case attachment(AttachmentViewModel, StatusViewModel)
case compose(inReplyTo: StatusViewModel?, redraft: Status?)
case confirmDelete(StatusViewModel, redraft: Bool)
case report(ReportViewModel)
case share(URL)
}

View File

@ -254,6 +254,13 @@ public extension StatusViewModel {
.eraseToAnyPublisher())
}
func confirmDelete(redraft: Bool) {
eventsSubject.send(
Just(.confirmDelete(self, redraft: redraft))
.setFailureType(to: Error.self)
.eraseToAnyPublisher())
}
func delete() {
eventsSubject.send(
statusService.delete()

View File

@ -431,13 +431,13 @@ private extension StatusView {
title: NSLocalizedString("status.delete", comment: ""),
image: UIImage(systemName: "trash"),
attributes: .destructive) { _ in
viewModel.delete()
viewModel.confirmDelete(redraft: false)
},
UIAction(
title: NSLocalizedString("status.delete-and-redraft", comment: ""),
image: UIImage(systemName: "trash.circle"),
attributes: .destructive) { _ in
viewModel.deleteAndRedraft()
viewModel.confirmDelete(redraft: true)
}
]
} else {