Newer
Older
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import AppCore
import ComposableArchitecture
import SwiftUI
public struct ContactLookupView: View {
public init(store: Store<ContactLookupState, ContactLookupAction>) {
self.store = store
}
let store: Store<ContactLookupState, ContactLookupAction>
struct ViewState: Equatable {
init(state: ContactLookupState) {
id = state.id
isLookingUp = state.isLookingUp
}
var id: Data
var isLookingUp: Bool
}
public var body: some View {
WithViewStore(store, observe: ViewState.init) { viewStore in
Form {
Section {
Label(viewStore.id.hexString, systemImage: "number")
.font(.footnote.monospaced())
Button {
viewStore.send(.lookupTapped)
} label: {
HStack {
Text("Lookup")
Spacer()
if viewStore.isLookingUp {
ProgressView()
} else {
Image(systemName: "magnifyingglass")
}
}
}
.disabled(viewStore.isLookingUp)
} header: {
Text("Contact ID")
}
}
.navigationTitle("Lookup")
.task {
await viewStore.send(.task).finish()
}
}
}
}
#if DEBUG
public struct ContactLookupView_Previews: PreviewProvider {
public static var previews: some View {
NavigationView {
ContactLookupView(store: Store(
initialState: ContactLookupState(
id: "1234".data(using: .utf8)!
),
reducer: .empty,
environment: ()
))
}
}
}
#endif