import KordophoneKit import SwiftUI struct ConversationList : View { @Binding var selectedConversation: Conversation? var conversations: [Conversation] var sortedConversations: [Conversation] { conversations .sorted { a, b in a.date > b.date } } var body: some View { List { ForEach(sortedConversations) { convo in ConversationRow(conversation: convo) .contentShape(Rectangle()) .onTapGesture { selectedConversation = convo } } } .animation(.spring(), value: sortedConversations) .animation(.spring(), value: selectedConversation) .navigationTitle("Kordophone") } } struct ConversationListWrapper : View { @Binding var selectedConversation: Conversation? @State private var conversations = [Conversation]() @EnvironmentObject private var connection: Connection @StateObject private var updater = IntervalUpdater(5) private func refresh() { Task { self.conversations = await connection.conversations() ?? .init() } } var body: some View { ConversationList(selectedConversation: $selectedConversation, conversations: conversations) .onAppear { refresh() } .onChange(of: connection.authenticated) { newValue in refresh() } .onChange(of: updater.seed) { newValue in refresh() } } }