Merge pull request #1078 from j-f1/discard

Improve heuristic for skipping the post discard confirmation modal
This commit is contained in:
Nathan Mattes 2023-07-02 16:25:02 +02:00 committed by GitHub
commit c51f021b12
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 21 additions and 26 deletions

View File

@ -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.",

View File

@ -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.",

View File

@ -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.")

View File

@ -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.";

View File

@ -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