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 { ...@@ -18,12 +18,14 @@ public struct MyContactState: Equatable {
focusedField: Field? = nil, focusedField: Field? = nil,
email: String = "", email: String = "",
phone: String = "", phone: String = "",
isLoadingFacts: Bool = false,
alert: AlertState<MyContactAction>? = nil alert: AlertState<MyContactAction>? = nil
) { ) {
self.contact = contact self.contact = contact
self.focusedField = focusedField self.focusedField = focusedField
self.email = email self.email = email
self.phone = phone self.phone = phone
self.isLoadingFacts = isLoadingFacts
self.alert = alert self.alert = alert
} }
...@@ -31,6 +33,7 @@ public struct MyContactState: Equatable { ...@@ -31,6 +33,7 @@ public struct MyContactState: Equatable {
@BindableState public var focusedField: Field? @BindableState public var focusedField: Field?
@BindableState public var email: String @BindableState public var email: String
@BindableState public var phone: String @BindableState public var phone: String
@BindableState public var isLoadingFacts: Bool
public var alert: AlertState<MyContactAction>? public var alert: AlertState<MyContactAction>?
} }
...@@ -112,6 +115,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact ...@@ -112,6 +115,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact
return .none return .none
case .loadFactsTapped: case .loadFactsTapped:
state.isLoadingFacts = true
return Effect.run { subscriber in return Effect.run { subscriber in
do { do {
let contactId = try env.messenger.e2e.tryGet().getContact().getId() let contactId = try env.messenger.e2e.tryGet().getContact().getId()
...@@ -124,6 +128,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact ...@@ -124,6 +128,7 @@ public let myContactReducer = Reducer<MyContactState, MyContactAction, MyContact
} catch { } catch {
subscriber.send(.didFail(error.localizedDescription)) subscriber.send(.didFail(error.localizedDescription))
} }
subscriber.send(.set(\.$isLoadingFacts, false))
subscriber.send(completion: .finished) subscriber.send(completion: .finished)
return AnyCancellable {} return AnyCancellable {}
} }
......
...@@ -16,12 +16,14 @@ public struct MyContactView: View { ...@@ -16,12 +16,14 @@ public struct MyContactView: View {
focusedField = state.focusedField focusedField = state.focusedField
email = state.email email = state.email
phone = state.phone phone = state.phone
isLoadingFacts = state.isLoadingFacts
} }
var contact: XXModels.Contact? var contact: XXModels.Contact?
var focusedField: MyContactState.Field? var focusedField: MyContactState.Field?
var email: String var email: String
var phone: String var phone: String
var isLoadingFacts: Bool
} }
public var body: some View { public var body: some View {
...@@ -105,8 +107,15 @@ public struct MyContactView: View { ...@@ -105,8 +107,15 @@ public struct MyContactView: View {
Button { Button {
viewStore.send(.loadFactsTapped) viewStore.send(.loadFactsTapped)
} label: { } label: {
Text("Load facts from client") HStack {
Text("Reload facts")
Spacer()
if viewStore.isLoadingFacts {
ProgressView()
}
}
} }
.disabled(viewStore.isLoadingFacts)
} header: { } header: {
Text("Actions") Text("Actions")
} }
......
...@@ -159,13 +159,19 @@ final class MyContactFeatureTests: XCTestCase { ...@@ -159,13 +159,19 @@ final class MyContactFeatureTests: XCTestCase {
return db return db
} }
store.send(.loadFactsTapped) store.send(.loadFactsTapped) {
$0.isLoadingFacts = true
}
XCTAssertNoDifference(didFetchContacts, [.init(id: [contactId])]) XCTAssertNoDifference(didFetchContacts, [.init(id: [contactId])])
var expectedSavedContact = dbContact var expectedSavedContact = dbContact
expectedSavedContact.email = email expectedSavedContact.email = email
expectedSavedContact.phone = phone expectedSavedContact.phone = phone
XCTAssertNoDifference(didSaveContact, [expectedSavedContact]) XCTAssertNoDifference(didSaveContact, [expectedSavedContact])
store.receive(.set(\.$isLoadingFacts, false)) {
$0.isLoadingFacts = false
}
} }
func testErrorAlert() { 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