This commit is contained in:
fmodf 2024-06-21 12:42:50 +02:00
parent 47943f15ff
commit 9f91741354
6 changed files with 19 additions and 9 deletions

View file

@ -1,3 +1,3 @@
enum ConversationAction: Codable {
case dumb
case makeConversationActive(chat: Chat)
}

View file

@ -5,6 +5,12 @@ final class ConversationMiddleware {
func middleware(state _: AppState, action: AppAction) -> AnyPublisher<AppAction, Never> {
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()
}

View file

@ -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

View file

@ -6,6 +6,7 @@ enum AppFlow: Codable {
case chats
case contacts
case settings
case conversation
}
struct AppState: Stateable {

View file

@ -30,6 +30,9 @@ struct BaseNavigationView: View {
case .settings:
SettingsScreen()
case .conversation:
ConversationScreen()
}
}
}

View file

@ -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