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
import ComposableArchitecture
import Foundation
import XCTestDynamicOverlay
import XXClient
public struct UserSearchResultState: Equatable, Identifiable {
public init(
id: Data,
contact: Contact,
username: String? = nil,
email: String? = nil,
phone: String? = nil
) {
self.id = id
self.contact = contact
self.username = username
self.email = email
self.phone = phone
}
public var id: Data
public var contact: XXClient.Contact
public var username: String?
public var email: String?
public var phone: String?
}
public enum UserSearchResultAction: Equatable {
case start
}
public struct UserSearchResultEnvironment {
public init() {}
}
#if DEBUG
extension UserSearchResultEnvironment {
public static let unimplemented = UserSearchResultEnvironment()
}
#endif
public let userSearchResultReducer = Reducer<UserSearchResultState, UserSearchResultAction, UserSearchResultEnvironment>
{ state, action, env in
switch action {
case .start:
let facts = (try? state.contact.getFacts()) ?? []
state.username = facts.first(where: { $0.type == 0 })?.fact
state.email = facts.first(where: { $0.type == 1 })?.fact
state.phone = facts.first(where: { $0.type == 2 })?.fact
return .none
}
}