Skip to content

Commit

Permalink
Merge pull request #21957 from wordpress-mobile/task/pages-attributes…
Browse files Browse the repository at this point in the history
…-submenu

Posts & Pages: Make the page attributes section collapsible
  • Loading branch information
momo-ozawa authored Nov 3, 2023
2 parents 8609031 + 99ed7d1 commit fec0921
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
21 changes: 18 additions & 3 deletions WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
}

Expand Down Expand Up @@ -70,20 +80,21 @@ 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")
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")
}
}

Expand Down Expand Up @@ -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
}
}

Expand Down Expand Up @@ -145,6 +157,8 @@ extension AbstractPostButton: AbstractPostMenuAction {
delegate.setHomepage(for: post)
case .setPostsPage:
delegate.setPostsPage(for: post)
case .pageAttributes:
break
}
}

Expand All @@ -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.")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -22,6 +28,7 @@ enum AbstractPostButton: Equatable {
case comments

/// Specific to pages
case pageAttributes
case setParent(IndexPath)
case setHomepage
case setPostsPage
Expand Down
6 changes: 3 additions & 3 deletions WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class PageMenuViewModel: AbstractPostMenuViewModel {
createPrimarySection(),
createSecondarySection(),
createBlazeSection(),
createSetPageSection(),
createSetPageAttributesSection(),
createTrashSection()
]
}
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit fec0921

Please sign in to comment.