Skip to content

Commit

Permalink
Update Post Editor context menu to use new style and update copy (#23145
Browse files Browse the repository at this point in the history
)
  • Loading branch information
kean authored May 7, 2024
2 parents 1325dba + 54b6b93 commit cd5d37f
Show file tree
Hide file tree
Showing 11 changed files with 116 additions and 123 deletions.
2 changes: 2 additions & 0 deletions RELEASE-NOTES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* [*] Add "Slug" and "Excerpt" fields to "Page Settings" [#23135]
* [*] Make it easier to "Share" and "Blaze" a published post with an updated success view [##23128]
* [*] Add support for viewing trashed posts and pages and restoring them from the editor [#23142]
* [*] Update the "More" menu in the Editor to use modern iOS design and update copy to match Gutenberg [#23145]
* [*] Update the "Revisions" list design and fix an issue with the footer displaying incorrect "Date Created" for drafts [#23145]

24.8
-----
Expand Down
3 changes: 3 additions & 0 deletions WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import Foundation
case editorPostSlugChanged
case editorPostExcerptChanged
case editorPostSiteChanged
case editorPostLegacyMoreMenuShown

// Resolve post version conflict
case resolveConflictScreenShown
Expand Down Expand Up @@ -666,6 +667,8 @@ import Foundation
return "editor_post_excerpt_changed"
case .editorPostSiteChanged:
return "editor_post_site_changed"
case .editorPostLegacyMoreMenuShown:
return "editor_post_legacy_more_menu_shown"
case .resolveConflictScreenShown:
return "resolve_conflict_screen_shown"
case .resolveConflictSaveTapped:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1197,7 +1197,7 @@ private extension AztecPostViewController {

if (post.revisions ?? []).count > 0 {
alert.addDefaultActionWithTitle(MoreSheetAlert.historyTitle) { [unowned self] _ in
self.displayHistory()
self.displayRevisionsList()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@ extension GutenbergViewController {
case managedObjectContextMissing = 2
}

// - warning: deprecated (kahu-offline-mode)
// TODO: Remove when/if confirmed that this is never invoked by Gutenberg.
func displayMoreSheet() {
WPAnalytics.track(.editorPostLegacyMoreMenuShown)

// Dismisses and locks the Notices Store from displaying any new notices.
ActionDispatcher.dispatch(NoticeAction.lock)
let alert = UIAlertController(title: nil, message: nil, preferredStyle: .actionSheet)
Expand Down Expand Up @@ -52,7 +56,7 @@ extension GutenbergViewController {

if (post.revisions ?? []).count > 0 {
alert.addDefaultActionWithTitle(MoreSheetAlert.historyTitle) { [weak self] _ in
self?.displayHistory()
self?.displayRevisionsList()
ActionDispatcher.dispatch(NoticeAction.unlock)
}
}
Expand Down Expand Up @@ -86,11 +90,68 @@ extension GutenbergViewController {

present(alert, animated: true)
}

func makeMoreMenu() -> UIMenu {
UIMenu(title: "", image: nil, identifier: nil, options: [], children: [
UIDeferredMenuElement.uncached { [weak self] in
$0(self?.makeMoreMenuSections() ?? [])
}
])
}

private func makeMoreMenuSections() -> [UIMenuElement] {
var sections: [UIMenuElement] = [
UIMenu(title: "", subtitle: "", options: .displayInline, children: makeMoreMenuActions())
]
if let string = makeContextStructureString() {
sections.append(UIAction(subtitle: string, attributes: [.disabled], handler: { _ in }))
}
return sections
}

private func makeMoreMenuActions() -> [UIAction] {
var actions: [UIAction] = []

let toggleModeTitle = mode == .richText ? Strings.codeEditor : Strings.visualEditor
let toggleModeIconName = mode == .richText ? "curlybraces" : "doc.richtext"
actions.append(UIAction(title: toggleModeTitle, image: UIImage(systemName: toggleModeIconName)) { [weak self] _ in
self?.toggleEditingMode()
})

actions.append(UIAction(title: Strings.preview, image: UIImage(systemName: "safari")) { [weak self] _ in
self?.displayPreview()
})

let revisionCount = (post.revisions ?? []).count
if revisionCount > 0 {
actions.append(UIAction(title: Strings.revisions + " (\(revisionCount))", image: UIImage(systemName: "clock.arrow.circlepath")) { [weak self] _ in
self?.displayRevisionsList()
})
}

let settingsTitle = self.post is Page ? Strings.pageSettings : Strings.postSettings
actions.append(UIAction(title: settingsTitle, image: UIImage(systemName: "gearshape")) { [weak self] _ in
self?.displayPostSettings()
})
let helpTitle = JetpackFeaturesRemovalCoordinator.jetpackFeaturesEnabled() ? Strings.helpAndSupport : Strings.help
actions.append(UIAction(title: helpTitle, image: UIImage(systemName: "questionmark.circle")) { [weak self] _ in
self?.showEditorHelp()
})
return actions
}

private func makeContextStructureString() -> String? {
guard mode == .richText, let contentInfo = contentInfo else {
return nil
}
return String(format: Strings.contentStructure, contentInfo.blockCount, contentInfo.wordCount, contentInfo.characterCount)
}
}

// MARK: - Constants

extension GutenbergViewController {
// - warning: deprecated (kahu-offline-mode)
struct MoreSheetAlert {
static let htmlTitle = NSLocalizedString("Switch to HTML Mode", comment: "Switches the Editor to HTML Mode")
static let richTitle = NSLocalizedString("Switch to Visual Mode", comment: "Switches the Editor to Rich Text Mode")
Expand All @@ -104,3 +165,15 @@ extension GutenbergViewController {
static let editorHelpTitle = NSLocalizedString("Help", comment: "Open editor help options")
}
}

private enum Strings {
static let codeEditor = NSLocalizedString("postEditor.moreMenu.codeEditor", value: "Code Editor", comment: "Post Editor / Button in the 'More' menu")
static let visualEditor = NSLocalizedString("postEditor.moreMenu.visualEditor", value: "Visual Editor", comment: "Post Editor / Button in the 'More' menu")
static let preview = NSLocalizedString("postEditor.moreMenu.preview", value: "Preview", comment: "Post Editor / Button in the 'More' menu")
static let revisions = NSLocalizedString("postEditor.moreMenu.revisions", value: "Revisions", comment: "Post Editor / Button in the 'More' menu")
static let pageSettings = NSLocalizedString("postEditor.moreMenu.pageSettings", value: "Page Settings", comment: "Post Editor / Button in the 'More' menu")
static let postSettings = NSLocalizedString("postEditor.moreMenu.postSettings", value: "Post Settings", comment: "Post Editor / Button in the 'More' menu")
static let helpAndSupport = NSLocalizedString("postEditor.moreMenu.helpAndSupport", value: "Help & Support", comment: "Post Editor / Button in the 'More' menu")
static let help = NSLocalizedString("postEditor.moreMenu.help", value: "Help", comment: "Post Editor / Button in the 'More' menu")
static let contentStructure = NSLocalizedString("postEditor.moreMenu.contentStructure", value: "Blocks: %li, Words: %li, Characters: %li", comment: "Post Editor / 'More' menu details labels with 'Blocks', 'Words' and 'Characters' counts as parameters (in that order)")
}
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,15 @@ class GutenbergViewController: UIViewController, PostEditor, FeaturedImageDelega
borderBottom.frame = CGRect(x: 0, y: navigationController?.navigationBar.frame.size.height ?? 0 - borderWidth, width: navigationController?.navigationBar.frame.size.width ?? 0, height: borderWidth)
borderBottom.autoresizingMask = [.flexibleWidth, .flexibleTopMargin]
navigationController?.navigationBar.addSubview(borderBottom)

if FeatureFlag.syncPublishing.enabled {
navigationBarManager.moreButton.menu = makeMoreMenu()
navigationBarManager.moreButton.showsMenuAsPrimaryAction = true
}
}

@objc private func buttonMoreTapped() {
displayMoreSheet()
}

private func reloadBlogIconView() {
Expand Down

This file was deleted.

67 changes: 0 additions & 67 deletions WordPress/Classes/ViewRelated/Pages/PageListSectionHeaderView.xib

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ extension PostEditor {
}
}

func displayHistory() {
func displayRevisionsList() {
guard FeatureFlag.syncPublishing.enabled else {
_displayHistory()
return
Expand All @@ -174,7 +174,7 @@ extension PostEditor {
self.post.mt_excerpt = revision.postExcerpt

// It's important to clear the pending uploads associated with the
    // post. The assumption is that if the revision on the remote,
// post. The assumption is that if the revision on the remote,
// its associated media has to be also uploaded.
MediaCoordinator.shared.cancelUploadOfAllMedia(for: self.post)
self.post.media = []
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class PostEditorNavigationBarManager {
return button
}()

private lazy var moreButton: UIButton = {
lazy var moreButton: UIButton = {
let image = UIImage(named: "editor-more")
let button = UIButton(type: .system)
button.setImage(image, for: .normal)
Expand Down
Loading

0 comments on commit cd5d37f

Please sign in to comment.