diff --git a/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme b/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme new file mode 100644 index 0000000000000000000000000000000000000000..e0070c64629dce6e785c4bb8590d0b330d522f5b --- /dev/null +++ b/Examples/xx-messenger/.swiftpm/xcode/xcshareddata/xcschemes/ContactLookupFeature.xcscheme @@ -0,0 +1,78 @@ +<?xml version="1.0" encoding="UTF-8"?> +<Scheme + LastUpgradeVersion = "1400" + version = "1.3"> + <BuildAction + parallelizeBuildables = "YES" + buildImplicitDependencies = "YES"> + <BuildActionEntries> + <BuildActionEntry + buildForTesting = "YES" + buildForRunning = "YES" + buildForProfiling = "YES" + buildForArchiving = "YES" + buildForAnalyzing = "YES"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeature" + BuildableName = "ContactLookupFeature" + BlueprintName = "ContactLookupFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </BuildActionEntry> + </BuildActionEntries> + </BuildAction> + <TestAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + shouldUseLaunchSchemeArgsEnv = "YES" + codeCoverageEnabled = "YES"> + <Testables> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeatureTests" + BuildableName = "ContactLookupFeatureTests" + BlueprintName = "ContactLookupFeatureTests" + ReferencedContainer = "container:"> + </BuildableReference> + </TestableReference> + </Testables> + </TestAction> + <LaunchAction + buildConfiguration = "Debug" + selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB" + selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB" + launchStyle = "0" + useCustomWorkingDirectory = "NO" + ignoresPersistentStateOnLaunch = "NO" + debugDocumentVersioning = "YES" + debugServiceExtension = "internal" + allowLocationSimulation = "YES"> + </LaunchAction> + <ProfileAction + buildConfiguration = "Release" + shouldUseLaunchSchemeArgsEnv = "YES" + savedToolIdentifier = "" + useCustomWorkingDirectory = "NO" + debugDocumentVersioning = "YES"> + <MacroExpansion> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeature" + BuildableName = "ContactLookupFeature" + BlueprintName = "ContactLookupFeature" + ReferencedContainer = "container:"> + </BuildableReference> + </MacroExpansion> + </ProfileAction> + <AnalyzeAction + buildConfiguration = "Debug"> + </AnalyzeAction> + <ArchiveAction + buildConfiguration = "Release" + revealArchiveInOrganizer = "YES"> + </ArchiveAction> +</Scheme> diff --git a/Examples/xx-messenger/Package.swift b/Examples/xx-messenger/Package.swift index 4668d629ddf3b295ce57fe54329d28101e94c7ff..1cab487ef6b858745e56cce7eda49a3e6c9d4a89 100644 --- a/Examples/xx-messenger/Package.swift +++ b/Examples/xx-messenger/Package.swift @@ -20,6 +20,7 @@ let package = Package( .library(name: "CheckContactAuthFeature", targets: ["CheckContactAuthFeature"]), .library(name: "ConfirmRequestFeature", targets: ["ConfirmRequestFeature"]), .library(name: "ContactFeature", targets: ["ContactFeature"]), + .library(name: "ContactLookupFeature", targets: ["ContactLookupFeature"]), .library(name: "ContactsFeature", targets: ["ContactsFeature"]), .library(name: "HomeFeature", targets: ["HomeFeature"]), .library(name: "MyContactFeature", targets: ["MyContactFeature"]), @@ -208,6 +209,24 @@ let package = Package( ], swiftSettings: swiftSettings ), + .target( + name: "ContactLookupFeature", + dependencies: [ + .target(name: "AppCore"), + .product(name: "ComposableArchitecture", package: "swift-composable-architecture"), + .product(name: "XXMessengerClient", package: "elixxir-dapps-sdk-swift"), + .product(name: "XXModels", package: "client-ios-db"), + ], + swiftSettings: swiftSettings + ), + .testTarget( + name: "ContactLookupFeatureTests", + dependencies: [ + .target(name: "ContactLookupFeature"), + .product(name: "CustomDump", package: "swift-custom-dump"), + ], + swiftSettings: swiftSettings + ), .target( name: "ContactsFeature", dependencies: [ diff --git a/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme b/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme index b50f1c107c6e3f6e79c5c4c22e64b4368732de84..42a3cede69290ef2541f14fb20a7c54ad71831b5 100644 --- a/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme +++ b/Examples/xx-messenger/Project/XXMessenger.xcodeproj/xcshareddata/xcschemes/XXMessenger.xcscheme @@ -99,6 +99,16 @@ ReferencedContainer = "container:.."> </BuildableReference> </TestableReference> + <TestableReference + skipped = "NO"> + <BuildableReference + BuildableIdentifier = "primary" + BlueprintIdentifier = "ContactLookupFeatureTests" + BuildableName = "ContactLookupFeatureTests" + BlueprintName = "ContactLookupFeatureTests" + ReferencedContainer = "container:.."> + </BuildableReference> + </TestableReference> <TestableReference skipped = "NO"> <BuildableReference diff --git a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift new file mode 100644 index 0000000000000000000000000000000000000000..7fd2fc8e893fa9dd62b0934b2030ada99c2ed94d --- /dev/null +++ b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupFeature.swift @@ -0,0 +1,46 @@ +import ComposableArchitecture +import Foundation +import XCTestDynamicOverlay + +public struct ContactLookupState: Equatable { + public init( + id: Data, + isLookingUp: Bool = false + ) { + self.id = id + self.isLookingUp = isLookingUp + } + + public var id: Data + public var isLookingUp: Bool +} + +public enum ContactLookupAction: Equatable { + case task + case cancelTask + case lookupTapped +} + +public struct ContactLookupEnvironment { + public init() {} +} + +#if DEBUG +extension ContactLookupEnvironment { + public static let unimplemented = ContactLookupEnvironment() +} +#endif + +public let contactLookupReducer = Reducer<ContactLookupState, ContactLookupAction, ContactLookupEnvironment> +{ state, action, env in + switch action { + case .task: + return .none + + case .cancelTask: + return .none + + case .lookupTapped: + return .none + } +} diff --git a/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift new file mode 100644 index 0000000000000000000000000000000000000000..1d1e02085ac84f849318dcf1b6548c5ee9cc4da4 --- /dev/null +++ b/Examples/xx-messenger/Sources/ContactLookupFeature/ContactLookupView.swift @@ -0,0 +1,69 @@ +import AppCore +import ComposableArchitecture +import SwiftUI + +public struct ContactLookupView: View { + public init(store: Store<ContactLookupState, ContactLookupAction>) { + self.store = store + } + + let store: Store<ContactLookupState, ContactLookupAction> + + struct ViewState: Equatable { + init(state: ContactLookupState) { + id = state.id + isLookingUp = state.isLookingUp + } + + var id: Data + var isLookingUp: Bool + } + + public var body: some View { + WithViewStore(store, observe: ViewState.init) { viewStore in + Form { + Section { + Label(viewStore.id.hexString, systemImage: "number") + .font(.footnote.monospaced()) + + Button { + viewStore.send(.lookupTapped) + } label: { + HStack { + Text("Lookup") + Spacer() + if viewStore.isLookingUp { + ProgressView() + } else { + Image(systemName: "magnifyingglass") + } + } + } + .disabled(viewStore.isLookingUp) + } header: { + Text("Contact ID") + } + } + .navigationTitle("Lookup") + .task { + await viewStore.send(.task).finish() + } + } + } +} + +#if DEBUG +public struct ContactLookupView_Previews: PreviewProvider { + public static var previews: some View { + NavigationView { + ContactLookupView(store: Store( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: .empty, + environment: () + )) + } + } +} +#endif diff --git a/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift new file mode 100644 index 0000000000000000000000000000000000000000..70847105030548fc33490bc567bb0cc0e57b2224 --- /dev/null +++ b/Examples/xx-messenger/Tests/ContactLookupFeatureTests/ContactLookupFeatureTests.swift @@ -0,0 +1,31 @@ +import ComposableArchitecture +import XCTest +@testable import ContactLookupFeature + +final class ContactLookupFeatureTests: XCTestCase { + func testTask() { + let store = TestStore( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: contactLookupReducer, + environment: .unimplemented + ) + + store.send(.task) + + store.send(.cancelTask) + } + + func testLookup() { + let store = TestStore( + initialState: ContactLookupState( + id: "1234".data(using: .utf8)! + ), + reducer: contactLookupReducer, + environment: .unimplemented + ) + + store.send(.lookupTapped) + } +}