forked from schmidyy/SwiftUI-ListFetching
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathProductListView.swift
44 lines (40 loc) · 1.14 KB
/
ProductListView.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//
// ProductListView.swift
// Products
//
// Created by Mat Schmid on 2019-06-10.
// Copyright © 2019 Shopify. All rights reserved.
//
import SwiftUI
struct ProductListView : View {
@ObservedObject var productFetcher = ProductFetcher()
private var stateContent: AnyView {
switch productFetcher.state {
case .loading:
return AnyView(
ActivityIndicator(style: .medium)
)
case .fetched(let result):
switch result {
case .failure(let error):
return AnyView(
Text(error.localizedDescription)
)
case .success(let root):
return AnyView(
List(root.products) { product in
NavigationLink(destination: ProductDetailsView(product: product)) {
ProductRow(product: product)
}
}
)
}
}
}
var body: some View {
NavigationView {
stateContent
.navigationBarTitle(Text("Products"))
}
}
}