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

Present group chat screen

parent 2d7b7dcb
No related branches found
No related tags found
2 merge requests!153Release 1.1.0,!152[Messenger example] group chat
......@@ -267,6 +267,7 @@ let package = Package(
name: "GroupFeature",
dependencies: [
.target(name: "AppCore"),
.target(name: "ChatFeature"),
.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 ChatFeature
import ComposableArchitecture
import ComposablePresentation
import Foundation
import XXMessengerClient
import XXModels
......@@ -10,18 +12,21 @@ public struct GroupComponent: ReducerProtocol {
groupId: XXModels.Group.ID,
groupInfo: XXModels.GroupInfo? = nil,
isJoining: Bool = false,
joinFailure: String? = nil
joinFailure: String? = nil,
chat: ChatComponent.State? = nil
) {
self.groupId = groupId
self.groupInfo = groupInfo
self.isJoining = isJoining
self.joinFailure = joinFailure
self.chat = chat
}
public var groupId: XXModels.Group.ID
public var groupInfo: XXModels.GroupInfo?
public var isJoining: Bool
public var joinFailure: String?
public var chat: ChatComponent.State?
}
public enum Action: Equatable {
......@@ -30,6 +35,9 @@ public struct GroupComponent: ReducerProtocol {
case joinButtonTapped
case didJoin
case didFailToJoin(String)
case chatButtonTapped
case didDismissChat
case chat(ChatComponent.Action)
}
public init() {}
......@@ -88,7 +96,24 @@ public struct GroupComponent: ReducerProtocol {
state.isJoining = false
state.joinFailure = failure
return .none
case .chatButtonTapped:
state.chat = ChatComponent.State(id: .group(state.groupId))
return .none
case .didDismissChat:
state.chat = nil
return .none
case .chat(_):
return .none
}
}
.presenting(
state: .keyPath(\.chat),
id: .notNil(),
action: /Action.chat,
presented: { ChatComponent() }
)
}
}
import AppCore
import ChatFeature
import ComposableArchitecture
import ComposablePresentation
import SwiftUI
import XXModels
......@@ -68,8 +70,28 @@ public struct GroupView: View {
}
}
}
Section {
Button {
viewStore.send(.chatButtonTapped)
} label: {
HStack {
Text("Chat")
Spacer()
Image(systemName: "chevron.forward")
}
}
}
}
.navigationTitle("Group")
.background(NavigationLinkWithStore(
store.scope(
state: \.chat,
action: Component.Action.chat
),
onDeactivate: { viewStore.send(.didDismissChat) },
destination: ChatView.init(store:)
))
.task { viewStore.send(.start) }
}
}
......
import ChatFeature
import Combine
import ComposableArchitecture
import CustomDump
......@@ -140,6 +141,26 @@ final class GroupComponentTests: XCTestCase {
$0.joinFailure = failure.localizedDescription
}
}
func testPresentChat() {
let groupInfo = GroupInfo.stub()
let store = TestStore(
initialState: GroupComponent.State(
groupId: groupInfo.group.id,
groupInfo: groupInfo
),
reducer: GroupComponent()
)
store.send(.chatButtonTapped) {
$0.chat = ChatComponent.State(id: .group(groupInfo.id))
}
store.send(.didDismissChat) {
$0.chat = nil
}
}
}
private extension XXModels.GroupInfo {
......
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