Skip to content

Custom Posts: Show "Post updated" notice#25576

Open
crazytonyli wants to merge 4 commits into
trunkfrom
task/custom-posts-show-notice
Open

Custom Posts: Show "Post updated" notice#25576
crazytonyli wants to merge 4 commits into
trunkfrom
task/custom-posts-show-notice

Conversation

@crazytonyli

Copy link
Copy Markdown
Contributor

Description

Mirror the existing UX: show notice after post is saved/published.

The first commit is code-format changes and can be ignored.

@crazytonyli crazytonyli added this to the 27.0 milestone May 21, 2026
@crazytonyli crazytonyli requested a review from jkmassel May 21, 2026 21:16
@wpmobilebot

wpmobilebot commented May 21, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in Jetpack by scanning the QR code below to install the corresponding build.
App NameJetpack
ConfigurationRelease-Alpha
Build Number32654
VersionPR #25576
Bundle IDcom.jetpack.alpha
Commita198936
Installation URL55rl9m36mqth8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@wpmobilebot

wpmobilebot commented May 21, 2026

Copy link
Copy Markdown
Contributor
App Icon📲 You can test the changes from this Pull Request in WordPress by scanning the QR code below to install the corresponding build.
App NameWordPress
ConfigurationRelease-Alpha
Build Number32654
VersionPR #25576
Bundle IDorg.wordpress.alpha
Commita198936
Installation URL2vnjfjrcns2q8
Automatticians: You can use our internal self-serve MC tool to give yourself access to those builds if needed.

@crazytonyli crazytonyli force-pushed the task/custom-posts-show-notice branch from 6c9a5a3 to caae1e1 Compare May 25, 2026 10:12

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a comment, but also publishPost notifies now but what about moveToDraft, trashPost, and deletePost?

editorService: editorService,
blog: blog,
from: vc,
completion: { _ in }

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this need a similar body to the one in showPublishingSheet?

}
}

private enum Strings {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we only ever pass false here, so do we need this param? (this will cause a breaking change in callers)

Suggested change
func save(publish: Bool) async {
func save() async {

Comment on lines +234 to +237
let postTitle = editorService.post?.title?.raw
let subtitle = (postTitle?.isEmpty == false) ? postTitle : nil
Notice(title: Strings.CustomPostNotice.postPublished, message: subtitle, feedbackType: .success)
.post()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@crazytonyli

Copy link
Copy Markdown
Contributor Author

what about moveToDraft, trashPost, and deletePost

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.
@crazytonyli crazytonyli force-pushed the task/custom-posts-show-notice branch from caae1e1 to e7d646d Compare June 15, 2026 23:52
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.
@crazytonyli crazytonyli requested a review from jkmassel June 16, 2026 00:33
publishVC.onCompletion = completion
publishVC.onCompletion = { result in
if case .published = result {
let postTitle = editorService.post?.title?.raw

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic: a whitespace-only title slips past .isEmpty, so the toast renders a blank second line. Trimming here (matching titleForDisplay) avoids it:

Suggested change
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

Copy link
Copy Markdown
Contributor

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:

Suggested change
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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same whitespace nit — data.title isn't trimmed before the .isEmpty check:

Suggested change
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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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 CustomPostNoticeStrings.subtitle(from: …). Take it or leave it — the inline trims work fine too; this just avoids triplicating the fix.

@jkmassel jkmassel left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry – I meant to note this whitespace thing earlier. I tried to make it easy to apply :)

@wpmobilebot wpmobilebot modified the milestones: 27.0, 27.1 Jun 18, 2026
@wpmobilebot

Copy link
Copy Markdown
Contributor

Version 27.0 has now entered code-freeze, so the milestone of this PR has been updated to 27.1.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants