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.
49 lines
1.2 KiB
49 lines
1.2 KiB
3 years ago
|
|
||
|
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
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
.navigationTitle("Kordophone")
|
||
|
}
|
||
|
}
|
||
|
|
||
|
struct ConversationListWrapper : View {
|
||
|
@Binding var selectedConversation: Conversation?
|
||
|
|
||
|
@State private var conversations = [Conversation]()
|
||
|
@EnvironmentObject private var connection: Connection
|
||
|
|
||
|
private func refresh() {
|
||
|
Task {
|
||
|
self.conversations = await connection.conversations() ?? .init()
|
||
|
}
|
||
|
}
|
||
|
|
||
|
var body: some View {
|
||
|
ConversationList(selectedConversation: $selectedConversation, conversations: conversations)
|
||
|
.onAppear {
|
||
|
refresh()
|
||
|
}
|
||
|
}
|
||
|
}
|