Newer
Older
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?
var dbContactAuth: XXModels.Contact.AuthStatus?
init(state: UserSearchResultState) {
username = state.username
email = state.email
phone = state.phone
dbContactAuth = state.dbContact?.authStatus
}
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)
}
}
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
switch viewStore.dbContactAuth {
case .none, .stranger:
Button {
viewStore.send(.sendRequestButtonTapped)
} label: {
HStack {
Text("Send request")
Spacer()
Image(systemName: "person.badge.plus")
}
}
case .requesting:
HStack {
Text("Sending auth request")
Spacer()
ProgressView()
}
case .requested:
HStack {
Text("Request sent")
Spacer()
Image(systemName: "paperplane")
}
case .requestFailed:
HStack {
Text("Sending request failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .verificationInProgress:
HStack {
Text("Verification is progress")
Spacer()
ProgressView()
}
case .verified:
HStack {
Text("Verified")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .verificationFailed:
HStack {
Text("Verification failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .confirming:
HStack {
Text("Confirming auth request")
Spacer()
ProgressView()
}
case .confirmationFailed:
HStack {
Text("Confirmation failed")
Spacer()
Image(systemName: "xmark.diamond.fill")
.foregroundColor(.red)
}
case .friend:
HStack {
Text("Friend")
Spacer()
Image(systemName: "person.fill.checkmark")
}
case .hidden:
HStack {
Text("Hidden")
Spacer()
Image(systemName: "eye.slash")
}
}
}
.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)!,
xxContact: .unimplemented("contact-data".data(using: .utf8)!)
),
reducer: .empty,
environment: ()
))
}
}
#endif