Skip to content

Commit

Permalink
Merge pull request #7701 from woocommerce/issue/7567-error-view
Browse files Browse the repository at this point in the history
Widgets: Unable to fetch data View
  • Loading branch information
Ecarrion authored Sep 12, 2022
2 parents 5eed639 + 62809a5 commit 29c95b9
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
10 changes: 7 additions & 3 deletions WooCommerce/StoreWidgets/StoreInfoProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,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 30 minutes reload.
let timeline = Timeline<StoreInfoEntry>(entries: [.error], policy: .after(reloadDate))
completion(timeline)
}
}
}
}
Expand Down
42 changes: 41 additions & 1 deletion WooCommerce/StoreWidgets/StoreInfoWidget.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ struct StoreInfoWidget: Widget {
case .notConnected:
NotLoggedInView()
case .error:
EmptyView() // TODO:
UnableToFetchView()
case .data(let data):
StoreInfoView(entry: data)
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand All @@ -176,5 +213,8 @@ struct StoreWidgets_Previews: PreviewProvider {

NotLoggedInView()
.previewContext(WidgetPreviewContext(family: .systemMedium))

UnableToFetchView()
.previewContext(WidgetPreviewContext(family: .systemMedium))
}
}

0 comments on commit 29c95b9

Please sign in to comment.