-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Custom Posts: Show "Post updated" notice #25576
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: trunk
Are you sure you want to change the base?
Changes from all commits
e7d646d
693ccb9
01ff98c
a198936
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import Foundation | ||
|
|
||
| /// Localized titles for the success notices emitted when a custom post is | ||
| /// persisted to the server. Shared between the editor, the publishing sheet, | ||
| /// and the Custom Posts list. | ||
| enum CustomPostNoticeStrings { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Optional follow-on to the three whitespace nits: the trim + empty→nil logic now repeats at all three notice sites. Since this enum is already the shared home, a small helper would keep it in one place: static func subtitle(from rawTitle: String?) -> String? {
let trimmed = rawTitle?.trimmingCharacters(in: .whitespacesAndNewlines)
return trimmed?.isEmpty == false ? trimmed : nil
}Then each call site becomes |
||
| static let draftSaved = NSLocalizedString( | ||
| "customPost.notice.draftSaved", | ||
| value: "Draft saved", | ||
| comment: "Success notice shown after a new draft custom post is created on the server." | ||
| ) | ||
| static let postUpdated = NSLocalizedString( | ||
| "customPost.notice.postUpdated", | ||
| value: "Post updated", | ||
| comment: "Success notice shown after an existing custom post is updated on the server." | ||
| ) | ||
| static let postPublished = NSLocalizedString( | ||
| "customPost.notice.postPublished", | ||
| value: "Post published", | ||
| comment: "Success notice shown after a custom post is published on the server." | ||
| ) | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
|
|
@@ -143,7 +143,7 @@ private extension CustomPostEditorViewController { | |||||||
| style: .default, | ||||||||
| handler: { [weak self] _ in | ||||||||
| Task { | ||||||||
| await self?.save(publish: false) | ||||||||
| await self?.save() | ||||||||
| } | ||||||||
| } | ||||||||
| ) | ||||||||
|
|
@@ -170,7 +170,7 @@ private extension CustomPostEditorViewController { | |||||||
| attributes: enabled ? [] : [.disabled] | ||||||||
| ) { [weak self] _ in | ||||||||
| Task { | ||||||||
| await self?.save(publish: false) | ||||||||
| await self?.save() | ||||||||
| } | ||||||||
| } | ||||||||
| resolve([saveDraft]) | ||||||||
|
|
@@ -197,7 +197,7 @@ private extension CustomPostEditorViewController { | |||||||
| } else { | ||||||||
| return UIAction(title: PostEditorStrings.update) { [weak self] _ in | ||||||||
| Task { | ||||||||
| await self?.save(publish: false) | ||||||||
| await self?.save() | ||||||||
| } | ||||||||
| } | ||||||||
| } | ||||||||
|
|
@@ -228,12 +228,8 @@ private extension CustomPostEditorViewController { | |||||||
| blog: blog, | ||||||||
| from: self, | ||||||||
| completion: { [weak self] result in | ||||||||
| guard let self else { return } | ||||||||
| switch result { | ||||||||
| case .published: | ||||||||
| completion() | ||||||||
| case .cancelled: | ||||||||
| break | ||||||||
| if case .published = result { | ||||||||
| self?.completion() | ||||||||
| } | ||||||||
| } | ||||||||
| ) | ||||||||
|
|
@@ -248,21 +244,27 @@ private extension CustomPostEditorViewController { | |||||||
|
|
||||||||
| private extension CustomPostEditorViewController { | ||||||||
|
|
||||||||
| func save(publish: Bool) async { | ||||||||
| func save() async { | ||||||||
| SVProgressHUD.show() | ||||||||
|
|
||||||||
| // Capture whether this is a brand-new post (not yet on the server) so the | ||||||||
| // notice can distinguish "Draft saved" (just created) from "Post updated" | ||||||||
| // (edited an existing post). Any save of an already-existing post (draft | ||||||||
| // or published) reads as an update from the user's perspective. | ||||||||
| let isNewPost = post == nil | ||||||||
|
|
||||||||
| do { | ||||||||
| let data = try await editorViewController.getTitleAndContent() | ||||||||
| try await editorService.save( | ||||||||
| content: EditorContent(title: data.title, content: data.content), | ||||||||
| publish: publish | ||||||||
| publish: false | ||||||||
| ) | ||||||||
|
|
||||||||
| dismissHUDWithSuccess() | ||||||||
|
|
||||||||
| if publish { | ||||||||
| completion() | ||||||||
| } | ||||||||
| let title = isNewPost ? CustomPostNoticeStrings.draftSaved : CustomPostNoticeStrings.postUpdated | ||||||||
| let subtitle = data.title.isEmpty ? nil : data.title | ||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same whitespace nit —
Suggested change
|
||||||||
| Notice(title: title, message: subtitle, feedbackType: .success).post() | ||||||||
| } catch { | ||||||||
| SVProgressHUD.showError(withStatus: error.localizedDescription) | ||||||||
| } | ||||||||
|
|
||||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -81,7 +81,14 @@ final class PublishPostViewController<ViewModel: PostSettingsViewModelProtocol>: | |||||
| editorService: editorService, | ||||||
| blog: blog | ||||||
| ) | ||||||
| publishVC.onCompletion = completion | ||||||
| publishVC.onCompletion = { result in | ||||||
| if case .published = result { | ||||||
| let postTitle = editorService.post?.title?.raw | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cosmetic: a whitespace-only title slips past
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The trimming is redundant since the site trims already. whitespaces.mov |
||||||
| let subtitle = (postTitle?.isEmpty == false) ? postTitle : nil | ||||||
| Notice(title: CustomPostNoticeStrings.postPublished, message: subtitle, feedbackType: .success).post() | ||||||
| } | ||||||
| completion(result) | ||||||
| } | ||||||
| let navigationVC = UINavigationController(rootViewController: publishVC) | ||||||
| navigationVC.sheetPresentationController?.detents = [ | ||||||
| .custom(identifier: .medium, resolver: { _ in 526 }), | ||||||
|
|
@@ -221,23 +228,82 @@ private typealias Strings = PrepublishingSheetStrings | |||||
|
|
||||||
| enum PrepublishingSheetStrings { | ||||||
| static let title = NSLocalizedString("prepublishing.title", value: "Publishing", comment: "Navigation title") | ||||||
| static let publishingTo = NSLocalizedString("prepublishing.publishingTo", value: "Publishing to", comment: "Label in the header in the pre-publishing sheet") | ||||||
| static let publish = NSLocalizedString("prepublishing.publish", value: "Publish", comment: "Primary button label in the pre-publishing sheet") | ||||||
| static let schedule = NSLocalizedString("prepublishing.schedule", value: "Schedule", comment: "Primary button label in the pre-publishing shee") | ||||||
| static let publishDate = NSLocalizedString("prepublishing.publishDate", value: "Publish Date", comment: "Label for a cell in the pre-publishing sheet") | ||||||
| static let visibility = NSLocalizedString("prepublishing.visibility", value: "Visibility", comment: "Label for a cell in the pre-publishing sheet") | ||||||
| static let categories = NSLocalizedString("prepublishing.categories", value: "Categories", comment: "Label for a cell in the pre-publishing sheet") | ||||||
| static let tags = NSLocalizedString("prepublishing.tags", value: "Tags", comment: "Label for a cell in the pre-publishing sheet") | ||||||
| static let jetpackSocial = NSLocalizedString("prepublishing.jetpackSocial", value: "Jetpack Social", comment: "Label for a cell in the pre-publishing sheet") | ||||||
| static let immediately = NSLocalizedString("prepublishing.publishDateImmediately", value: "Immediately", comment: "Placeholder value for a publishing date in the prepublishing sheet when the date is not selected") | ||||||
| static let uploadingMedia = NSLocalizedString("prepublishing.uploadingMedia", value: "Uploading media", comment: "Title for a publish button state in the pre-publishing sheet") | ||||||
| private static let uploadMediaOneItemRemaining = NSLocalizedString("prepublishing.uploadMediaOneItemRemaining", value: "%@ item remaining", comment: "Details label for a publish button state in the pre-publishing sheet") | ||||||
| private static let uploadMediaManyItemsRemaining = NSLocalizedString("prepublishing.uploadMediaManyItemsRemaining", value: "%@ items remaining", comment: "Details label for a publish button state in the pre-publishing sheet") | ||||||
| static let publishingTo = NSLocalizedString( | ||||||
| "prepublishing.publishingTo", | ||||||
| value: "Publishing to", | ||||||
| comment: "Label in the header in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let publish = NSLocalizedString( | ||||||
| "prepublishing.publish", | ||||||
| value: "Publish", | ||||||
| comment: "Primary button label in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let schedule = NSLocalizedString( | ||||||
| "prepublishing.schedule", | ||||||
| value: "Schedule", | ||||||
| comment: "Primary button label in the pre-publishing shee" | ||||||
| ) | ||||||
| static let publishDate = NSLocalizedString( | ||||||
| "prepublishing.publishDate", | ||||||
| value: "Publish Date", | ||||||
| comment: "Label for a cell in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let visibility = NSLocalizedString( | ||||||
| "prepublishing.visibility", | ||||||
| value: "Visibility", | ||||||
| comment: "Label for a cell in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let categories = NSLocalizedString( | ||||||
| "prepublishing.categories", | ||||||
| value: "Categories", | ||||||
| comment: "Label for a cell in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let tags = NSLocalizedString( | ||||||
| "prepublishing.tags", | ||||||
| value: "Tags", | ||||||
| comment: "Label for a cell in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let jetpackSocial = NSLocalizedString( | ||||||
| "prepublishing.jetpackSocial", | ||||||
| value: "Jetpack Social", | ||||||
| comment: "Label for a cell in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let immediately = NSLocalizedString( | ||||||
| "prepublishing.publishDateImmediately", | ||||||
| value: "Immediately", | ||||||
| comment: "Placeholder value for a publishing date in the prepublishing sheet when the date is not selected" | ||||||
| ) | ||||||
| static let uploadingMedia = NSLocalizedString( | ||||||
| "prepublishing.uploadingMedia", | ||||||
| value: "Uploading media", | ||||||
| comment: "Title for a publish button state in the pre-publishing sheet" | ||||||
| ) | ||||||
| private static let uploadMediaOneItemRemaining = NSLocalizedString( | ||||||
| "prepublishing.uploadMediaOneItemRemaining", | ||||||
| value: "%@ item remaining", | ||||||
| comment: "Details label for a publish button state in the pre-publishing sheet" | ||||||
| ) | ||||||
| private static let uploadMediaManyItemsRemaining = NSLocalizedString( | ||||||
| "prepublishing.uploadMediaManyItemsRemaining", | ||||||
| value: "%@ items remaining", | ||||||
| comment: "Details label for a publish button state in the pre-publishing sheet" | ||||||
| ) | ||||||
| static func uploadMediaRemaining(count: Int) -> String { | ||||||
| String(format: count == 1 ? Strings.uploadMediaOneItemRemaining : Strings.uploadMediaManyItemsRemaining, count.description) | ||||||
| String( | ||||||
| format: count == 1 ? Strings.uploadMediaOneItemRemaining : Strings.uploadMediaManyItemsRemaining, | ||||||
| count.description | ||||||
| ) | ||||||
| } | ||||||
| static let mediaUploadFailedTitle = NSLocalizedString("prepublishing.mediaUploadFailedTitle", value: "Failed to upload media", comment: "Title for a publish button state in the pre-publishing sheet") | ||||||
| static let mediaUploadFailedDetailsMultipleFailures = NSLocalizedString("prepublishing.mediaUploadFailedDetails", value: "%@ items failed to upload", comment: "Details for a publish button state in the pre-publishing sheet; count as a parameter") | ||||||
| static let mediaUploadFailedTitle = NSLocalizedString( | ||||||
| "prepublishing.mediaUploadFailedTitle", | ||||||
| value: "Failed to upload media", | ||||||
| comment: "Title for a publish button state in the pre-publishing sheet" | ||||||
| ) | ||||||
| static let mediaUploadFailedDetailsMultipleFailures = NSLocalizedString( | ||||||
| "prepublishing.mediaUploadFailedDetails", | ||||||
| value: "%@ items failed to upload", | ||||||
| comment: "Details for a publish button state in the pre-publishing sheet; count as a parameter" | ||||||
| ) | ||||||
|
|
||||||
| static let discardChangesTitle = NSLocalizedString( | ||||||
| "prepublishing.discardChanges.title", | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same whitespace nit as the publishing sheet — trim so a blank title doesn't show an empty subtitle line: