Skip to content

Commit 29c95b9

Browse files
authored
Merge pull request #7701 from woocommerce/issue/7567-error-view
Widgets: Unable to fetch data View
2 parents 5eed639 + 62809a5 commit 29c95b9

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

WooCommerce/StoreWidgets/StoreInfoProvider.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,14 @@ final class StoreInfoProvider: TimelineProvider {
9898
completion(timeline)
9999

100100
} catch {
101-
// TODO: Dispatch network error entry.
102-
print("Error: \(error)")
103-
}
104101

102+
// WooFoundation does not expose `DDLOG` types. Should we include them?
103+
print("⛔️ Error fetching today's widget stats: \(error)")
104+
105+
let reloadDate = Date(timeIntervalSinceNow: 30 * 60) // Ask for a 30 minutes reload.
106+
let timeline = Timeline<StoreInfoEntry>(entries: [.error], policy: .after(reloadDate))
107+
completion(timeline)
108+
}
105109
}
106110
}
107111
}

WooCommerce/StoreWidgets/StoreInfoWidget.swift

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ struct StoreInfoWidget: Widget {
1616
case .notConnected:
1717
NotLoggedInView()
1818
case .error:
19-
EmptyView() // TODO:
19+
UnableToFetchView()
2020
case .data(let data):
2121
StoreInfoView(entry: data)
2222
}
@@ -126,6 +126,29 @@ private struct NotLoggedInView: View {
126126
}
127127
}
128128

129+
private struct UnableToFetchView: View {
130+
var body: some View {
131+
ZStack {
132+
// Background
133+
Color(.brand)
134+
135+
VStack {
136+
Image(uiImage: .wooLogoWhite)
137+
.resizable()
138+
.frame(width: Layout.logoSize.width, height: Layout.logoSize.height)
139+
140+
Spacer()
141+
142+
Text(Localization.unableToFetch)
143+
.statTextStyle()
144+
145+
Spacer()
146+
}
147+
.padding(.vertical, Layout.cardVerticalPadding)
148+
}
149+
}
150+
}
151+
129152
// MARK: Constants
130153

131154
/// Constants definition
@@ -160,6 +183,20 @@ private extension NotLoggedInView {
160183
}
161184
}
162185

186+
/// Constants definition
187+
///
188+
private extension UnableToFetchView {
189+
enum Localization {
190+
static let unableToFetch = NSLocalizedString("Unable to fetch today's stats",
191+
comment: "Title label when the widget can't fetch data.")
192+
}
193+
194+
enum Layout {
195+
static let cardVerticalPadding = 22.0
196+
static let logoSize = CGSize(width: 24, height: 16)
197+
}
198+
}
199+
163200
// MARK: Previews
164201

165202
struct StoreWidgets_Previews: PreviewProvider {
@@ -176,5 +213,8 @@ struct StoreWidgets_Previews: PreviewProvider {
176213

177214
NotLoggedInView()
178215
.previewContext(WidgetPreviewContext(family: .systemMedium))
216+
217+
UnableToFetchView()
218+
.previewContext(WidgetPreviewContext(family: .systemMedium))
179219
}
180220
}

0 commit comments

Comments
 (0)