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
import ComposableArchitecture
import SwiftUI
public struct UserSearchResultView: View {
public init(store: Store<UserSearchResultState, UserSearchResultAction>) {
self.store = store
}
let store: Store<UserSearchResultState, UserSearchResultAction>
struct ViewState: Equatable {
var username: String?
var email: String?
var phone: String?
init(state: UserSearchResultState) {
username = state.username
email = state.email
phone = state.phone
}
var isEmpty: Bool {
username == nil && email == nil && phone == nil
}
}
public var body: some View {
WithViewStore(store.scope(state: ViewState.init)) { viewStore in
Section {
if viewStore.isEmpty {
Image(systemName: "questionmark")
.frame(maxWidth: .infinity)
} else {
if let username = viewStore.username {
Text(username)
}
if let email = viewStore.email {
Text(email)
}
if let phone = viewStore.phone {
Text(phone)
}
}
}
.task { viewStore.send(.start) }
}
}
}
#if DEBUG
public struct UserSearchResultView_Previews: PreviewProvider {
public static var previews: some View {
UserSearchResultView(store: Store(
initialState: UserSearchResultState(
id: "contact-id".data(using: .utf8)!,
),
reducer: .empty,
environment: ()
))
}
}
#endif