From ea152f3e99e826e34d128d10143bf7ebd033fd58 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Thu, 2 Nov 2023 17:58:01 +0000 Subject: [PATCH 1/2] make the page attributes section collapsible --- .../Post/AbstractPostMenuHelper.swift | 17 ++++++++++++++++- .../Post/AbstractPostMenuViewModel.swift | 7 +++++++ .../ViewRelated/Post/PageMenuViewModel.swift | 6 +++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift index 72f4539505e9..3211aaa21f71 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift @@ -35,7 +35,17 @@ struct AbstractPostMenuHelper { .filter { !$0.buttons.isEmpty } .map { section in let actions = makeActions(for: section.buttons, presentingView: presentingView, delegate: delegate) - return UIMenu(title: "", options: .displayInline, children: actions) + let menu = UIMenu(title: "", options: .displayInline, children: actions) + + if let submenuButton = section.submenuButton { + return UIMenu( + title: submenuButton.title(for: post), + image: submenuButton.icon, + children: [menu] + ) + } else { + return menu + } } } @@ -84,6 +94,7 @@ extension AbstractPostButton: AbstractPostMenuAction { case .setParent: return UIImage(systemName: "text.append") case .setHomepage: return UIImage(systemName: "house") case .setPostsPage: return UIImage(systemName: "text.word.spacing") + case .pageAttributes: return UIImage(systemName: "doc") } } @@ -112,6 +123,7 @@ extension AbstractPostButton: AbstractPostMenuAction { case .setParent: return Strings.setParent case .setHomepage: return Strings.setHomepage case .setPostsPage: return Strings.setPostsPage + case .pageAttributes: return Strings.pageAttributes } } @@ -145,6 +157,8 @@ extension AbstractPostButton: AbstractPostMenuAction { delegate.setHomepage(for: post) case .setPostsPage: delegate.setPostsPage(for: post) + case .pageAttributes: + break } } @@ -164,5 +178,6 @@ extension AbstractPostButton: AbstractPostMenuAction { static let setParent = NSLocalizedString("posts.setParent.actionTitle", value: "Set parent", comment: "Set the parent page for the selected page.") static let setHomepage = NSLocalizedString("posts.setHomepage.actionTitle", value: "Set as homepage", comment: "Set the selected page as the homepage.") static let setPostsPage = NSLocalizedString("posts.setPostsPage.actionTitle", value: "Set as posts page", comment: "Set the selected page as a posts page.") + static let pageAttributes = NSLocalizedString("posts.pageAttributes.actionTitle", value: "Page attributes", comment: "Opens a submenu for page attributes.") } } diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift index 2d977b64d316..85e5400ef9cb 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift @@ -6,6 +6,12 @@ protocol AbstractPostMenuViewModel { struct AbstractPostButtonSection { let buttons: [AbstractPostButton] + let submenuButton: AbstractPostButton? + + init(buttons: [AbstractPostButton], submenuButton: AbstractPostButton? = nil) { + self.buttons = buttons + self.submenuButton = submenuButton + } } enum AbstractPostButton: Equatable { @@ -22,6 +28,7 @@ enum AbstractPostButton: Equatable { case comments /// Specific to pages + case pageAttributes case setParent(IndexPath) case setHomepage case setPostsPage diff --git a/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift b/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift index b1b084e12d1c..7be877f72297 100644 --- a/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift @@ -14,7 +14,7 @@ final class PageMenuViewModel: AbstractPostMenuViewModel { createPrimarySection(), createSecondarySection(), createBlazeSection(), - createSetPageSection(), + createSetPageAttributesSection(), createTrashSection() ] } @@ -82,7 +82,7 @@ final class PageMenuViewModel: AbstractPostMenuViewModel { return AbstractPostButtonSection(buttons: buttons) } - private func createSetPageSection() -> AbstractPostButtonSection { + private func createSetPageAttributesSection() -> AbstractPostButtonSection { var buttons = [AbstractPostButton]() guard page.status != .trash else { @@ -99,7 +99,7 @@ final class PageMenuViewModel: AbstractPostMenuViewModel { buttons.append(.setPostsPage) } - return AbstractPostButtonSection(buttons: buttons) + return AbstractPostButtonSection(buttons: buttons, submenuButton: .pageAttributes) } private func createTrashSection() -> AbstractPostButtonSection { From 99ed7d1b156e63c07d32736424b1ccece2ff4ea7 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Fri, 3 Nov 2023 10:23:03 +0000 Subject: [PATCH 2/2] add missing icons --- .../Classes/ViewRelated/Post/AbstractPostMenuHelper.swift | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift index 3211aaa21f71..0be2c0b9ab45 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift @@ -80,14 +80,14 @@ extension AbstractPostButton: AbstractPostMenuAction { var icon: UIImage? { switch self { - case .retry: return UIImage() // TODO + case .retry: return UIImage(systemName: "arrow.clockwise") case .view: return UIImage(systemName: "safari") case .publish: return UIImage(systemName: "globe") case .stats: return UIImage(systemName: "chart.bar.xaxis") case .duplicate: return UIImage(systemName: "doc.on.doc") case .moveToDraft: return UIImage(systemName: "pencil.line") case .trash: return UIImage(systemName: "trash") - case .cancelAutoUpload: return UIImage() // TODO + case .cancelAutoUpload: return UIImage(systemName: "xmark.icloud") case .share: return UIImage(systemName: "square.and.arrow.up") case .blaze: return UIImage(systemName: "flame") case .comments: return UIImage(systemName: "bubble")