Skip to content
Snippets Groups Projects
Commit b5bbc0ca authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Update UserSearchResultFeature

parent 20f14b6a
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!68Messenger example - send auth request
......@@ -158,7 +158,6 @@ let package = Package(
.target(
name: "UserSearchFeature",
dependencies: [
.target(name: "AppCore"),
.product(name: "ComposableArchitecture", package: "swift-composable-architecture"),
.product(name: "ComposablePresentation", package: "swift-composable-presentation"),
.product(name: "XXClient", package: "elixxir-dapps-sdk-swift"),
......
import AppCore
import ComposableArchitecture
import Foundation
import XCTestDynamicOverlay
import XXClient
import XXModels
public struct UserSearchResultState: Equatable, Identifiable {
public init(
id: Data,
xxContact: XXClient.Contact,
dbContact: XXModels.Contact? = nil,
username: String? = nil,
email: String? = nil,
phone: String? = nil
) {
self.id = id
self.xxContact = xxContact
self.dbContact = dbContact
self.username = username
self.email = email
self.phone = phone
......@@ -24,7 +20,6 @@ public struct UserSearchResultState: Equatable, Identifiable {
public var id: Data
public var xxContact: XXClient.Contact
public var dbContact: XXModels.Contact?
public var username: String?
public var email: String?
public var phone: String?
......@@ -32,60 +27,30 @@ public struct UserSearchResultState: Equatable, Identifiable {
public enum UserSearchResultAction: Equatable {
case start
case didUpdateContact(XXModels.Contact?)
case sendRequestButtonTapped
case tapped
}
public struct UserSearchResultEnvironment {
public init(
db: DBManagerGetDB,
mainQueue: AnySchedulerOf<DispatchQueue>,
bgQueue: AnySchedulerOf<DispatchQueue>
) {
self.db = db
self.mainQueue = mainQueue
self.bgQueue = bgQueue
}
public var db: DBManagerGetDB
public var mainQueue: AnySchedulerOf<DispatchQueue>
public var bgQueue: AnySchedulerOf<DispatchQueue>
public init() {}
}
#if DEBUG
extension UserSearchResultEnvironment {
public static let unimplemented = UserSearchResultEnvironment(
db: .unimplemented,
mainQueue: .unimplemented,
bgQueue: .unimplemented
)
public static let unimplemented = UserSearchResultEnvironment()
}
#endif
public let userSearchResultReducer = Reducer<UserSearchResultState, UserSearchResultAction, UserSearchResultEnvironment>
{ state, action, env in
enum DBFetchEffectID {}
switch action {
case .start:
let facts = (try? state.xxContact.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 try! env.db().fetchContactsPublisher(.init(id: [state.id]))
.assertNoFailure()
.map(\.first)
.map(UserSearchResultAction.didUpdateContact)
.subscribe(on: env.bgQueue)
.receive(on: env.mainQueue)
.eraseToEffect()
.cancellable(id: DBFetchEffectID.self, cancelInFlight: true)
case .didUpdateContact(let contact):
state.dbContact = contact
return .none
case .sendRequestButtonTapped:
case .tapped:
return .none
}
}
......@@ -13,13 +13,11 @@ public struct UserSearchResultView: View {
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 {
......@@ -30,6 +28,11 @@ public struct UserSearchResultView: View {
public var body: some View {
WithViewStore(store.scope(state: ViewState.init)) { viewStore in
Section {
Button {
viewStore.send(.tapped)
} label: {
HStack {
VStack {
if viewStore.isEmpty {
Image(systemName: "questionmark")
.frame(maxWidth: .infinity)
......@@ -44,89 +47,9 @@ public struct UserSearchResultView: View {
Text(phone)
}
}
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")
Image(systemName: "chevron.forward")
}
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment