From 22ca46f1c01e7f56b93f5c8e68cfa83ab7b46fcf Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Wed, 7 Jun 2023 16:11:31 +0100 Subject: [PATCH 1/3] add no results view controller to blaze campaigns --- .../BlazeCampaignsViewController.swift | 71 ++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift index 1c9d83eedb51..d7be2f85e62b 100644 --- a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift +++ b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift @@ -1,6 +1,6 @@ import UIKit -final class BlazeCampaignsViewController: UIViewController { +final class BlazeCampaignsViewController: UIViewController, NoResultsViewHost { // MARK: - Views @@ -16,6 +16,14 @@ final class BlazeCampaignsViewController: UIViewController { private var blog: Blog + private var isLoading: Bool = false { + didSet { + if isLoading != oldValue { + showNoResultsViewIfNeeded() + } + } + } + // MARK: - Initializers init(blog: Blog) { @@ -34,6 +42,12 @@ final class BlazeCampaignsViewController: UIViewController { super.viewDidLoad() setupView() setupNavBar() + setupNoResults() + } + + override func viewWillAppear(_ animated: Bool) { + super.viewWillAppear(animated) + fetchCampaigns() } // MARK: - Private helpers @@ -47,15 +61,70 @@ final class BlazeCampaignsViewController: UIViewController { navigationItem.rightBarButtonItem = dismissButton } + private func setupNoResults() { + noResultsViewController.delegate = self + } + + private func fetchCampaigns() { + isLoading = true + + // FIXME: Call BlazeService + } + @objc private func promotePostButtonTapped() { // TODO: Track event BlazeFlowCoordinator.presentBlaze(in: self, source: .campaignsList, blog: blog) } } +// MARK: - No results + +extension BlazeCampaignsViewController: NoResultsViewControllerDelegate { + + private func showNoResultsViewIfNeeded() { + guard !isLoading else { + showLoadingView() + return + } + + // FIXME: if results aren't empty, hide the no results view and return + + showNoResultsView() + } + + private func showNoResultsView() { + hideNoResults() + noResultsViewController.hideImageView() + configureAndDisplayNoResults(on: view, + title: NoResults.emptyTitle, + subtitle: NoResults.emptySubtitle, + buttonTitle: Strings.promoteButtonTitle) + } + + private func showLoadingView() { + hideNoResults() + configureAndDisplayNoResults(on: view, + title: NoResults.loadingTitle, + accessoryView: NoResultsViewController.loadingAccessoryView()) + } + + func actionButtonPressed() { + promotePostButtonTapped() + } +} + +// MARK: - Constants + extension BlazeCampaignsViewController { private enum Strings { static let navigationTitle = NSLocalizedString("blaze.campaigns.title", value: "Blaze Campaigns", comment: "Title for the screen that allows users to manage their Blaze campaigns.") + static let promoteButtonTitle = NSLocalizedString("blaze.campaigns.promote.button.title", value: "Promote", comment: "Button title for the button that shows the Blaze flow when tapped.") + } + + private enum NoResults { + static let loadingTitle = NSLocalizedString("blaze.campaigns.loading.title", value: "Loading campaigns...", comment: "Displayed while Blaze campaigns are being loaded.") + static let emptyTitle = NSLocalizedString("blaze.campaigns.empty.title", value: "You have no campaigns", comment: "Title displayed when there are no Blaze campaigns to display.") + static let emptySubtitle = NSLocalizedString("blaze.campaigns.empty.subtitle", value: "You have not created any campaigns yet. Click promote to get started.", comment: "Text displayed when there are no Blaze campaigns to display.") } } From c8c53c37cb66262e9859424561208f3675d694fb Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Thu, 8 Jun 2023 10:47:20 +0100 Subject: [PATCH 2/3] nest NoResults inside Strings --- .../BlazeCampaignsViewController.swift | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift index d7be2f85e62b..7553abaa16da 100644 --- a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift +++ b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift @@ -96,15 +96,15 @@ extension BlazeCampaignsViewController: NoResultsViewControllerDelegate { hideNoResults() noResultsViewController.hideImageView() configureAndDisplayNoResults(on: view, - title: NoResults.emptyTitle, - subtitle: NoResults.emptySubtitle, + title: Strings.NoResults.emptyTitle, + subtitle: Strings.NoResults.emptySubtitle, buttonTitle: Strings.promoteButtonTitle) } private func showLoadingView() { hideNoResults() configureAndDisplayNoResults(on: view, - title: NoResults.loadingTitle, + title: Strings.NoResults.loadingTitle, accessoryView: NoResultsViewController.loadingAccessoryView()) } @@ -115,16 +115,16 @@ extension BlazeCampaignsViewController: NoResultsViewControllerDelegate { // MARK: - Constants -extension BlazeCampaignsViewController { +private extension BlazeCampaignsViewController { - private enum Strings { + enum Strings { static let navigationTitle = NSLocalizedString("blaze.campaigns.title", value: "Blaze Campaigns", comment: "Title for the screen that allows users to manage their Blaze campaigns.") static let promoteButtonTitle = NSLocalizedString("blaze.campaigns.promote.button.title", value: "Promote", comment: "Button title for the button that shows the Blaze flow when tapped.") - } - private enum NoResults { - static let loadingTitle = NSLocalizedString("blaze.campaigns.loading.title", value: "Loading campaigns...", comment: "Displayed while Blaze campaigns are being loaded.") - static let emptyTitle = NSLocalizedString("blaze.campaigns.empty.title", value: "You have no campaigns", comment: "Title displayed when there are no Blaze campaigns to display.") - static let emptySubtitle = NSLocalizedString("blaze.campaigns.empty.subtitle", value: "You have not created any campaigns yet. Click promote to get started.", comment: "Text displayed when there are no Blaze campaigns to display.") + enum NoResults { + static let loadingTitle = NSLocalizedString("blaze.campaigns.loading.title", value: "Loading campaigns...", comment: "Displayed while Blaze campaigns are being loaded.") + static let emptyTitle = NSLocalizedString("blaze.campaigns.empty.title", value: "You have no campaigns", comment: "Title displayed when there are no Blaze campaigns to display.") + static let emptySubtitle = NSLocalizedString("blaze.campaigns.empty.subtitle", value: "You have not created any campaigns yet. Click promote to get started.", comment: "Text displayed when there are no Blaze campaigns to display.") + } } } From e154ec54693e81ae35c0413347816284ca1a3078 Mon Sep 17 00:00:00 2001 From: Momo Ozawa Date: Thu, 8 Jun 2023 13:14:15 +0100 Subject: [PATCH 3/3] present blaze flow when action button is pressed --- .../Blaze Campaigns/BlazeCampaignsViewController.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift index f86f85d99eec..41fab54086db 100644 --- a/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift +++ b/WordPress/Classes/ViewRelated/Blaze Campaigns/BlazeCampaignsViewController.swift @@ -109,7 +109,7 @@ extension BlazeCampaignsViewController: NoResultsViewControllerDelegate { } func actionButtonPressed() { - promotePostButtonTapped() + BlazeFlowCoordinator.presentBlaze(in: self, source: .campaignsList, blog: blog) } }