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.bookmark" = "Bookmark";
"status.content-warning-abbreviation" = "CW"; "status.content-warning-abbreviation" = "CW";
"status.delete" = "Delete"; "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" = "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.mute" = "Mute conversation";
"status.pin" = "Pin on profile"; "status.pin" = "Pin on profile";
"status.pinned-post" = "Pinned post"; "status.pinned-post" = "Pinned post";

View File

@ -307,6 +307,8 @@ private extension TableViewController {
present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel) present(attachmentViewModel: attachmentViewModel, statusViewModel: statusViewModel)
case let .compose(inReplyToViewModel, redraft): case let .compose(inReplyToViewModel, redraft):
compose(inReplyToViewModel: inReplyToViewModel, redraft: redraft) compose(inReplyToViewModel: inReplyToViewModel, redraft: redraft)
case let .confirmDelete(statusViewModel, redraft):
confirmDelete(statusViewModel: statusViewModel, redraft: redraft)
case let .report(reportViewModel): case let .report(reportViewModel):
report(reportViewModel: reportViewModel) report(reportViewModel: reportViewModel)
} }
@ -389,6 +391,29 @@ private extension TableViewController {
present(navigationController, animated: true) 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) { func set(expandAllState: ExpandAllState) {
switch expandAllState { switch expandAllState {
case .hidden: case .hidden:

View File

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

View File

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

View File

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