diff --git a/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift b/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift index 276b48d1a7fc..5edfbcd6784e 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageListViewController.swift @@ -322,10 +322,8 @@ class PageListViewController: AbstractPostListViewController, UIViewControllerRe UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in guard let self else { return nil } let page = self.pages[indexPath.row] - let viewModel = PageMenuViewModel(page: page) - let helper = AbstractPostMenuHelper(page, viewModel: viewModel) let cell = self.tableView.cellForRow(at: indexPath) - return helper.makeMenu(presentingView: cell?.contentView ?? UIView(), delegate: self) + return AbstractPostHelper.makeContextMenu(for: page, presentingView: cell, delegate: self) } } diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostHelper+Actions.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostHelper+Actions.swift index 046bed200c0f..361a4650fcb0 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostHelper+Actions.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostHelper+Actions.swift @@ -1,6 +1,8 @@ import UIKit extension AbstractPostHelper { + // MARK: - Swipe Actions + static func makeLeadingContextualActions(for post: AbstractPost, delegate: InteractivePostViewDelegate) -> [UIContextualAction] { var actions: [UIContextualAction] = [] @@ -42,6 +44,23 @@ extension AbstractPostHelper { return actions } + + // MARK: - Context Menu + + static func makeContextMenu(for post: AbstractPost, presentingView: UIView?, delegate: InteractivePostViewDelegate) -> UIMenu { + switch post { + case let post as Post: + let viewModel = PostListItemViewModel(post: post).statusViewModel + let helper = AbstractPostMenuHelper(post, viewModel: viewModel) + return helper.makeMenu(presentingView: presentingView ?? UIView(), delegate: delegate) + case let page as Page: + let viewModel = PageMenuViewModel(page: page) + let helper = AbstractPostMenuHelper(page, viewModel: viewModel) + return helper.makeMenu(presentingView: presentingView ?? UIView(), delegate: delegate) + default: + fatalError("Unsupported post type: \(type(of: post))") + } + } } private enum Strings { diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 7596b0ddc291..6599afa1a0e5 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -259,10 +259,8 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe UIContextMenuConfiguration(identifier: nil, previewProvider: nil) { [weak self] _ in guard let self else { return nil } let post = self.postAtIndexPath(indexPath) - let viewModel = PostListItemViewModel(post: post).statusViewModel - let helper = AbstractPostMenuHelper(post, viewModel: viewModel) let cell = self.tableView.cellForRow(at: indexPath) - return helper.makeMenu(presentingView: cell?.contentView ?? UIView(), delegate: self) + return AbstractPostHelper.makeContextMenu(for: post, presentingView: cell, delegate: self) } }