Skip to content
Merged
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Foundation
import Yosemite

/// Main View Model for the Analytics Hub.
///
Expand Down Expand Up @@ -27,4 +28,56 @@ final class AnalyticsHubViewModel: ObservableObject {
trailingValue: "$57,99",
trailingDelta: "-16%",
trailingDeltaColor: .withColorStudio(.red, shade: .shade40))

// MARK: Private data

/// Order stats for the current selected time period
///
@Published private var currentOrderStats: OrderStatsV4 = {
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the reason for these to be published properties? 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought if we make them published properties, we can listen for changes to the data (i.e. when a different time period is selected and new data is synced) to update what is displayed on the cards. WDYT?

fakeOrderStats(with: fakeCurrentOrderTotals())
}()

/// Order stats for the previous time period (for comparison)
///
@Published private var previousOrderStats: OrderStatsV4 = {
fakeOrderStats(with: fakePreviousOrderTotals())
}()
}

// MARK: - Fake data

/// Extension with fake data. This can be removed once we fetch real data from the API.
///
private extension AnalyticsHubViewModel {
static func fakeCurrentOrderTotals() -> OrderStatsV4Totals {
OrderStatsV4Totals(totalOrders: 3,
totalItemsSold: 5,
grossRevenue: 800,
couponDiscount: 0,
totalCoupons: 0,
refunds: 0,
taxes: 0,
shipping: 0,
netRevenue: 800,
totalProducts: 2,
averageOrderValue: 266)
}

static func fakePreviousOrderTotals() -> OrderStatsV4Totals {
OrderStatsV4Totals(totalOrders: 2,
totalItemsSold: 8,
grossRevenue: 1000,
couponDiscount: 0,
totalCoupons: 0,
refunds: 0,
taxes: 0,
shipping: 0,
netRevenue: 900,
totalProducts: 2,
averageOrderValue: 500)
}

static func fakeOrderStats(with totals: OrderStatsV4Totals) -> OrderStatsV4 {
OrderStatsV4(siteID: 12345, granularity: .daily, totals: totals, intervals: [])
}
}