From 9f917413543f2e5657dbd4dfb2d8f2e6f3e3d1b5 Mon Sep 17 00:00:00 2001 From: fmodf Date: Fri, 21 Jun 2024 12:42:50 +0200 Subject: [PATCH] wip --- .../AppCore/Actions/ConversationActions.swift | 2 +- .../AppCore/Middlewares/ConversationMiddleware.swift | 6 ++++++ .../AppCore/Reducers/ConversationReducer.swift | 4 ++-- ConversationsClassic/AppCore/State/AppState.swift | 1 + ConversationsClassic/View/BaseNavigationView.swift | 3 +++ .../{ChatScreen.swift => ConversationScreen.swift} | 12 ++++++------ 6 files changed, 19 insertions(+), 9 deletions(-) rename ConversationsClassic/View/Screens/{ChatScreen.swift => ConversationScreen.swift} (92%) diff --git a/ConversationsClassic/AppCore/Actions/ConversationActions.swift b/ConversationsClassic/AppCore/Actions/ConversationActions.swift index a419373..a50e8b4 100644 --- a/ConversationsClassic/AppCore/Actions/ConversationActions.swift +++ b/ConversationsClassic/AppCore/Actions/ConversationActions.swift @@ -1,3 +1,3 @@ enum ConversationAction: Codable { - case dumb + case makeConversationActive(chat: Chat) } diff --git a/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift index b64dd3f..ddcd4bf 100644 --- a/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift +++ b/ConversationsClassic/AppCore/Middlewares/ConversationMiddleware.swift @@ -5,6 +5,12 @@ final class ConversationMiddleware { func middleware(state _: AppState, action: AppAction) -> AnyPublisher { switch action { + case .chatsAction(.chatStarted(let chat)): + return Just(AppAction.conversationAction(.makeConversationActive(chat: chat))).eraseToAnyPublisher() + + case .conversationAction(.makeConversationActive): + return Just(AppAction.changeFlow(.conversation)).eraseToAnyPublisher() + default: return Empty().eraseToAnyPublisher() } diff --git a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift index 99581da..4f1c5e5 100644 --- a/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift +++ b/ConversationsClassic/AppCore/Reducers/ConversationReducer.swift @@ -1,8 +1,8 @@ extension ConversationState { static func reducer(state: inout ConversationState, action: ConversationAction) { switch action { - case .dumb: - state.dumb = true + case .makeConversationActive(let chat): + state.currentChat = chat default: break diff --git a/ConversationsClassic/AppCore/State/AppState.swift b/ConversationsClassic/AppCore/State/AppState.swift index 6928485..9db82c9 100644 --- a/ConversationsClassic/AppCore/State/AppState.swift +++ b/ConversationsClassic/AppCore/State/AppState.swift @@ -6,6 +6,7 @@ enum AppFlow: Codable { case chats case contacts case settings + case conversation } struct AppState: Stateable { diff --git a/ConversationsClassic/View/BaseNavigationView.swift b/ConversationsClassic/View/BaseNavigationView.swift index 3848577..558b471 100644 --- a/ConversationsClassic/View/BaseNavigationView.swift +++ b/ConversationsClassic/View/BaseNavigationView.swift @@ -30,6 +30,9 @@ struct BaseNavigationView: View { case .settings: SettingsScreen() + + case .conversation: + ConversationScreen() } } } diff --git a/ConversationsClassic/View/Screens/ChatScreen.swift b/ConversationsClassic/View/Screens/ConversationScreen.swift similarity index 92% rename from ConversationsClassic/View/Screens/ChatScreen.swift rename to ConversationsClassic/View/Screens/ConversationScreen.swift index e7c9a8f..9833e1e 100644 --- a/ConversationsClassic/View/Screens/ChatScreen.swift +++ b/ConversationsClassic/View/Screens/ConversationScreen.swift @@ -3,13 +3,13 @@ import Foundation import Martin import SwiftUI -struct ChatScreen: View { - // @EnvironmentObject var state: AppState +struct ConversationScreen: View { + @EnvironmentObject var store: AppStore var body: some View { VStack(spacing: 0) { // Header - ChatScreenHeader() + ConversationScreenHeader() // Msg list // if !state.messages.isEmpty { @@ -26,7 +26,7 @@ struct ChatScreen: View { } } -private struct ChatScreenHeader: View { +private struct ConversationScreenHeader: View { // @EnvironmentObject var state: AppState var body: some View { @@ -48,7 +48,7 @@ private struct ChatScreenHeader: View { Image(systemName: "chevron.left") .foregroundColor(Color.Tango.orangeMedium) .tappablePadding(.symmetric(12)) { - // state.flow = .chatsList + store.dispatch(.changeFlow(store.state.previousFlow)) } Spacer() // Image(systemName: "plus.viewfinder") @@ -63,7 +63,7 @@ private struct ChatScreenHeader: View { } } -private struct ChatMessageView: View { +private struct ConversationMessageView: View { // @EnvironmentObject var state: AppState let message: Message