mirror of
https://github.com/metabolist/metatext.git
synced 2024-11-22 00:01:00 +00:00
Confirm deletion
This commit is contained in:
parent
88c3fedd93
commit
fab43da52f
5 changed files with 37 additions and 2 deletions
|
@ -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";
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Reference in a new issue