Custom Posts: Show "Post updated" notice#25576
Conversation
|
| App Name | Jetpack | |
| Configuration | Release-Alpha | |
| Build Number | 32654 | |
| Version | PR #25576 | |
| Bundle ID | com.jetpack.alpha | |
| Commit | a198936 | |
| Installation URL | 55rl9m36mqth8 |
|
| App Name | WordPress | |
| Configuration | Release-Alpha | |
| Build Number | 32654 | |
| Version | PR #25576 | |
| Bundle ID | org.wordpress.alpha | |
| Commit | a198936 | |
| Installation URL | 2vnjfjrcns2q8 |
6c9a5a3 to
caae1e1
Compare
jkmassel
left a comment
There was a problem hiding this comment.
Left a comment, but also publishPost notifies now but what about moveToDraft, trashPost, and deletePost?
| editorService: editorService, | ||
| blog: blog, | ||
| from: vc, | ||
| completion: { _ in } |
There was a problem hiding this comment.
Does this need a similar body to the one in showPublishingSheet?
| } | ||
| } | ||
|
|
||
| private enum Strings { |
There was a problem hiding this comment.
Is this a duplicate of the ViewModel strings?
WDYT about extracting them into a higher-level shared CustomPostNotice string set?
| @@ -251,6 +255,12 @@ private extension CustomPostEditorViewController { | |||
| func save(publish: Bool) async { | |||
There was a problem hiding this comment.
I think we only ever pass false here, so do we need this param? (this will cause a breaking change in callers)
| func save(publish: Bool) async { | |
| func save() async { |
| let postTitle = editorService.post?.title?.raw | ||
| let subtitle = (postTitle?.isEmpty == false) ? postTitle : nil | ||
| Notice(title: Strings.CustomPostNotice.postPublished, message: subtitle, feedbackType: .success) | ||
| .post() |
There was a problem hiding this comment.
We repeat this pattern a bunch – I wonder if we could extract it to a helper? Could be the enum you use to consolidate the strings?
I didn't touch those because the existing Posts list does not show a notice on these actions. |
Post a Notice toast on every HTTP write to the site from the Custom Post editor (save draft, update, publish) and from the standalone settings sheet reached from the Custom Posts list. The notice's title reflects the action: "Draft saved" only on the first save of a brand-new post, "Post updated" for any save of an existing post, and "Post published" via the publishing sheet. The post title is the notice's subtitle (omitted when empty). Localized strings live in a shared CustomPostNotice enum.
caae1e1 to
e7d646d
Compare
Move the success notice into PublishPostViewController.show(editorService:blog:from:completion:) so both the custom post editor and the Custom Posts list show it after publishing through the sheet. Consolidate the duplicated notice strings into a shared CustomPostNoticeStrings type.
…r.save The method is only ever called to persist a draft or update, so drop the always-false publish parameter and the dead publish-only branches.
| publishVC.onCompletion = completion | ||
| publishVC.onCompletion = { result in | ||
| if case .published = result { | ||
| let postTitle = editorService.post?.title?.raw |
There was a problem hiding this comment.
Cosmetic: a whitespace-only title slips past .isEmpty, so the toast renders a blank second line. Trimming here (matching titleForDisplay) avoids it:
| let postTitle = editorService.post?.title?.raw | |
| let postTitle = editorService.post?.title?.raw?.trimmingCharacters(in: .whitespacesAndNewlines) |
| ) | ||
| let viewModel = CustomPostSettingsViewModel(editorService: editorService, blog: blog, isStandalone: true) | ||
| viewModel.onEditorPostSaved = { [editorService] in | ||
| let postTitle = editorService.post?.title?.raw |
There was a problem hiding this comment.
Same whitespace nit as the publishing sheet — trim so a blank title doesn't show an empty subtitle line:
| let postTitle = editorService.post?.title?.raw | |
| let postTitle = editorService.post?.title?.raw?.trimmingCharacters(in: .whitespacesAndNewlines) |
| completion() | ||
| } | ||
| let title = isNewPost ? CustomPostNoticeStrings.draftSaved : CustomPostNoticeStrings.postUpdated | ||
| let subtitle = data.title.isEmpty ? nil : data.title |
There was a problem hiding this comment.
Same whitespace nit — data.title isn't trimmed before the .isEmpty check:
| let subtitle = data.title.isEmpty ? nil : data.title | |
| let trimmedTitle = data.title.trimmingCharacters(in: .whitespacesAndNewlines) | |
| let subtitle = trimmedTitle.isEmpty ? nil : trimmedTitle |
| /// 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 { |
There was a problem hiding this comment.
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 CustomPostNoticeStrings.subtitle(from: …). Take it or leave it — the inline trims work fine too; this just avoids triplicating the fix.
jkmassel
left a comment
There was a problem hiding this comment.
Sorry – I meant to note this whitespace thing earlier. I tried to make it easy to apply :)
|
Version |


Description
Mirror the existing UX: show notice after post is saved/published.
The first commit is code-format changes and can be ignored.