Skip to content

Commit 8c5cd31

Browse files
committed
Stats revamp: Use new Totals cell for Followers
1 parent 1ccd61b commit 8c5cd31

File tree

4 files changed

+46
-3
lines changed

4 files changed

+46
-3
lines changed

WordPress/Classes/Stores/StatsInsightsStore.swift

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -938,6 +938,19 @@ extension StatsInsightsStore {
938938
return state.emailFollowers
939939
}
940940

941+
func getTotalFollowerCount() -> Int {
942+
let totalDotComFollowers = getDotComFollowers()?.dotComFollowersCount ?? 0
943+
let totalEmailFollowers = getEmailFollowers()?.emailFollowersCount ?? 0
944+
945+
var totalPublicize = 0
946+
if let publicize = getPublicize(),
947+
!publicize.publicizeServices.isEmpty {
948+
totalPublicize = publicize.publicizeServices.compactMap({$0.followers}).reduce(0, +)
949+
}
950+
951+
return totalDotComFollowers + totalEmailFollowers + totalPublicize
952+
}
953+
941954
func getPublicize() -> StatsPublicizeInsight? {
942955
return state.publicizeFollowers
943956
}

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsTableViewController.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,7 @@ private extension SiteStatsInsightsTableViewController {
177177
TabbedTotalsStatsRow.self,
178178
TopTotalsInsightStatsRow.self,
179179
MostPopularTimeInsightStatsRow.self,
180+
TotalInsightStatsRow.self,
180181
TableFooterRow.self,
181182
StatsErrorRow.self,
182183
StatsGhostGrowAudienceImmutableRow.self,

WordPress/Classes/ViewRelated/Stats/Insights/SiteStatsInsightsViewModel.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,13 @@ class SiteStatsInsightsViewModel: Observable {
126126
type: .insights,
127127
status: insightsStore.followersTotalsStatus,
128128
block: {
129+
if FeatureFlag.statsNewInsights.enabled {
130+
return TotalInsightStatsRow(dataRow: createFollowerTotalInsightsRow(), statSection: .insightsFollowerTotals, siteStatsInsightsDelegate: siteStatsInsightsDelegate)
131+
} else {
129132
return TwoColumnStatsRow(dataRows: createTotalFollowersRows(),
130133
statSection: .insightsFollowerTotals,
131134
siteStatsInsightsDelegate: nil)
135+
}
132136
}, loading: {
133137
return StatsGhostTwoColumnImmutableRow()
134138
}, error: errorBlock))
@@ -413,12 +417,12 @@ private extension SiteStatsInsightsViewModel {
413417
let totalEmailFollowers = insightsStore.getEmailFollowers()?.emailFollowersCount ?? 0
414418

415419
var totalPublicize = 0
416-
if let publicize = insightsStore.getPublicize(), !publicize.publicizeServices.isEmpty {
420+
if let publicize = insightsStore.getPublicize(),
421+
!publicize.publicizeServices.isEmpty {
417422
totalPublicize = publicize.publicizeServices.compactMap({$0.followers}).reduce(0, +)
418423
}
419424

420-
let totalFollowers = totalDotComFollowers + totalEmailFollowers + totalPublicize
421-
425+
let totalFollowers = insightsStore.getTotalFollowerCount()
422426
guard totalFollowers > 0 else {
423427
return []
424428
}
@@ -438,6 +442,10 @@ private extension SiteStatsInsightsViewModel {
438442
return dataRows
439443
}
440444

445+
func createFollowerTotalInsightsRow() -> StatsTotalInsightsData {
446+
return StatsTotalInsightsData(count: insightsStore.getTotalFollowerCount().abbreviatedString())
447+
}
448+
441449
func createPublicizeRows() -> [StatsTotalRowData] {
442450
guard let services = insightsStore.getPublicize()?.publicizeServices else {
443451
return []

WordPress/Classes/ViewRelated/Stats/SiteStatsTableViewCells.swift

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,27 @@ struct MostPopularTimeInsightStatsRow: ImmuTableRow {
287287
}
288288
}
289289

290+
struct TotalInsightStatsRow: ImmuTableRow {
291+
292+
typealias CellType = StatsTotalInsightsCell
293+
294+
static let cell: ImmuTableCell = {
295+
return ImmuTableCell.class(CellType.self)
296+
}()
297+
298+
let dataRow: StatsTotalInsightsData
299+
let statSection: StatSection
300+
weak var siteStatsInsightsDelegate: SiteStatsInsightsDelegate?
301+
let action: ImmuTableAction? = nil
302+
303+
func configureCell(_ cell: UITableViewCell) {
304+
guard let cell = cell as? CellType else {
305+
return
306+
}
307+
308+
cell.configure(count: dataRow.count, statSection: statSection, siteStatsInsightsDelegate: siteStatsInsightsDelegate)
309+
}
310+
}
290311

291312
// MARK: - Insights Management
292313

0 commit comments

Comments
 (0)