Skip to content

Commit

Permalink
Clean up code
Browse files Browse the repository at this point in the history
  • Loading branch information
guarani committed Feb 27, 2024
1 parent 16eabfb commit 18b7d4b
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ final class SiteStatsPeriodTableViewController: SiteStatsBaseTableViewController
return ImmuTableDiffableViewHandler(takeOver: self, with: analyticsTracker)
}()

init(selectedDate: Date, selectedPeriod: StatsPeriodUnit) {
datePickerViewModel = StatsTrafficDatePickerViewModel(period: selectedPeriod, date: selectedDate)
init(date: Date, period: StatsPeriodUnit) {
datePickerViewModel = StatsTrafficDatePickerViewModel(period: period, date: date)
datePickerView = StatsTrafficDatePickerView(viewModel: datePickerViewModel)
super.init(nibName: nil, bundle: nil)
tableStyle = .insetGrouped
Expand Down Expand Up @@ -159,7 +159,6 @@ private extension SiteStatsPeriodTableViewController {
tableHandler.diffableDataSource.apply(viewModel.tableViewSnapshot(), animatingDifferences: false)

refreshControl.endRefreshing()
// tableHeaderView?.animateGhostLayers(viewModel.isFetchingChart() == true)

if viewModel.fetchingFailed() {
displayFailureViewIfNecessary()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import UIKit
import SwiftUI

enum StatsPeriodType: Int, FilterTabBarItem, CaseIterable {
case insights = 0
Expand Down Expand Up @@ -80,16 +79,16 @@ class SiteStatsDashboardViewController: UIViewController {
private var insightsTableViewController = SiteStatsInsightsTableViewController.loadFromStoryboard()
private lazy var periodTableViewControllerDeprecated = SiteStatsPeriodTableViewControllerDeprecated.loadFromStoryboard()
private lazy var trafficTableViewController = {
let selectedDate: Date
if let date = getLastSelectedDateFromUserDefaults() {
selectedDate = date
let date: Date
if let selectedDate = getLastSelectedDateFromUserDefaults() {
date = selectedDate
} else {
selectedDate = StatsDataHelper.currentDateForSite()
date = StatsDataHelper.currentDateForSite()
}

let selectedPeriod = StatsPeriodUnit(rawValue: currentSelectedPeriod.rawValue - 1) ?? .day
let currentPeriod = StatsPeriodUnit(rawValue: currentSelectedPeriod.rawValue - 1) ?? .day

return SiteStatsPeriodTableViewController(selectedDate: selectedDate, selectedPeriod: selectedPeriod)
return SiteStatsPeriodTableViewController(date: date, period: currentPeriod)
}()
private var pageViewController: UIPageViewController?
private lazy var displayedPeriods: [StatsPeriodType] = StatsPeriodType.displayedPeriods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ class StatsTrafficDatePickerViewModel: ObservableObject {
}

func goToPreviousPeriod() {
date = Calendar.current.date(byAdding: period.calendarComponent, value: -1, to: date) ?? date
date = StatsDataHelper.calendar.date(byAdding: period.calendarComponent, value: -1, to: date) ?? date
track(isNext: false)
}

func goToNextPeriod() {
date = Calendar.current.date(byAdding: period.calendarComponent, value: 1, to: date) ?? date
date = StatsDataHelper.calendar.date(byAdding: period.calendarComponent, value: 1, to: date) ?? date
track(isNext: true)
}

Expand Down

0 comments on commit 18b7d4b

Please sign in to comment.