Skip to content

Commit 40d9788

Browse files
committed
extend composableArh navigation + implement Conversation list + Move to ChatRoom
1 parent 8ddb7d1 commit 40d9788

File tree

25 files changed

+767
-93
lines changed

25 files changed

+767
-93
lines changed

Addame/Addame.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ struct AddameApp: App {
2424
static let tabsState = TabsState(
2525
selectedTab: .event,
2626
event: EventsState(),
27-
chat: ChatState(),
27+
conversations: ConversationsState(),
2828
profile: ProfileState()
2929
)
3030

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// ActivityIndicator.swift
3+
//
4+
//
5+
// Created by Saroar Khandoker on 21.04.2021.
6+
//
7+
8+
import SwiftUI
9+
10+
public struct ActivityIndicator: UIViewRepresentable {
11+
public init() {}
12+
13+
public func makeUIView(context: Context) -> UIActivityIndicatorView {
14+
let view = UIActivityIndicatorView(style: .large)
15+
view.color = .systemBackground
16+
view.startAnimating()
17+
return view
18+
}
19+
20+
public func updateUIView(_ uiView: UIActivityIndicatorView, context: Context) {}
21+
}
22+

Addame/Modules/Views/EventView/Sources/NavigationLink+Store.swift renamed to Addame/Modules/Core/SwiftUIExtension/Sources/SwiftUIExtension/NavigationLink+Store.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ extension View {
5959
/// - destinationStore: store with non-optional state
6060
/// - onDismiss: closure invoked when link is deactivated
6161
/// - Returns: view with label-less `NavigationLink` added as a background view
62-
func navigate<State, Action, DestinationContent>(
62+
public func navigate<State, Action, DestinationContent>(
6363
using store: Store<State?, Action>,
6464
destination: @escaping (_ destinationStore: Store<State, Action>) -> DestinationContent,
6565
onDismiss: @escaping () -> Void

Addame/Modules/Services/ConversationClient/Package.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ let package = Package(
2323
targets: ["ConversationClientLive"]),
2424
],
2525
dependencies: [
26+
.package(path: "\(Path.Container.core)/Common"),
2627
.package(path: "\(Path.Container.core)/FuncNetworking"),
2728
.package(path: "\(Path.Container.domain)/AddaMeModels"),
2829
.package(path: "\(Path.Container.core)/FoundationExtension"),
@@ -32,7 +33,7 @@ let package = Package(
3233
targets: [
3334
.target(
3435
name: "ConversationClient",
35-
dependencies: ["FoundationExtension","FuncNetworking", "AddaMeModels"]),
36+
dependencies: ["Common", "FoundationExtension","FuncNetworking", "AddaMeModels"]),
3637
.target(
3738
name: "ConversationClientLive",
3839
dependencies: ["ConversationClient", "KeychainService", "InfoPlist"]),

Addame/Modules/Services/ConversationClient/Sources/ConversationClientLive/Live.swift

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,7 @@ public struct ConversationAPI {
9999
.eraseToAnyPublisher()
100100
}
101101

102-
public func list(
103-
query: QueryItem,
104-
path: String
105-
) -> AnyPublisher<ConversationResponse, HTTPError> {
102+
public func list(query: QueryItem, path: String ) -> AnyPublisher<ConversationResponse, HTTPError> {
106103
return tokenHandle(input: query, path: path, method: .get)
107104
.map { $0 }
108105
.catch { (error: HTTPError) -> AnyPublisher<ConversationResponse, HTTPError> in
@@ -112,10 +109,8 @@ public struct ConversationAPI {
112109
.eraseToAnyPublisher()
113110
}
114111

115-
public func find(
116-
conversationsId: String,
117-
path: String
118-
) -> AnyPublisher<ConversationResponse.Item, HTTPError> {
112+
113+
public func find(conversationsId: String, path: String ) -> AnyPublisher<ConversationResponse.Item, HTTPError> {
119114
return tokenHandle(input: conversationsId, path: path, method: .get)
120115
.map { $0 }
121116
.catch { (error: HTTPError) -> AnyPublisher<ConversationResponse.Item, HTTPError> in

Addame/Modules/Services/EventClient/Sources/EventClient/Mocks.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ extension EventClient {
4545
.setFailureType(to: HTTPError.self)
4646
.receive(on: DispatchQueue.main)
4747
.eraseToAnyPublisher()
48-
4948
}
49+
5050
)
5151

5252
}

Addame/Modules/Views/ChatView/Package.swift

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
import PackageDescription
55

6+
enum Path {
7+
static let modules = "../Modules"
8+
enum Container {
9+
static let core = "\(Path.modules)/Core"
10+
static let domains = "\(Path.modules)/Domains"
11+
static let services = "\(Path.modules)/Services"
12+
static let views = "\(Path.modules)/Views"
13+
}
14+
}
15+
616
let package = Package(
717
name: "ChatView",
818
platforms: [.iOS(.v14)],
@@ -12,12 +22,50 @@ let package = Package(
1222
targets: ["ChatView"]),
1323
],
1424
dependencies: [
15-
.package(path: "../Modules/Core/Common"),
25+
// Domains
26+
.package(path: "\(Path.Container.domains)/AddaMeModels"),
27+
28+
// Core
29+
.package(path: "\(Path.Container.core)/Common"),
30+
.package(path: "\(Path.Container.core)/AsyncImageLoder"),
31+
.package(path: "\(Path.Container.core)/FuncNetworking"),
32+
.package(path: "\(Path.Container.core)/InfoPlist"),
33+
.package(path: "\(Path.Container.core)/KeychainService"),
34+
.package(path: "\(Path.Container.core)/FoundationExtension"),
35+
.package(path: "\(Path.Container.core)/SwiftUIExtension"),
36+
37+
// Services
38+
.package(path: "\(Path.Container.services)/WebsocketClient"),
39+
.package(path: "\(Path.Container.services)/ConversationClient"),
40+
.package(path: "\(Path.Container.services)/ChatClient")
41+
1642
],
1743
targets: [
1844
.target(
1945
name: "ChatView",
20-
dependencies: ["Common"],
46+
dependencies: [
47+
48+
// Domains
49+
"AddaMeModels",
50+
51+
// Services
52+
"InfoPlist", "Common",
53+
"WebsocketClient", "ConversationClient", "ChatClient",
54+
55+
// Core
56+
"SwiftUIExtension", "FoundationExtension", "AsyncImageLoder",
57+
"FuncNetworking", "KeychainService",
58+
59+
// Views
60+
61+
62+
// Live
63+
.product(name: "ChatClientLive", package: "ChatClient"),
64+
.product(name: "ConversationClientLive", package: "ConversationClient"),
65+
.product(name: "WebsocketClientLive", package: "WebsocketClient"),
66+
67+
],
68+
2169
path: "Sources"
2270
),
2371
.testTarget(

Addame/Modules/Views/ChatView/Sources/ChatView/ChatAction.swift

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,25 @@
55
// Created by Saroar Khandoker on 06.04.2021.
66
//
77

8-
public enum ChatAction: Equatable {}
8+
import AddaMeModels
9+
10+
public enum ChatAction: Equatable {
11+
case alertDismissed
12+
case conversation(ConversationResponse.Item?)
13+
}
14+
15+
public extension ChatAction {
16+
static func view(_ localAction: ChatView.ViewAction) -> Self {
17+
switch localAction {
18+
19+
case .alertDismissed:
20+
return .alertDismissed
21+
case .conversation(let conversation):
22+
return .conversation(conversation)
23+
}
24+
}
25+
}
26+
27+
28+
//public extension ProfileAction {
29+
// static func view(_ localAction: ProfileView.ViewAction) -> Self {
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//
2+
// ChatEnvironment.swift
3+
//
4+
//
5+
// Created by Saroar Khandoker on 19.04.2021.
6+
//
7+
8+
import Combine
9+
import ComposableArchitecture
10+
import ChatClient
11+
import ConversationClient
12+
import WebsocketClient
13+
import AddaMeModels
14+
15+
public struct ChatEnvironment {
16+
17+
let chatClient: ChatClient
18+
public var mainQueue: AnySchedulerOf<DispatchQueue>
19+
20+
public init(
21+
chatClient: ChatClient,
22+
mainQueue: AnySchedulerOf<DispatchQueue>
23+
) {
24+
self.chatClient = chatClient
25+
self.mainQueue = mainQueue
26+
}
27+
28+
}
29+
30+
public class WebsocketEnvironment {
31+
32+
let websocketClient: WebsocketClient
33+
public var mainQueue: AnySchedulerOf<DispatchQueue>
34+
35+
public init(
36+
websocketClient: WebsocketClient,
37+
mainQueue: AnySchedulerOf<DispatchQueue>
38+
) {
39+
self.websocketClient = websocketClient
40+
self.websocketClient.handshake()
41+
self.mainQueue = mainQueue
42+
}
43+
44+
public func send(_ msg: SocketMessage) {
45+
self.websocketClient.send(msg.localMsg, msg.remostJSON)
46+
}
47+
48+
}
49+
50+
public struct SocketMessage: Equatable {
51+
public var localMsg: ChatMessageResponse.Item
52+
public var remostJSON: String
53+
54+
public static func ==(lhs: SocketMessage, rhs: SocketMessage) -> Bool {
55+
return lhs.localMsg == rhs.localMsg && lhs.remostJSON == rhs.remostJSON
56+
}
57+
}

Addame/Modules/Views/ChatView/Sources/ChatView/ChatReducer.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,12 @@ import ComposableArchitecture
1010
public let chatReducer = Reducer<ChatState, ChatAction, Void> { state, action, _ in
1111
switch action {
1212

13+
case .alertDismissed:
14+
state.alert = nil
15+
return .none
16+
case .conversation(let converstion):
17+
state.conversation = converstion
18+
return .none
19+
1320
}
1421
}

0 commit comments

Comments
 (0)