Skip to content
Snippets Groups Projects
Commit 388c66c7 authored by Dariusz Rybicki's avatar Dariusz Rybicki
Browse files

Show message status in ChatView

parent 2d709642
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!87Messenger example - chat
......@@ -17,18 +17,21 @@ public struct ChatState: Equatable, Identifiable {
id: Int64,
date: Date,
senderId: Data,
text: String
text: String,
status: XXModels.Message.Status
) {
self.id = id
self.date = date
self.senderId = senderId
self.text = text
self.status = status
}
public var id: Int64
public var date: Date
public var senderId: Data
public var text: String
public var status: XXModels.Message.Status
}
public init(
......@@ -118,7 +121,8 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
id: id,
date: message.date,
senderId: message.senderId,
text: message.text
text: message.text,
status: message.status
)
}
}
......
......@@ -95,7 +95,7 @@ public struct ChatView: View {
var body: some View {
VStack {
Text("\(message.date.formatted())")
Text("\(message.date.formatted()), \(statusText)")
.foregroundColor(.secondary)
.font(.footnote)
.frame(maxWidth: .infinity, alignment: alignment)
......@@ -112,6 +112,18 @@ public struct ChatView: View {
}
.padding(.horizontal)
}
var statusText: String {
switch message.status {
case .sending: return "Sending"
case .sendingTimedOut: return "Sending timed out"
case .sendingFailed: return "Failed"
case .sent: return "Sent"
case .receiving: return "Receiving"
case .receivingFailed: return "Receiving failed"
case .received: return "Received"
}
}
}
}
......@@ -128,13 +140,15 @@ public struct ChatView_Previews: PreviewProvider {
id: 1,
date: Date(),
senderId: "contact-id".data(using: .utf8)!,
text: "Hello!"
text: "Hello!",
status: .received
),
.init(
id: 2,
date: Date(),
senderId: "my-contact-id".data(using: .utf8)!,
text: "Hi!"
text: "Hi!",
status: .sent
),
]
),
......
......@@ -87,13 +87,15 @@ final class ChatFeatureTests: XCTestCase {
id: 1,
date: Date(timeIntervalSince1970: 1),
senderId: contactId,
text: "Message 1"
text: "Message 1",
status: .received
),
.init(
id: 2,
date: Date(timeIntervalSince1970: 2),
senderId: myContactId,
text: "Message 2"
text: "Message 2",
status: .sent
),
])
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment