Skip to content

Commit

Permalink
Merge pull request wordpress-mobile#20814 from wordpress-mobile/task/…
Browse files Browse the repository at this point in the history
…20764-blaze-campaigns-no-results

Blaze Manage Campaigns: Show loading and empty view in campaigns screen
  • Loading branch information
momo-ozawa authored Jun 8, 2023
2 parents d2aae43 + e154ec5 commit 328640e
Showing 1 changed file with 72 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import UIKit

final class BlazeCampaignsViewController: UIViewController {
final class BlazeCampaignsViewController: UIViewController, NoResultsViewHost {

// MARK: - Views

Expand All @@ -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) {
Expand All @@ -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
Expand All @@ -47,15 +61,70 @@ final class BlazeCampaignsViewController: UIViewController {
navigationItem.rightBarButtonItem = plusButton
}

private func setupNoResults() {
noResultsViewController.delegate = self
}

private func fetchCampaigns() {
isLoading = true

// FIXME: Call BlazeService
}

@objc private func plusButtonTapped() {
// TODO: Track event
BlazeFlowCoordinator.presentBlaze(in: self, source: .campaignsList, blog: blog)
}
}

extension BlazeCampaignsViewController {
// MARK: - No results

extension BlazeCampaignsViewController: NoResultsViewControllerDelegate {

private enum Strings {
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: Strings.NoResults.emptyTitle,
subtitle: Strings.NoResults.emptySubtitle,
buttonTitle: Strings.promoteButtonTitle)
}

private func showLoadingView() {
hideNoResults()
configureAndDisplayNoResults(on: view,
title: Strings.NoResults.loadingTitle,
accessoryView: NoResultsViewController.loadingAccessoryView())
}

func actionButtonPressed() {
BlazeFlowCoordinator.presentBlaze(in: self, source: .campaignsList, blog: blog)
}
}

// MARK: - Constants

private extension BlazeCampaignsViewController {

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.")

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.")
}
}
}

0 comments on commit 328640e

Please sign in to comment.