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

Add facts loading indicator

parent 1f6e477c
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!98Messenger example - register, confirm, and unregister user facts
......@@ -18,12 +18,14 @@ public struct MyContactState: Equatable {
focusedField: Field? = nil,
email: String = "",
phone: String = "",
isLoadingFacts: Bool = false,
alert: AlertState<MyContactAction>? = nil
) {
self.contact = contact
self.focusedField = focusedField
self.email = email
self.phone = phone
self.isLoadingFacts = isLoadingFacts
self.alert = alert
}
......@@ -31,6 +33,7 @@ public struct MyContactState: Equatable {
@BindableState public var focusedField: Field?
@BindableState public var email: String
@BindableState public var phone: String
@BindableState public var isLoadingFacts: Bool
public var alert: AlertState<MyContactAction>?
}
......@@ -112,6 +115,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact
return .none
case .loadFactsTapped:
state.isLoadingFacts = true
return Effect.run { subscriber in
do {
let contactId = try env.messenger.e2e.tryGet().getContact().getId()
......@@ -124,6 +128,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact
} catch {
subscriber.send(.didFail(error.localizedDescription))
}
subscriber.send(.set(\.$isLoadingFacts, false))
subscriber.send(completion: .finished)
return AnyCancellable {}
}
......
......@@ -16,12 +16,14 @@ public struct MyContactView: View {
focusedField = state.focusedField
email = state.email
phone = state.phone
isLoadingFacts = state.isLoadingFacts
}
var contact: XXModels.Contact?
var focusedField: MyContactState.Field?
var email: String
var phone: String
var isLoadingFacts: Bool
}
public var body: some View {
......@@ -105,8 +107,15 @@ public struct MyContactView: View {
Button {
viewStore.send(.loadFactsTapped)
} label: {
Text("Load facts from client")
HStack {
Text("Reload facts")
Spacer()
if viewStore.isLoadingFacts {
ProgressView()
}
}
}
.disabled(viewStore.isLoadingFacts)
} header: {
Text("Actions")
}
......
......@@ -159,13 +159,19 @@ final class MyContactFeatureTests: XCTestCase {
return db
}
store.send(.loadFactsTapped)
store.send(.loadFactsTapped) {
$0.isLoadingFacts = true
}
XCTAssertNoDifference(didFetchContacts, [.init(id: [contactId])])
var expectedSavedContact = dbContact
expectedSavedContact.email = email
expectedSavedContact.phone = phone
XCTAssertNoDifference(didSaveContact, [expectedSavedContact])
store.receive(.set(\.$isLoadingFacts, false)) {
$0.isLoadingFacts = false
}
}
func testErrorAlert() {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment