Skip to content

Commit eee1d55

Browse files
authored
Merge pull request #7715 from woocommerce/issue/7709-reload-stats
Widget: Reload widget when App stats are reloaded.
2 parents 701ba00 + 317276e commit eee1d55

File tree

3 files changed

+24
-2
lines changed

3 files changed

+24
-2
lines changed

WooCommerce/Classes/System/WooConstants.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ enum WooConstants {
4949
/// before an app review prompt appears
5050
///
5151
static let systemEventCount = 10
52+
53+
/// Store Info Widget Identifier.
54+
///
55+
static let storeInfoWidgetKind = "StoreInfoWidget"
5256
}
5357

5458
// MARK: URLs

WooCommerce/Classes/ViewRelated/Dashboard/Stats v4/StoreStatsAndTopPerformersViewController.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import Combine
22
import UIKit
33
import XLPagerTabStrip
44
import Yosemite
5+
import class WidgetKit.WidgetCenter
56

67
/// Top-level stats container view controller that consists of a button bar with 4 time ranges.
78
/// Each time range tab is managed by a `StoreStatsAndTopPerformersPeriodViewController`.
@@ -298,6 +299,11 @@ private extension StoreStatsAndTopPerformersViewController {
298299
// Update last successful data sync timestamp
299300
if periodSyncError == nil {
300301
vc.lastFullSyncTimestamp = Date()
302+
303+
// Reload the Store Info Widget after syncing the today's stats.
304+
if vc.timeRange == .today {
305+
WidgetCenter.shared.reloadTimelines(ofKind: WooConstants.storeInfoWidgetKind)
306+
}
301307
} else {
302308
syncError = periodSyncError
303309
}

WooCommerce/StoreWidgets/StoreInfoWidget.swift

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ struct StoreInfoWidget: Widget {
1010
let enableWidgets = DefaultFeatureFlagService().isFeatureFlagEnabled(.storeWidgets)
1111

1212
var body: some WidgetConfiguration {
13-
StaticConfiguration(kind: "StoreInfoWidget", provider: StoreInfoProvider()) { entry in
13+
StaticConfiguration(kind: WooConstants.storeInfoWidgetKind, provider: StoreInfoProvider()) { entry in
1414
Group {
1515
switch entry {
1616
case .notConnected:
@@ -22,7 +22,7 @@ struct StoreInfoWidget: Widget {
2222
}
2323
}
2424
}
25-
.configurationDisplayName("Store Info")
25+
.configurationDisplayName(Localization.storeInfo)
2626
.supportedFamilies(enableWidgets ? [.systemMedium] : [])
2727
}
2828
}
@@ -151,6 +151,18 @@ private struct UnableToFetchView: View {
151151

152152
// MARK: Constants
153153

154+
/// Constants definition
155+
///
156+
private extension StoreInfoWidget {
157+
enum Localization {
158+
static let storeInfo = AppLocalizedString(
159+
"storeWidgets.displayName",
160+
value: "Store Info",
161+
comment: "Widget title, displayed when selecting which widget to add"
162+
)
163+
}
164+
}
165+
154166
/// Constants definition
155167
///
156168
private extension StoreInfoView {

0 commit comments

Comments
 (0)