Merge pull request #1078 from j-f1/discard
Improve heuristic for skipping the post discard confirmation modal
This commit is contained in:
commit
c51f021b12
|
@ -15,10 +15,6 @@
|
|||
"title": "Vote Failure",
|
||||
"poll_ended": "The poll has ended"
|
||||
},
|
||||
"discard_post_content": {
|
||||
"title": "Discard Draft",
|
||||
"message": "Confirm to discard composed post content."
|
||||
},
|
||||
"publish_post_failure": {
|
||||
"title": "Publish Failure",
|
||||
"message": "Failed to publish the post.\nPlease check your internet connection.",
|
||||
|
|
|
@ -15,10 +15,6 @@
|
|||
"title": "Vote Failure",
|
||||
"poll_ended": "The poll has ended"
|
||||
},
|
||||
"discard_post_content": {
|
||||
"title": "Discard Draft",
|
||||
"message": "Confirm to discard composed post content."
|
||||
},
|
||||
"publish_post_failure": {
|
||||
"title": "Publish Failure",
|
||||
"message": "Failed to publish the post.\nPlease check your internet connection.",
|
||||
|
|
|
@ -40,12 +40,6 @@ public enum L10n {
|
|||
/// Delete Post
|
||||
public static let title = L10n.tr("Localizable", "Common.Alerts.DeletePost.Title", fallback: "Delete Post")
|
||||
}
|
||||
public enum DiscardPostContent {
|
||||
/// Confirm to discard composed post content.
|
||||
public static let message = L10n.tr("Localizable", "Common.Alerts.DiscardPostContent.Message", fallback: "Confirm to discard composed post content.")
|
||||
/// Discard Draft
|
||||
public static let title = L10n.tr("Localizable", "Common.Alerts.DiscardPostContent.Title", fallback: "Discard Draft")
|
||||
}
|
||||
public enum EditProfileFailure {
|
||||
/// Cannot edit profile. Please try again.
|
||||
public static let message = L10n.tr("Localizable", "Common.Alerts.EditProfileFailure.Message", fallback: "Cannot edit profile. Please try again.")
|
||||
|
|
|
@ -6,8 +6,6 @@
|
|||
"Common.Alerts.Common.PleaseTryAgainLater" = "Please try again later.";
|
||||
"Common.Alerts.DeletePost.Message" = "Are you sure you want to delete this post?";
|
||||
"Common.Alerts.DeletePost.Title" = "Delete Post";
|
||||
"Common.Alerts.DiscardPostContent.Message" = "Confirm to discard composed post content.";
|
||||
"Common.Alerts.DiscardPostContent.Title" = "Discard Draft";
|
||||
"Common.Alerts.EditProfileFailure.Message" = "Cannot edit profile. Please try again.";
|
||||
"Common.Alerts.EditProfileFailure.Title" = "Edit Profile Error";
|
||||
"Common.Alerts.PublishPostFailure.AttachmentsMessage.MoreThanOneVideo" = "Cannot attach more than one video.";
|
||||
|
|
|
@ -472,16 +472,27 @@ extension ComposeContentViewModel {
|
|||
.assign(to: &$isPublishBarButtonItemEnabled)
|
||||
|
||||
// bind modal dismiss state
|
||||
$content
|
||||
.receive(on: DispatchQueue.main)
|
||||
.map { content in
|
||||
if content.isEmpty {
|
||||
return true
|
||||
}
|
||||
// if the trimmed content equal to initial content
|
||||
return content.trimmingCharacters(in: .whitespacesAndNewlines) == self.initialContent
|
||||
}
|
||||
.assign(to: &$shouldDismiss)
|
||||
Publishers.CombineLatest4(
|
||||
$contentWarning,
|
||||
$content,
|
||||
$isPollActive,
|
||||
$attachmentViewModels
|
||||
)
|
||||
.receive(on: DispatchQueue.main)
|
||||
.map { contentWarning, content, hasPoll, attachments in
|
||||
let canDiscardContentWarning = contentWarning.isEmpty
|
||||
|
||||
let trimmedContent = content.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let initialContent = self.initialContent.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
let canDiscardContent = trimmedContent.isEmpty || trimmedContent == initialContent
|
||||
|
||||
let canDiscardPoll = !hasPoll
|
||||
|
||||
let canDiscardAttachments = attachments.isEmpty
|
||||
|
||||
return canDiscardContent && canDiscardPoll && canDiscardAttachments
|
||||
}
|
||||
.assign(to: &$shouldDismiss)
|
||||
|
||||
// languages
|
||||
context.settingService.currentSetting
|
||||
|
|
Loading…
Reference in New Issue