Kordophone client for iOS and macOS
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.6 KiB

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()
}
}
}