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.
55 lines
1.5 KiB
55 lines
1.5 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 |
|
} |
|
} |
|
} |
|
.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() |
|
} |
|
} |
|
}
|
|
|