Message loading on watchOS

This commit is contained in:
2025-10-30 02:04:10 +08:00
parent 44dbcfdc94
commit 6fc94001b3
3 changed files with 199 additions and 75 deletions

View File

@@ -181,7 +181,10 @@ struct ChatRoomListItem: View {
}
var body: some View {
NavigationLink(destination: ChatRoomView(room: room)) {
NavigationLink(
destination: ChatRoomView(room: room)
.environmentObject(appState)
) {
HStack {
// Avatar using ImageLoader pattern
Group {
@@ -292,9 +295,23 @@ struct ChatRoomView: View {
}
private func loadMessages() async {
// Placeholder for message loading
// In a full implementation, this would fetch messages from the API
// For now, just show empty state
guard let token = appState.token, let serverUrl = appState.serverUrl else {
isLoading = false
return
}
do {
let messages = try await appState.networkService.fetchChatMessages(
chatRoomId: room.id,
token: token,
serverUrl: serverUrl
)
self.messages = messages.sorted { $0.createdAt < $1.createdAt }
} catch {
print("[watchOS] Error loading messages: \(error.localizedDescription)")
self.error = error
}
isLoading = false
}
}