From de717709dc6502e1a6b100d02665016820a2f4cf Mon Sep 17 00:00:00 2001 From: kean Date: Thu, 2 Nov 2023 10:07:43 -0400 Subject: [PATCH 1/5] Add Settings context menu --- .../UINavigationController+Helpers.swift | 15 +++++ ...FullScreenCommentReplyViewController.swift | 4 +- .../Pages/PageListViewController+Menu.swift | 6 +- .../Post/AbstractPostListViewController.swift | 15 +---- .../Post/AbstractPostMenuHelper.swift | 5 ++ .../Post/AbstractPostMenuViewModel.swift | 1 + .../Post/InteractivePostViewDelegate.swift | 3 +- .../Post/PostCardStatusViewModel.swift | 3 + .../Post/PostListViewController.swift | 9 +++ .../PostSettingsViewController+Swift.swift | 62 +++++++++++++++++++ .../Post/PostSettingsViewController.h | 2 + .../Post/PostSettingsViewController.m | 17 +++-- WordPress/WordPress.xcodeproj/project.pbxproj | 6 ++ 13 files changed, 126 insertions(+), 22 deletions(-) create mode 100644 WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift diff --git a/WordPress/Classes/Extensions/UINavigationController+Helpers.swift b/WordPress/Classes/Extensions/UINavigationController+Helpers.swift index c7462b5c40e8..13a3e306f6e6 100644 --- a/WordPress/Classes/Extensions/UINavigationController+Helpers.swift +++ b/WordPress/Classes/Extensions/UINavigationController+Helpers.swift @@ -51,3 +51,18 @@ extension UINavigationController { self.pushViewController(viewController, animated: animated) } } + +extension UIViewController { + func configureDefaultNavigationBarAppearance() { + let standardAppearance = UINavigationBarAppearance() + standardAppearance.configureWithDefaultBackground() + + let scrollEdgeAppearance = UINavigationBarAppearance() + scrollEdgeAppearance.configureWithTransparentBackground() + + navigationItem.standardAppearance = standardAppearance + navigationItem.compactAppearance = standardAppearance + navigationItem.scrollEdgeAppearance = scrollEdgeAppearance + navigationItem.compactScrollEdgeAppearance = scrollEdgeAppearance + } +} diff --git a/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift b/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift index b0dc2f2c782d..1884b296112c 100644 --- a/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift +++ b/WordPress/Classes/ViewRelated/Comments/FullScreenCommentReplyViewController.swift @@ -50,7 +50,7 @@ public class FullScreenCommentReplyViewController: EditCommentViewController, Su public override func viewDidLoad() { super.viewDidLoad() placeholderLabel.text = placeholder - setupNavigationItems() + setupStandaloneEditor() configureNavigationAppearance() } @@ -174,7 +174,7 @@ public class FullScreenCommentReplyViewController: EditCommentViewController, Su } /// Creates the `leftBarButtonItem` and the `rightBarButtonItem` - private func setupNavigationItems() { + private func setupStandaloneEditor() { navigationItem.leftBarButtonItem = ({ let image = UIImage.gridicon(.chevronDown).imageWithTintColor(.primary) let leftItem = UIBarButtonItem(image: image, diff --git a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift index db24f4769cab..122b883d4c7d 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift @@ -59,7 +59,11 @@ extension PageListViewController: InteractivePostViewDelegate { // Not available for pages } - func setParent(for apost: AbstractPost) { + func showSettings(for post: AbstractPost) { + // TODO: + } + + func setParent(for apost: AbstractPost, at indexPath: IndexPath) { guard let page = apost as? Page else { return } setParentPage(for: page) } diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift index f5ad07299e08..93aa543b4ca9 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostListViewController.swift @@ -104,7 +104,7 @@ class AbstractPostListViewController: UIViewController, configureTableView() configureSearchController() configureAuthorFilter() - configureNavigationBarAppearance() + configureDefaultNavigationBarAppearance() updateAndPerformFetchRequest() @@ -203,19 +203,6 @@ class AbstractPostListViewController: UIViewController, } } - private func configureNavigationBarAppearance() { - let standardAppearance = UINavigationBarAppearance() - standardAppearance.configureWithDefaultBackground() - - let scrollEdgeAppearance = UINavigationBarAppearance() - scrollEdgeAppearance.configureWithTransparentBackground() - - navigationItem.standardAppearance = standardAppearance - navigationItem.compactAppearance = standardAppearance - navigationItem.scrollEdgeAppearance = scrollEdgeAppearance - navigationItem.compactScrollEdgeAppearance = scrollEdgeAppearance - } - func propertiesForAnalytics() -> [String: AnyObject] { var properties = [String: AnyObject]() diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift index 22b78fdba9b3..805106330e44 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuHelper.swift @@ -91,6 +91,7 @@ extension AbstractPostButton: AbstractPostMenuAction { case .share: return UIImage(systemName: "square.and.arrow.up") case .blaze: return UIImage(systemName: "flame") case .comments: return UIImage(systemName: "bubble") + case .settings: return UIImage(systemName: "gearshape") case .setParent: return UIImage(systemName: "text.append") case .setHomepage: return UIImage(systemName: "house") case .setPostsPage: return UIImage(systemName: "text.word.spacing") @@ -121,6 +122,7 @@ extension AbstractPostButton: AbstractPostMenuAction { case .share: return Strings.share case .blaze: return Strings.blaze case .comments: return Strings.comments + case .settings: return Strings.settings case .setParent: return Strings.setParent case .setHomepage: return Strings.setHomepage case .setPostsPage: return Strings.setPostsPage @@ -153,6 +155,8 @@ extension AbstractPostButton: AbstractPostMenuAction { delegate.blaze(post) case .comments: delegate.comments(post) + case .settings: + delegate.showSettings(for: post) case .setParent: delegate.setParent(for: post) case .setHomepage: @@ -170,6 +174,7 @@ extension AbstractPostButton: AbstractPostMenuAction { static let cancelAutoUpload = NSLocalizedString("posts.cancelUpload.actionTitle", value: "Cancel upload", comment: "Label for the Post List option that cancels automatic uploading of a post.") static let stats = NSLocalizedString("posts.stats.actionTitle", value: "Stats", comment: "Label for post stats option. Tapping displays statistics for a post.") static let comments = NSLocalizedString("posts.comments.actionTitle", value: "Comments", comment: "Label for post comments option. Tapping displays comments for a post.") + static let settings = NSLocalizedString("posts.settings.actionTitle", value: "Settings", comment: "Label for post settings option. Tapping displays settings for a post.") static let duplicate = NSLocalizedString("posts.duplicate.actionTitle", value: "Duplicate", comment: "Label for post duplicate option. Tapping creates a copy of the post.") static let publish = NSLocalizedString("posts.publish.actionTitle", value: "Publish now", comment: "Label for an option that moves a publishes a post immediately") static let draft = NSLocalizedString("posts.draft.actionTitle", value: "Move to draft", comment: "Label for an option that moves a post to the draft folder") diff --git a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift index a2cc7e4c8ffe..47f0f3994035 100644 --- a/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/AbstractPostMenuViewModel.swift @@ -26,6 +26,7 @@ enum AbstractPostButton: Equatable { case share case blaze case comments + case settings /// Specific to pages case pageAttributes diff --git a/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift b/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift index cdd2afc54ad2..1640edcf9d5d 100644 --- a/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift +++ b/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift @@ -13,7 +13,8 @@ protocol InteractivePostViewDelegate: AnyObject { func share(_ post: AbstractPost, fromView view: UIView) func blaze(_ post: AbstractPost) func comments(_ post: AbstractPost) - func setParent(for post: AbstractPost) + func showSettings(for post: AbstractPost) + func setParent(for post: AbstractPost, at indexPath: IndexPath) func setHomepage(for post: AbstractPost) func setPostsPage(for post: AbstractPost) func setRegularPage(for post: AbstractPost) diff --git a/WordPress/Classes/ViewRelated/Post/PostCardStatusViewModel.swift b/WordPress/Classes/ViewRelated/Post/PostCardStatusViewModel.swift index a652c571f2b6..783a7dead13e 100644 --- a/WordPress/Classes/ViewRelated/Post/PostCardStatusViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/PostCardStatusViewModel.swift @@ -199,6 +199,9 @@ class PostCardStatusViewModel: NSObject, AbstractPostMenuViewModel { if isJetpackFeaturesEnabled, post.status == .publish && post.hasRemote() { buttons.append(contentsOf: [.stats, .comments]) } + if post.status != .trash { + buttons.append(.settings) + } return AbstractPostButtonSection(buttons: buttons) } diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 7596b0ddc291..45a977f71423 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -426,6 +426,15 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe try? contentCoordinator.displayCommentsWithPostId(post.postID, siteID: blog.dotComID, commentID: nil, source: .postsList) } + func showSettings(for post: AbstractPost) { + let viewController = PostSettingsViewController(post: post.latest()) + viewController.hidesBottomBarWhenPushed = true + viewController.isStandalone = true + let navigation = UINavigationController(rootViewController: viewController) + navigation.navigationBar.isTranslucent = true // Reset to default + self.present(navigation, animated: true) + } + // MARK: - NetworkAwareUI override func noConnectionMessage() -> String { diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift new file mode 100644 index 000000000000..d379a5950032 --- /dev/null +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift @@ -0,0 +1,62 @@ +import UIKit +import CoreData +import Combine + +extension PostSettingsViewController { + @objc func setupStandaloneEditor() { + guard isStandalone else { return } + + configureDefaultNavigationBarAppearance() + + refreshNavigationBarButtons() + navigationItem.rightBarButtonItem?.isEnabled = false + + var cancellables: [AnyCancellable] = [] + apost.objectWillChange.sink { [weak self] in + self?.navigationItem.rightBarButtonItem?.isEnabled = true + }.store(in: &cancellables) + objc_setAssociatedObject(self, &PostSettingsViewController.cancellablesKey, cancellables, .OBJC_ASSOCIATION_RETAIN_NONATOMIC) + } + + private func refreshNavigationBarButtons() { + navigationItem.leftBarButtonItem = UIBarButtonItem(barButtonSystemItem: .cancel, target: self, action: #selector(buttonCancelTapped)) + + navigationItem.rightBarButtonItem = UIBarButtonItem(barButtonSystemItem: .done, target: self, action: #selector(buttonDoneTapped)) + } + + @objc private func buttonCancelTapped() { + presentingViewController?.dismiss(animated: true) + } + + @objc private func buttonDoneTapped() { + let activityIndicator = UIActivityIndicatorView(style: .medium) + activityIndicator.startAnimating() + + navigationItem.rightBarButtonItem = UIBarButtonItem(customView: activityIndicator) + + setEnabled(false) + + PostCoordinator.shared.save(apost) { [weak self] result in + switch result { + case .success: + self?.isStandaloneEditorDismissingAfterSave = true + self?.presentingViewController?.dismiss(animated: true) + case .failure: + self?.setEnabled(true) + SVProgressHUD.showError(withStatus: Strings.errorMessage) + self?.refreshNavigationBarButtons() + } + } + } + + private func setEnabled(_ isEnabled: Bool) { + tableView.tintAdjustmentMode = isEnabled ? .automatic : .dimmed + tableView.isUserInteractionEnabled = isEnabled + } + + private static var cancellablesKey: UInt8 = 0 +} + +private enum Strings { + static let errorMessage = NSLocalizedString("postSettings.updateFailedMessage", value: "Failed to update the post settings", comment: "Error message on post/page settings screen") +} diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.h b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.h index 412f4b5cebc2..82e6b9087968 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.h +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.h @@ -13,6 +13,8 @@ - (void)endEditingAction:(nullable id)sender; @property (nonnull, nonatomic, strong, readonly) AbstractPost *apost; +@property (nonatomic) BOOL isStandalone; +@property (nonatomic) BOOL isStandaloneEditorDismissingAfterSave; @property (nonnull, nonatomic, strong, readonly) NSArray *publicizeConnections; @property (nonnull, nonatomic, strong, readonly) NSArray *unsupportedConnections; diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m index 4245d8e39592..b671874d9058 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController.m @@ -159,6 +159,7 @@ - (void)viewDidLoad // reachability callbacks to trigger before such initial setup completes. // [self setupReachability]; + [self setupStandaloneEditor]; } - (void)viewWillAppear:(BOOL)animated @@ -177,9 +178,15 @@ - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; - [self.apost.managedObjectContext performBlock:^{ - [self.apost.managedObjectContext save:nil]; - }]; + if (self.isStandalone) { + if (!self.isStandaloneEditorDismissingAfterSave) { + [self.apost.managedObjectContext refreshObject:self.apost mergeChanges:NO]; + } + } else { + [self.apost.managedObjectContext performBlock:^{ + [self.apost.managedObjectContext save:nil]; + }]; + } } - (void)didReceiveMemoryWarning @@ -1373,7 +1380,9 @@ - (void)postCategoriesViewController:(PostCategoriesViewController *)controller // Save changes. self.post.categories = [categories mutableCopy]; - [self.post save]; + if (!self.isStandalone) { + [self.post save]; + } } #pragma mark - PostFeaturedImageCellDelegate diff --git a/WordPress/WordPress.xcodeproj/project.pbxproj b/WordPress/WordPress.xcodeproj/project.pbxproj index 4d9b9409d866..702c7894909e 100644 --- a/WordPress/WordPress.xcodeproj/project.pbxproj +++ b/WordPress/WordPress.xcodeproj/project.pbxproj @@ -516,6 +516,8 @@ 0CF7D6C32ABB753A006D1E89 /* MediaImageServiceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CF7D6C22ABB753A006D1E89 /* MediaImageServiceTests.swift */; }; 0CFE9AC62AF44A9F00B8F659 /* AbstractPostHelper+Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFE9AC52AF44A9F00B8F659 /* AbstractPostHelper+Actions.swift */; }; 0CFE9AC72AF44A9F00B8F659 /* AbstractPostHelper+Actions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFE9AC52AF44A9F00B8F659 /* AbstractPostHelper+Actions.swift */; }; + 0CFE9AC92AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFE9AC82AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift */; }; + 0CFE9ACA2AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0CFE9AC82AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift */; }; 1702BBDC1CEDEA6B00766A33 /* BadgeLabel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1702BBDB1CEDEA6B00766A33 /* BadgeLabel.swift */; }; 1702BBE01CF3034E00766A33 /* DomainsService.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1702BBDF1CF3034E00766A33 /* DomainsService.swift */; }; 17039225282E6D2800F602E9 /* ViewsVisitorsLineChartCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = DC772B0728201F5300664C02 /* ViewsVisitorsLineChartCell.swift */; }; @@ -6197,6 +6199,7 @@ 0CF7D6C22ABB753A006D1E89 /* MediaImageServiceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MediaImageServiceTests.swift; sourceTree = ""; }; 0CFD6C792A73E703003DD0A0 /* WordPress 152.xcdatamodel */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcdatamodel; path = "WordPress 152.xcdatamodel"; sourceTree = ""; }; 0CFE9AC52AF44A9F00B8F659 /* AbstractPostHelper+Actions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "AbstractPostHelper+Actions.swift"; sourceTree = ""; }; + 0CFE9AC82AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PostSettingsViewController+Swift.swift"; sourceTree = ""; }; 131D0EE49695795ECEDAA446 /* Pods-WordPressTest.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WordPressTest.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-WordPressTest/Pods-WordPressTest.release-alpha.xcconfig"; sourceTree = ""; }; 150B6590614A28DF9AD25491 /* Pods-Apps-Jetpack.release-alpha.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Apps-Jetpack.release-alpha.xcconfig"; path = "../Pods/Target Support Files/Pods-Apps-Jetpack/Pods-Apps-Jetpack.release-alpha.xcconfig"; sourceTree = ""; }; 152F25D5C232985E30F56CAC /* Pods-Apps-Jetpack.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Apps-Jetpack.debug.xcconfig"; path = "../Pods/Target Support Files/Pods-Apps-Jetpack/Pods-Apps-Jetpack.debug.xcconfig"; sourceTree = ""; }; @@ -14899,6 +14902,7 @@ 5D62BAD818AAAE9B0044E5F7 /* PostSettingsViewController_Internal.h */, ACBAB5FC0E121C7300F38795 /* PostSettingsViewController.h */, ACBAB5FD0E121C7300F38795 /* PostSettingsViewController.m */, + 0CFE9AC82AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift */, FFEECFFB2084DE2B009B8CDB /* PostSettingsViewController+FeaturedImageUpload.swift */, 83914BD32A2EA03A0017A588 /* PostSettingsViewController+JetpackSocial.swift */, 8B260D7D2444FC9D0010F756 /* PostVisibilitySelectorViewController.swift */, @@ -22242,6 +22246,7 @@ 436D562B2117312700CEAA33 /* RegisterDomainDetailsErrorSectionFooter.swift in Sources */, 7E729C28209A087300F76599 /* ImageLoader.swift in Sources */, 3FAF9CC226D01CFE00268EA2 /* DomainsDashboardView.swift in Sources */, + 0CFE9AC92AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift in Sources */, 73C8F06821BF1A5E00DDDF7E /* SiteAssemblyContentView.swift in Sources */, 178DDD30266D7576006C68C4 /* BloggingRemindersFlowCompletionViewController.swift in Sources */, 5D146EBB189857ED0068FDC6 /* FeaturedImageViewController.m in Sources */, @@ -25239,6 +25244,7 @@ F4CBE3DA29265BC8004FFBB6 /* LogOutActionHandler.swift in Sources */, FABB24C22602FC2C00C8785C /* WPSplitViewController.swift in Sources */, FABB24C32602FC2C00C8785C /* CollectionViewContainerRow.swift in Sources */, + 0CFE9ACA2AF52D3B00B8F659 /* PostSettingsViewController+Swift.swift in Sources */, FABB24C42602FC2C00C8785C /* JetpackConnectionWebViewController.swift in Sources */, FABB24C52602FC2C00C8785C /* SiteSuggestion+CoreDataProperties.swift in Sources */, F47E154B29E84A9300B6E426 /* SiteCreationPurchasingWebFlowController.swift in Sources */, From 934c6a0dc146f8b73ec1f8a4a77c340541d03c7c Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 3 Nov 2023 11:15:13 -0400 Subject: [PATCH 2/5] Add Settings context menu action to Pages --- .../Pages/PageListViewController+Menu.swift | 2 +- .../Post/InteractivePostViewDelegate.swift | 2 +- .../ViewRelated/Post/PageMenuViewModel.swift | 3 +++ .../ViewRelated/Post/PostListViewController.swift | 8 +------- .../Post/PostSettingsViewController+Swift.swift | 13 +++++++++++++ 5 files changed, 19 insertions(+), 9 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift index 122b883d4c7d..8139c1a09fb9 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift @@ -60,7 +60,7 @@ extension PageListViewController: InteractivePostViewDelegate { } func showSettings(for post: AbstractPost) { - // TODO: + PostSettingsViewController.showStandaloneEditor(for: post, from: self) } func setParent(for apost: AbstractPost, at indexPath: IndexPath) { diff --git a/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift b/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift index 1640edcf9d5d..ec4a2ac0113c 100644 --- a/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift +++ b/WordPress/Classes/ViewRelated/Post/InteractivePostViewDelegate.swift @@ -14,7 +14,7 @@ protocol InteractivePostViewDelegate: AnyObject { func blaze(_ post: AbstractPost) func comments(_ post: AbstractPost) func showSettings(for post: AbstractPost) - func setParent(for post: AbstractPost, at indexPath: IndexPath) + func setParent(for post: AbstractPost) func setHomepage(for post: AbstractPost) func setPostsPage(for post: AbstractPost) func setRegularPage(for post: AbstractPost) diff --git a/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift b/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift index 7b73b71b3a04..407673651b13 100644 --- a/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift +++ b/WordPress/Classes/ViewRelated/Post/PageMenuViewModel.swift @@ -101,6 +101,9 @@ final class PageMenuViewModel: AbstractPostMenuViewModel { } else { buttons.append(.setRegularPage) } + if page.status != .trash { + buttons.append(.settings) + } return AbstractPostButtonSection(buttons: buttons, submenuButton: .pageAttributes) } diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index 45a977f71423..d6985f60b01a 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -5,7 +5,6 @@ import Gridicons import UIKit class PostListViewController: AbstractPostListViewController, UIViewControllerRestoration, InteractivePostViewDelegate { - private let statsStoryboardName = "SiteStats" private let currentPostListStatusFilterKey = "CurrentPostListStatusFilterKey" @@ -427,12 +426,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } func showSettings(for post: AbstractPost) { - let viewController = PostSettingsViewController(post: post.latest()) - viewController.hidesBottomBarWhenPushed = true - viewController.isStandalone = true - let navigation = UINavigationController(rootViewController: viewController) - navigation.navigationBar.isTranslucent = true // Reset to default - self.present(navigation, animated: true) + PostSettingsViewController.showStandaloneEditor(for: post, from: self) } // MARK: - NetworkAwareUI diff --git a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift index d379a5950032..f6ff9c80905d 100644 --- a/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift +++ b/WordPress/Classes/ViewRelated/Post/PostSettingsViewController+Swift.swift @@ -3,6 +3,19 @@ import CoreData import Combine extension PostSettingsViewController { + static func showStandaloneEditor(for post: AbstractPost, from presentingViewController: UIViewController) { + let viewController: PostSettingsViewController + if let post = post as? Post { + viewController = PostSettingsViewController(post: post.latest()) + } else { + viewController = PageSettingsViewController(post: post) + } + viewController.isStandalone = true + let navigation = UINavigationController(rootViewController: viewController) + navigation.navigationBar.isTranslucent = true // Reset to default + presentingViewController.present(navigation, animated: true) + } + @objc func setupStandaloneEditor() { guard isStandalone else { return } From 17af6daf6eb9cf8e0312adec20eb333bcd4cda1f Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 3 Nov 2023 12:12:39 -0400 Subject: [PATCH 3/5] Add analytics --- WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift | 5 +++++ .../ViewRelated/Pages/PageListViewController+Menu.swift | 1 + .../Classes/ViewRelated/Post/PostListViewController.swift | 1 + 3 files changed, 7 insertions(+) diff --git a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift index bdaec020cac8..7631ef7d5e44 100644 --- a/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift +++ b/WordPress/Classes/Utility/Analytics/WPAnalyticsEvent.swift @@ -259,6 +259,7 @@ import Foundation case postListSetAsPostsPageAction case postListSetHomePageAction case postListSetAsRegularPageAction + case postListSettingsAction // Page List case pageListEditHomepageTapped @@ -970,6 +971,8 @@ import Foundation return "post_list_button_pressed" case .postListSetAsRegularPageAction: return "post_list_button_pressed" + case .postListSettingsAction: + return "post_list_button_pressed" // Page List case .pageListEditHomepageTapped: @@ -1429,6 +1432,8 @@ import Foundation return ["button": "set_homepage"] case .postListSetAsRegularPageAction: return ["button": "set_regular_page"] + case .postListSettingsAction: + return ["button": "settings"] default: return nil } diff --git a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift index 8139c1a09fb9..311b4c90a971 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageListViewController+Menu.swift @@ -60,6 +60,7 @@ extension PageListViewController: InteractivePostViewDelegate { } func showSettings(for post: AbstractPost) { + WPAnalytics.track(.postListSettingsAction, properties: propertiesForAnalytics()) PostSettingsViewController.showStandaloneEditor(for: post, from: self) } diff --git a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift index d6985f60b01a..ef9d78e67873 100644 --- a/WordPress/Classes/ViewRelated/Post/PostListViewController.swift +++ b/WordPress/Classes/ViewRelated/Post/PostListViewController.swift @@ -426,6 +426,7 @@ class PostListViewController: AbstractPostListViewController, UIViewControllerRe } func showSettings(for post: AbstractPost) { + WPAnalytics.track(.postListSettingsAction, properties: propertiesForAnalytics()) PostSettingsViewController.showStandaloneEditor(for: post, from: self) } From 6364b50c6f6e1eec551dfb37d92d9c32c22c38f8 Mon Sep 17 00:00:00 2001 From: kean Date: Fri, 3 Nov 2023 18:38:56 -0400 Subject: [PATCH 4/5] Fix Xcode warning --- WordPress/Classes/Services/PostCoordinator.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WordPress/Classes/Services/PostCoordinator.swift b/WordPress/Classes/Services/PostCoordinator.swift index e4e1de383fa5..fe938747342e 100644 --- a/WordPress/Classes/Services/PostCoordinator.swift +++ b/WordPress/Classes/Services/PostCoordinator.swift @@ -492,7 +492,6 @@ class PostCoordinator: NSObject { setPendingDeletion(true, post: post) - let originalStatus = post.status let trashed = (post.status == .trash) let repository = PostRepository(coreDataStack: ContextManager.shared) From d5de113387ffef7ef39282862bb84cac7e4d1f5d Mon Sep 17 00:00:00 2001 From: kean Date: Mon, 6 Nov 2023 11:38:43 -0500 Subject: [PATCH 5/5] Fix tests --- .../ViewRelated/Pages/PageMenuViewModelTests.swift | 10 +++++----- .../Post/Views/PostCardStatusViewModelTests.swift | 7 +++++-- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Pages/PageMenuViewModelTests.swift b/WordPress/Classes/ViewRelated/Pages/PageMenuViewModelTests.swift index 4ea70295de37..9f666889c8b5 100644 --- a/WordPress/Classes/ViewRelated/Pages/PageMenuViewModelTests.swift +++ b/WordPress/Classes/ViewRelated/Pages/PageMenuViewModelTests.swift @@ -26,7 +26,7 @@ final class PageMenuViewModelTests: CoreDataTestCase { [.view], [.moveToDraft, .duplicate], [.blaze], - [.setParent, .setHomepage, .setPostsPage], + [.setParent, .setHomepage, .setPostsPage, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -53,7 +53,7 @@ final class PageMenuViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.moveToDraft, .duplicate], - [.setParent, .setHomepage, .setPostsPage], + [.setParent, .setHomepage, .setPostsPage, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -80,7 +80,7 @@ final class PageMenuViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.moveToDraft, .duplicate], - [.setParent, .setHomepage, .setPostsPage], + [.setParent, .setHomepage, .setPostsPage, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -108,7 +108,7 @@ final class PageMenuViewModelTests: CoreDataTestCase { [.view], [.duplicate], [.blaze], - [.setParent, .setPostsPage] + [.setParent, .setPostsPage, .settings] ] expect(buttons).to(equal(expectedButtons)) } @@ -135,7 +135,7 @@ final class PageMenuViewModelTests: CoreDataTestCase { [.view], [.moveToDraft, .duplicate], [.blaze], - [.setParent, .setHomepage, .setRegularPage], + [.setParent, .setHomepage, .setRegularPage, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) diff --git a/WordPress/WordPressTest/ViewRelated/Post/Views/PostCardStatusViewModelTests.swift b/WordPress/WordPressTest/ViewRelated/Post/Views/PostCardStatusViewModelTests.swift index 9c81160653da..109d4c3b09d2 100644 --- a/WordPress/WordPressTest/ViewRelated/Post/Views/PostCardStatusViewModelTests.swift +++ b/WordPress/WordPressTest/ViewRelated/Post/Views/PostCardStatusViewModelTests.swift @@ -20,7 +20,7 @@ class PostCardStatusViewModelTests: CoreDataTestCase { [.view], [.moveToDraft, .duplicate, .share], [.blaze], - [.stats, .comments], + [.stats, .comments, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -41,7 +41,7 @@ class PostCardStatusViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.moveToDraft, .duplicate, .share], - [.stats, .comments], + [.stats, .comments, .settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -62,6 +62,7 @@ class PostCardStatusViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.moveToDraft, .duplicate, .share], + [.settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -81,6 +82,7 @@ class PostCardStatusViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.duplicate, .publish], + [.settings], [.trash] ] expect(buttons).to(equal(expectedButtons)) @@ -100,6 +102,7 @@ class PostCardStatusViewModelTests: CoreDataTestCase { let expectedButtons: [[AbstractPostButton]] = [ [.view], [.moveToDraft], + [.settings], [.trash] ] expect(buttons).to(equal(expectedButtons))