From 2cbacbb37ddc55eaeed6c3fcaebf53474b43a66c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Fri, 9 Sep 2022 11:23:48 -0500 Subject: [PATCH 1/4] Adds unable to ftch view --- .../StoreWidgets/StoreInfoWidget.swift | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/WooCommerce/StoreWidgets/StoreInfoWidget.swift b/WooCommerce/StoreWidgets/StoreInfoWidget.swift index 539a6d894af..2ac14eac144 100644 --- a/WooCommerce/StoreWidgets/StoreInfoWidget.swift +++ b/WooCommerce/StoreWidgets/StoreInfoWidget.swift @@ -126,6 +126,29 @@ private struct NotLoggedInView: View { } } +private struct UnableToFetchView: View { + var body: some View { + ZStack { + // Background + Color(.brand) + + VStack { + Image(uiImage: .wooLogoWhite) + .resizable() + .frame(width: Layout.logoSize.width, height: Layout.logoSize.height) + + Spacer() + + Text(Localization.unableToFetch) + .statTextStyle() + + Spacer() + } + .padding(.vertical, Layout.cardVerticalPadding) + } + } +} + // MARK: Constants /// Constants definition @@ -160,6 +183,20 @@ private extension NotLoggedInView { } } +/// Constants definition +/// +private extension UnableToFetchView { + enum Localization { + static let unableToFetch = NSLocalizedString("Unable to fetch today's stats", + comment: "Title label when the widget can't fetch data.") + } + + enum Layout { + static let cardVerticalPadding = 22.0 + static let logoSize = CGSize(width: 24, height: 16) + } +} + // MARK: Previews struct StoreWidgets_Previews: PreviewProvider { @@ -176,5 +213,8 @@ struct StoreWidgets_Previews: PreviewProvider { NotLoggedInView() .previewContext(WidgetPreviewContext(family: .systemMedium)) + + UnableToFetchView() + .previewContext(WidgetPreviewContext(family: .systemMedium)) } } From 7d60489f5372fdfb05ed18fa9700c963f6ec6a02 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Fri, 9 Sep 2022 11:35:02 -0500 Subject: [PATCH 2/4] Render unable to fetch view when there is an error fetching stats --- WooCommerce/StoreWidgets/StoreInfoProvider.swift | 11 ++++++++--- WooCommerce/StoreWidgets/StoreInfoWidget.swift | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index 7734c50385f..ba574c9158d 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -1,5 +1,6 @@ import WidgetKit import KeychainAccess +import WooFoundation /// Type that represents the all the possible Widget states. /// @@ -98,10 +99,14 @@ final class StoreInfoProvider: TimelineProvider { completion(timeline) } catch { - // TODO: Dispatch network error entry. - print("Error: \(error)") - } + // WooFoundation does not expose `DDLOG` types. Should we include them? + print("⛔️ Error fetching today's widget stats: \(error)") + + let reloadDate = Date(timeIntervalSinceNow: 30 * 60) // Ask for a 15 minutes reload. + let timeline = Timeline(entries: [.error], policy: .after(reloadDate)) + completion(timeline) + } } } } diff --git a/WooCommerce/StoreWidgets/StoreInfoWidget.swift b/WooCommerce/StoreWidgets/StoreInfoWidget.swift index 2ac14eac144..0f4eea3dbda 100644 --- a/WooCommerce/StoreWidgets/StoreInfoWidget.swift +++ b/WooCommerce/StoreWidgets/StoreInfoWidget.swift @@ -16,7 +16,7 @@ struct StoreInfoWidget: Widget { case .notConnected: NotLoggedInView() case .error: - EmptyView() // TODO: + UnableToFetchView() case .data(let data): StoreInfoView(entry: data) } From f3b818dd9c87b1701a356d641653321873882cb6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Fri, 9 Sep 2022 13:55:31 -0500 Subject: [PATCH 3/4] Removes unnecesary import --- WooCommerce/StoreWidgets/StoreInfoProvider.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index ba574c9158d..4f0723fc339 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -1,6 +1,5 @@ import WidgetKit import KeychainAccess -import WooFoundation /// Type that represents the all the possible Widget states. /// From 62809a52afd5278178f74b8ed60b69abd99cc4bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ernesto=20Carri=C3=B3n?= Date: Mon, 12 Sep 2022 07:45:43 -0500 Subject: [PATCH 4/4] Update WooCommerce/StoreWidgets/StoreInfoProvider.swift Co-authored-by: Evgeny Aleksandrov --- WooCommerce/StoreWidgets/StoreInfoProvider.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/WooCommerce/StoreWidgets/StoreInfoProvider.swift b/WooCommerce/StoreWidgets/StoreInfoProvider.swift index 4f0723fc339..81671065820 100644 --- a/WooCommerce/StoreWidgets/StoreInfoProvider.swift +++ b/WooCommerce/StoreWidgets/StoreInfoProvider.swift @@ -102,7 +102,7 @@ final class StoreInfoProvider: TimelineProvider { // WooFoundation does not expose `DDLOG` types. Should we include them? print("⛔️ Error fetching today's widget stats: \(error)") - let reloadDate = Date(timeIntervalSinceNow: 30 * 60) // Ask for a 15 minutes reload. + let reloadDate = Date(timeIntervalSinceNow: 30 * 60) // Ask for a 30 minutes reload. let timeline = Timeline(entries: [.error], policy: .after(reloadDate)) completion(timeline) }