Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,11 @@ final class CustomPostListViewModel: ObservableObject {
wpService: service
)
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)

let subtitle = (postTitle?.isEmpty == false) ? postTitle : nil
Notice(title: CustomPostNoticeStrings.postUpdated, message: subtitle, feedbackType: .success).post()
}
let settingsVC = PostSettingsViewController(viewModel: viewModel)
let nav = UINavigationController(rootViewController: settingsVC)
vc.present(nav, animated: true)
Expand Down
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 {

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.

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
Expand Up @@ -143,7 +143,7 @@ private extension CustomPostEditorViewController {
style: .default,
handler: { [weak self] _ in
Task {
await self?.save(publish: false)
await self?.save()
}
}
)
Expand All @@ -170,7 +170,7 @@ private extension CustomPostEditorViewController {
attributes: enabled ? [] : [.disabled]
) { [weak self] _ in
Task {
await self?.save(publish: false)
await self?.save()
}
}
resolve([saveDraft])
Expand All @@ -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()
}
}
}
Expand Down Expand Up @@ -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()
}
}
)
Expand All @@ -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

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

Notice(title: title, message: subtitle, feedbackType: .success).post()
} catch {
SVProgressHUD.showError(withStatus: error.localizedDescription)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The 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 }),
Expand Down Expand Up @@ -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",
Expand Down