From 47943f15ff79aec9387d25570a43127093c36741 Mon Sep 17 00:00:00 2001 From: fmodf Date: Fri, 21 Jun 2024 12:32:16 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/AppActions.swift | 1 + .../AppCore/Actions/ConversationActions.swift | 3 +++ .../AppCore/Middlewares/ChatsMiddleware.swift | 4 ---- .../AppCore/Middlewares/ConversationMiddleware.swift | 12 ++++++++++++ .../AppCore/Reducers/AppReducer.swift | 3 +++ .../AppCore/Reducers/ConversationReducer.swift | 11 +++++++++++ ConversationsClassic/AppCore/State/AppState.swift | 2 ++ .../AppCore/State/ConversationState.swift | 11 +++++++++++ ConversationsClassic/ConversationsClassicApp.swift | 3 ++- 9 files changed, 45 insertions(+), 5 deletions(-) create mode 100644 ConversationsClassic/AppCore/Actions/ConversationActions.swift create mode 100644 ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift create mode 100644 ConversationsClassic/AppCore/Reducers/ConversationReducer.swift create mode 100644 ConversationsClassic/AppCore/State/ConversationState.swift diff --git a/ConversationsClassic/AppCore/Actions/AppActions.swift b/ConversationsClassic/AppCore/Actions/AppActions.swift index e97afdd..97f387b 100644 --- a/ConversationsClassic/AppCore/Actions/AppActions.swift +++ b/ConversationsClassic/AppCore/Actions/AppActions.swift @@ -9,4 +9,5 @@ enum AppAction: Codable { case xmppAction(_ action: XMPPAction) case rostersAction(_ action: RostersAction) case chatsAction(_ action: ChatsAction) + case conversationAction(_ action: ConversationAction) } diff --git a/ConversationsClassic/AppCore/Actions/ConversationActions.swift b/ConversationsClassic/AppCore/Actions/ConversationActions.swift new file mode 100644 index 0000000..a419373 --- /dev/null +++ b/ConversationsClassic/AppCore/Actions/ConversationActions.swift @@ -0,0 +1,3 @@ +enum ConversationAction: Codable { + case dumb +} diff --git a/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift index a3cfd82..5eea0fd 100644 --- a/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/ChatsMiddleware.swift @@ -25,10 +25,6 @@ final class ChatsMiddleware { return Just(.chatsAction(.chatStarted(chat: chat))) .eraseToAnyPublisher() - case .chatsAction(.chatStarted(let chat)): - // TODO: make transition to chat screen - return Empty().eraseToAnyPublisher() - default: return Empty().eraseToAnyPublisher() } diff --git a/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift new file mode 100644 index 0000000..b64dd3f --- /dev/null +++ b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift @@ -0,0 +1,12 @@ +import Combine + +final class ConversationMiddleware { + static let shared = ConversationMiddleware() + + func middleware(state _: AppState, action: AppAction) -> AnyPublisher { + switch action { + default: + return Empty().eraseToAnyPublisher() + } + } +} diff --git a/ConversationsClassic/AppCore/Reducers/AppReducer.swift b/ConversationsClassic/AppCore/Reducers/AppReducer.swift index ac17fe1..5c8ebf2 100644 --- a/ConversationsClassic/AppCore/Reducers/AppReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/AppReducer.swift @@ -24,6 +24,9 @@ extension AppState { case .chatsAction(let action): ChatsState.reducer(state: &state.chatsState, action: action) + + case .conversationAction(let action): + ConversationState.reducer(state: &state.conversationsState, action: action) } } } diff --git a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift new file mode 100644 index 0000000..99581da --- /dev/null +++ b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift @@ -0,0 +1,11 @@ +extension ConversationState { + static func reducer(state: inout ConversationState, action: ConversationAction) { + switch action { + case .dumb: + state.dumb = true + + default: + break + } + } +} diff --git a/ConversationsClassic/AppCore/State/AppState.swift b/ConversationsClassic/AppCore/State/AppState.swift index 1dbb251..6928485 100644 --- a/ConversationsClassic/AppCore/State/AppState.swift +++ b/ConversationsClassic/AppCore/State/AppState.swift @@ -17,6 +17,7 @@ struct AppState: Stateable { var accountsState: AccountsState var rostersState: RostersState var chatsState: ChatsState + var conversationsState: ConversationState } // MARK: Init @@ -30,5 +31,6 @@ extension AppState { accountsState = AccountsState() rostersState = RostersState() chatsState = ChatsState() + conversationsState = ConversationState() } } diff --git a/ConversationsClassic/AppCore/State/ConversationState.swift b/ConversationsClassic/AppCore/State/ConversationState.swift new file mode 100644 index 0000000..b651573 --- /dev/null +++ b/ConversationsClassic/AppCore/State/ConversationState.swift @@ -0,0 +1,11 @@ +struct ConversationState: Stateable { + var currentChat: Chat? + var dumb: Bool +} + +// MARK: Init +extension ConversationState { + init() { + dumb = false + } +} diff --git a/ConversationsClassic/ConversationsClassicApp.swift b/ConversationsClassic/ConversationsClassicApp.swift index 76c2663..aa485fd 100644 --- a/ConversationsClassic/ConversationsClassicApp.swift +++ b/ConversationsClassic/ConversationsClassicApp.swift @@ -12,7 +12,8 @@ let store = AppStore( AccountsMiddleware.shared.middleware, XMPPMiddleware.shared.middleware, RostersMiddleware.shared.middleware, - ChatsMiddleware.shared.middleware + ChatsMiddleware.shared.middleware, + ConversationMiddleware.shared.middleware ] )