Skip to content

Commit

Permalink
Fix: return nil for itemToDisplay if view count is also nil
Browse files Browse the repository at this point in the history
The default view count 0 was being supplied to itemToDisplay, which was causing .social to be returned when it should have been returning nil.
  • Loading branch information
Momo Ozawa committed Oct 15, 2021
1 parent c887490 commit b4fb243
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ private extension SiteStatsInsightsTableViewController {
}

func loadPinnedCards() {
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount
switch pinnedItemStore?.itemToDisplay(for: viewsCount) {
case .none:
insightsToShow = insightsToShow.filter { $0 != .growAudience || $0 != .customize }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class SiteStatsInsightsViewModel: Observable {
self.insightsToShow = insightsToShow
self.insightsStore = insightsStore
self.pinnedItemStore = pinnedItemStore
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount ?? 0
let viewsCount = insightsStore.getAllTimeStats()?.viewsCount
self.itemToDisplay = pinnedItemStore?.itemToDisplay(for: viewsCount)

insightsChangeReceipt = self.insightsStore.onChange { [weak self] in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@ final class SiteStatsPinnedItemStore {
self.siteId = siteId
}

func itemToDisplay(for siteViewsCount: Int) -> SiteStatsPinnable? {
func itemToDisplay(for siteViewsCount: Int?) -> SiteStatsPinnable? {
guard let siteViewsCount = siteViewsCount else {
return nil
}

if siteViewsCount < lowSiteViewsCountTreshold {
return nudgeToDisplay ?? customizeToDisplay
} else {
Expand Down

0 comments on commit b4fb243

Please sign in to comment.