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

Empty Stats: Stay on insights tab if Grow Audience card is showing #17332

Merged
merged 2 commits into from
Oct 18, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion WordPress/Classes/Utility/ContentCoordinator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,17 @@ struct DefaultContentCoordinator: ContentCoordinator {
}

private func setTimePeriodForStatsURLIfPossible(_ url: URL) {
guard let key = SiteStatsDashboardViewController.lastSelectedStatsPeriodTypeKey else {
return
}

let matcher = RouteMatcher(routes: UniversalLinkRouter.statsRoutes)
let matches = matcher.routesMatching(url)
if let match = matches.first,
let action = match.action as? StatsRoute,
let timePeriod = action.timePeriod {
// Initializing a StatsPeriodType to ensure we have a valid period
UserDefaults.standard.set(timePeriod.rawValue, forKey: SiteStatsDashboardViewController.lastSelectedStatsPeriodTypeKey)
UserDefaults.standard.set(timePeriod.rawValue, forKey: key)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ class SiteStatsInsightsTableViewController: UITableViewController, StoryboardLoa
static var defaultStoryboardName: String = "SiteStatsDashboard"

// MARK: - Properties
var isGrowAudienceShowing: Bool {
return insightsToShow.contains(.growAudience)
}

private var insightsChangeReceipt: Receipt?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,13 @@ fileprivate extension StatsPeriodType {

class SiteStatsDashboardViewController: UIViewController {

static let lastSelectedStatsPeriodTypeKey = "LastSelectedStatsPeriodType"
static var lastSelectedStatsPeriodTypeKey: String? {
guard let siteID = SiteStatsInformation.sharedInstance.siteID?.intValue else {
return nil
}
return "LastSelectedStatsPeriodType-\(siteID)"
}

static let lastSelectedStatsDateKey = "LastSelectedStatsDate"

// MARK: - Properties
Expand Down Expand Up @@ -148,11 +154,23 @@ private extension SiteStatsDashboardViewController {
private extension SiteStatsDashboardViewController {

func saveSelectedPeriodToUserDefaults() {
UserDefaults.standard.set(currentSelectedPeriod.rawValue, forKey: Self.lastSelectedStatsPeriodTypeKey)

guard let key = Self.lastSelectedStatsPeriodTypeKey,
!insightsTableViewController.isGrowAudienceShowing else {
return
}

UserDefaults.standard.set(currentSelectedPeriod.rawValue, forKey: key)
}

func getSelectedPeriodFromUserDefaults() -> StatsPeriodType {
return StatsPeriodType(rawValue: UserDefaults.standard.integer(forKey: Self.lastSelectedStatsPeriodTypeKey)) ?? .insights

guard let key = Self.lastSelectedStatsPeriodTypeKey,
let periodType = StatsPeriodType(rawValue: UserDefaults.standard.integer(forKey: key)) else {
return .insights
}

return periodType
}

func getLastSelectedDateFromUserDefaults() -> Date? {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ class MySitesCoordinator: NSObject {
UserDefaults.standard.set(date, forKey: SiteStatsDashboardViewController.lastSelectedStatsDateKey)
}

UserDefaults.standard.set(timePeriod.rawValue, forKey: SiteStatsDashboardViewController.lastSelectedStatsPeriodTypeKey)
guard let key = SiteStatsDashboardViewController.lastSelectedStatsPeriodTypeKey else {
return
}

UserDefaults.standard.set(timePeriod.rawValue, forKey: key)

mySiteViewController.showDetailView(for: .stats)
}
Expand Down