Private
Public Access
1
0

Adds getting/sending messages

This commit is contained in:
2025-08-24 17:58:37 -07:00
parent b5a2f318b4
commit 3ee94a3bea
6 changed files with 345 additions and 2 deletions

View File

@@ -11,19 +11,33 @@ import SwiftUI
struct KordophoneApp: App
{
@State var conversationListModel = ConversationListView.ViewModel()
@State var transcriptViewModel = ChatTranscriptView.ViewModel()
@State var entryViewModel = MessageEntryView.ViewModel()
private let xpcClient = XPCClient()
private var selectedConversation: Display.Conversation? {
guard let id = conversationListModel.selectedConversations.first else { return nil }
return conversationListModel.conversations.first { $0.id == id }
}
var body: some Scene {
WindowGroup {
NavigationSplitView {
ConversationListView(model: $conversationListModel)
.frame(minWidth: 330.0)
.xpcClient(xpcClient)
.task {
await refreshConversations()
}
} detail: {
// Detail
ConversationView(transcriptModel: $transcriptViewModel, entryModel: $entryViewModel)
.xpcClient(xpcClient)
.selectedConversation(selectedConversation)
.navigationTitle("Kordophone")
.navigationSubtitle(selectedConversation?.displayName ?? "")
.onChange(of: conversationListModel.selectedConversations) { oldValue, newValue in
transcriptViewModel.displayedConversation = newValue.first
}
}
}
}
@@ -42,3 +56,21 @@ struct KordophoneApp: App
print("Error: \(e.localizedDescription)")
}
}
extension EnvironmentValues
{
@Entry var xpcClient: XPCClient = XPCClient()
@Entry var selectedConversation: Display.Conversation? = nil
}
extension View
{
func xpcClient(_ client: XPCClient) -> some View {
environment(\.xpcClient, client)
}
func selectedConversation(_ convo: Display.Conversation?) -> some View {
environment(\.selectedConversation, convo)
}
}