diff --git a/Localizations/Localizable.strings b/Localizations/Localizable.strings index a597d44..be14cf8 100644 --- a/Localizations/Localizable.strings +++ b/Localizations/Localizable.strings @@ -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"; diff --git a/View Controllers/TableViewController.swift b/View Controllers/TableViewController.swift index a4ebaf4..cc02779 100644 --- a/View Controllers/TableViewController.swift +++ b/View Controllers/TableViewController.swift @@ -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: diff --git a/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift b/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift index 4f72c4c..317fddd 100644 --- a/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift +++ b/ViewModels/Sources/ViewModels/Entities/CollectionItemEvent.swift @@ -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) } diff --git a/ViewModels/Sources/ViewModels/StatusViewModel.swift b/ViewModels/Sources/ViewModels/StatusViewModel.swift index 5635d68..fe2c874 100644 --- a/ViewModels/Sources/ViewModels/StatusViewModel.swift +++ b/ViewModels/Sources/ViewModels/StatusViewModel.swift @@ -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() diff --git a/Views/Status/StatusView.swift b/Views/Status/StatusView.swift index 5fb875a..5beecd1 100644 --- a/Views/Status/StatusView.swift +++ b/Views/Status/StatusView.swift @@ -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 {