Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stats: Open People -> Subscribers from Subscribers List card #23077

Merged
merged 5 commits into from Apr 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
39 changes: 30 additions & 9 deletions WordPress/Classes/ViewRelated/People/PeopleViewController.swift
Expand Up @@ -27,6 +27,10 @@ class PeopleViewController: UITableViewController {
}
}

/// Default Filter value when People loads
///
fileprivate var defaultFilter = Filter.users

/// NoResults Helper
///
private let noResultsViewController = NoResultsViewController.controller()
Expand Down Expand Up @@ -240,12 +244,9 @@ extension PeopleViewController: NetworkStatusDelegate {
}
}

// MARK: - Private behavior

private extension PeopleViewController {

// MARK: Enums
// MARK: - Enum

extension PeopleViewController {
enum Filter: String, CaseIterable, FilterTabBarItem {

case users = "users"
Expand All @@ -262,11 +263,11 @@ private extension PeopleViewController {
case .users:
return NSLocalizedString("Users", comment: "Blog Users")
case .followers:
return NSLocalizedString("Followers", comment: "Blog Followers")
return NSLocalizedString("users.list.title.subscribers", value: "Subscribers", comment: "Site Subscribers")
case .viewers:
return NSLocalizedString("Viewers", comment: "Blog Viewers")
case .email:
return NSLocalizedString("Email Followers", comment: "Blog Email Followers")
return NSLocalizedString("users.list.title.subscribers", value: "Email Subscribers", comment: "Site Email Subscribers")
}
}

Expand Down Expand Up @@ -296,6 +297,11 @@ private extension PeopleViewController {
}
}
}
}

// MARK: - Private behavior

private extension PeopleViewController {

enum Storyboard {
static let inviteSegueIdentifier = "invite"
Expand Down Expand Up @@ -497,8 +503,9 @@ private extension PeopleViewController {
filterBar.items = filtersAvailableForBlog(blog)
filterBar.addTarget(self, action: #selector(selectedFilterDidChange(_:)), for: .valueChanged)

// By default, let's display the Blog's Users
filter = .users
let indexToSet = Filter.allCases.firstIndex(where: { $0 == defaultFilter }) ?? 0
Copy link
Contributor

@guarani guarani Apr 26, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:

Suggested change
let indexToSet = Filter.allCases.firstIndex(where: { $0 == defaultFilter }) ?? 0
let indexToSet = Filter.allCases.firstIndex(of: defaultFilter) ?? 0

Also, I think a force unwrap is OK since we know that defaultFilter is present in allCases.

filterBar.setSelectedIndex(indexToSet)
filter = defaultFilter
}

func setupTableView() {
Expand Down Expand Up @@ -555,3 +562,17 @@ extension PeopleViewController {
WPAnalytics.track(.peopleFilterChanged, properties: [:], blog: blog)
}
}

extension PeopleViewController {
class func controllerWithBlog(_ blog: Blog, selectedFilter: Filter) -> PeopleViewController? {
let storyboard = UIStoryboard(name: "People", bundle: nil)
guard let viewController = storyboard.instantiateInitialViewController() as? PeopleViewController else {
return nil
}

viewController.defaultFilter = selectedFilter
viewController.blog = blog

return viewController
}
}
Expand Up @@ -28,13 +28,13 @@ final class PersonViewController: UITableViewController {
var title: String {
switch self {
case .User:
return NSLocalizedString("Blog's User", comment: "Blog's User Profile. Displayed when the name is empty!")
return NSLocalizedString("user.details.title.user", value: "Site's User", comment: "Sites's User Profile. Displayed when the name is empty!")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea to use "Site" instead 👍

case .Follower:
return NSLocalizedString("Blog's Follower", comment: "Blog's Follower Profile. Displayed when the name is empty!")
return NSLocalizedString("user.details.title.subscriber", value: "Site's Subscriber", comment: "Site's Subscriber Profile. Displayed when the name is empty!")
case .Viewer:
return NSLocalizedString("Blog's Viewer", comment: "Blog's Viewer Profile. Displayed when the name is empty!")
return NSLocalizedString("user.details.title.viewer", value: "Site's Viewer", comment: "Site's Viewers Profile. Displayed when the name is empty!")
case .Email:
return NSLocalizedString("Blog's Email Follower", comment: "Blog's Email Follower Profile. Displayed when the name is empty!")
return NSLocalizedString("user.details.title.emailSubscriber", value: "Site's Email Subscriber", comment: "Site's Email Subscriber Profile. Displayed when the name is empty!")
}
}
}
Expand Down
Expand Up @@ -40,7 +40,10 @@ private extension ViewMoreRow {
backgroundColor = .listForeground
viewMoreLabel.text = NSLocalizedString("View more", comment: "Label for viewing more stats.")
viewMoreLabel.textColor = WPStyleGuide.Stats.actionTextColor
if statSection == .insightsFollowersWordPress || statSection == .insightsFollowersEmail {
if statSection == .insightsFollowersWordPress ||
statSection == .insightsFollowersEmail ||
statSection == .subscribersList ||
statSection == .subscribersEmailsSummary {
disclosureImageView.isHidden = true
}
}
Expand Down
Expand Up @@ -79,8 +79,18 @@ final class StatsSubscribersViewController: SiteStatsBaseTableViewController {

extension StatsSubscribersViewController: SiteStatsPeriodDelegate {
func viewMoreSelectedForStatSection(_ statSection: StatSection) {
let detailTableViewController = SiteStatsDetailTableViewController.loadFromStoryboard()
detailTableViewController.configure(statSection: statSection)
navigationController?.pushViewController(detailTableViewController, animated: true)
switch statSection {
case .subscribersList:
guard let blog = RootViewCoordinator.sharedPresenter.mySitesCoordinator.currentBlog,
let peopleViewController = PeopleViewController.controllerWithBlog(blog, selectedFilter: .followers) else { return }
navigationController?.pushViewController(peopleViewController, animated: true)
case .subscribersEmailsSummary:
let detailTableViewController = SiteStatsDetailTableViewController.loadFromStoryboard()
detailTableViewController.configure(statSection: statSection)
navigationController?.pushViewController(detailTableViewController, animated: true)
default:
// TODO
DDLogInfo("\(statSection) selected")
}
}
}