diff --git a/Examples/xx-messenger/Sources/ContactFeature/ContactFeature.swift b/Examples/xx-messenger/Sources/ContactFeature/ContactFeature.swift index 6624bb2c6ef01482052069fdfa647d3269f302a8..37388359cf5266757bd2e0585773df078556cd2d 100644 --- a/Examples/xx-messenger/Sources/ContactFeature/ContactFeature.swift +++ b/Examples/xx-messenger/Sources/ContactFeature/ContactFeature.swift @@ -25,6 +25,8 @@ public struct ContactState: Equatable { public enum ContactAction: Equatable { case start case dbContactFetched(XXModels.Contact?) + case saveFactsTapped + case sendRequestTapped } public struct ContactEnvironment { @@ -75,5 +77,11 @@ public let contactReducer = Reducer<ContactState, ContactAction, ContactEnvironm case .dbContactFetched(let contact): state.dbContact = contact return .none + + case .saveFactsTapped: + return .none + + case .sendRequestTapped: + return .none } } diff --git a/Examples/xx-messenger/Sources/ContactFeature/ContactView.swift b/Examples/xx-messenger/Sources/ContactFeature/ContactView.swift index 0d985c62e9c1de709f7b14992446c7e271ecd137..ca5eb328b000e13c65cccb29a971875d7b561552 100644 --- a/Examples/xx-messenger/Sources/ContactFeature/ContactView.swift +++ b/Examples/xx-messenger/Sources/ContactFeature/ContactView.swift @@ -24,110 +24,138 @@ public struct ContactView: View { public var body: some View { WithViewStore(store.scope(state: ViewState.init)) { viewStore in Form { - Section { - if let dbContact = viewStore.dbContact { + if let xxContact = viewStore.xxContact { + Section { + Label(xxContact.username ?? "", systemImage: "person") + Label(xxContact.email ?? "", systemImage: "envelope") + Label(xxContact.phone ?? "", systemImage: "phone") + Button { + viewStore.send(.saveFactsTapped) + } label: { + if viewStore.dbContact == nil { + Text("Save contact") + } else { + Text("Update contact") + } + } + } header: { + Text("Facts") + } + } + + if let dbContact = viewStore.dbContact { + Section { Label(dbContact.username ?? "", systemImage: "person") Label(dbContact.email ?? "", systemImage: "envelope") Label(dbContact.phone ?? "", systemImage: "phone") - } else { - Text("Contact not saved locally") + } header: { + Text("Contact") } - } header: { - Text("Local data") - } - - Section { - Label(viewStore.xxContact?.username ?? "", systemImage: "person") - Label(viewStore.xxContact?.email ?? "", systemImage: "envelope") - Label(viewStore.xxContact?.phone ?? "", systemImage: "phone") - } header: { - Text("Facts") - } - - Section { - switch viewStore.dbContact?.authStatus { - case .none, .stranger: - HStack { - Text("Stranger") - Spacer() - Image(systemName: "person.fill.questionmark") - } - - 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") + Section { + switch dbContact.authStatus { + case .stranger: + HStack { + Text("Stranger") + Spacer() + Image(systemName: "person.fill.questionmark") + } + Button { + viewStore.send(.sendRequestTapped) + } label: { + HStack { + Text("Send request") + Spacer() + Image(systemName: "chevron.forward") + } + } + + case .requesting: + HStack { + Text("Sending auth request") + Spacer() + ProgressView() + } + + case .requested: + HStack { + Text("Request sent") + Spacer() + Image(systemName: "chevron.forward") + } + + case .requestFailed: + HStack { + Text("Sending request failed") + Spacer() + Image(systemName: "xmark.diamond.fill") + .foregroundColor(.red) + } + Button { + viewStore.send(.sendRequestTapped) + } label: { + HStack { + Text("Resend request") + Spacer() + Image(systemName: "paperplane") + } + } + + 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") + } } + } header: { + Text("Auth status") } - } header: { - Text("Auth status") + .animation(.default, value: viewStore.dbContact?.authStatus) } } .navigationTitle("Contact") diff --git a/Examples/xx-messenger/Tests/ContactFeatureTests/ContactFeatureTests.swift b/Examples/xx-messenger/Tests/ContactFeatureTests/ContactFeatureTests.swift index 5145acce1eb9409a13968db64778746cbf6a3e53..b0d3e8b68dbfd6313acbf026cc53e0f5fe738584 100644 --- a/Examples/xx-messenger/Tests/ContactFeatureTests/ContactFeatureTests.swift +++ b/Examples/xx-messenger/Tests/ContactFeatureTests/ContactFeatureTests.swift @@ -44,4 +44,28 @@ final class ContactFeatureTests: XCTestCase { dbContactsPublisher.send(completion: .finished) } + + func testSaveFacts() { + let store = TestStore( + initialState: ContactState( + id: "contact-id".data(using: .utf8)! + ), + reducer: contactReducer, + environment: .unimplemented + ) + + store.send(.saveFactsTapped) + } + + func testSendRequest() { + let store = TestStore( + initialState: ContactState( + id: "contact-id".data(using: .utf8)! + ), + reducer: contactReducer, + environment: .unimplemented + ) + + store.send(.sendRequestTapped) + } }