Adds getting/sending messages
This commit is contained in:
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user