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 { ...@@ -17,18 +17,21 @@ public struct ChatState: Equatable, Identifiable {
id: Int64, id: Int64,
date: Date, date: Date,
senderId: Data, senderId: Data,
text: String text: String,
status: XXModels.Message.Status
) { ) {
self.id = id self.id = id
self.date = date self.date = date
self.senderId = senderId self.senderId = senderId
self.text = text self.text = text
self.status = status
} }
public var id: Int64 public var id: Int64
public var date: Date public var date: Date
public var senderId: Data public var senderId: Data
public var text: String public var text: String
public var status: XXModels.Message.Status
} }
public init( public init(
...@@ -118,7 +121,8 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment> ...@@ -118,7 +121,8 @@ public let chatReducer = Reducer<ChatState, ChatAction, ChatEnvironment>
id: id, id: id,
date: message.date, date: message.date,
senderId: message.senderId, senderId: message.senderId,
text: message.text text: message.text,
status: message.status
) )
} }
} }
......
...@@ -95,7 +95,7 @@ public struct ChatView: View { ...@@ -95,7 +95,7 @@ public struct ChatView: View {
var body: some View { var body: some View {
VStack { VStack {
Text("\(message.date.formatted())") Text("\(message.date.formatted()), \(statusText)")
.foregroundColor(.secondary) .foregroundColor(.secondary)
.font(.footnote) .font(.footnote)
.frame(maxWidth: .infinity, alignment: alignment) .frame(maxWidth: .infinity, alignment: alignment)
...@@ -112,6 +112,18 @@ public struct ChatView: View { ...@@ -112,6 +112,18 @@ public struct ChatView: View {
} }
.padding(.horizontal) .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 { ...@@ -128,13 +140,15 @@ public struct ChatView_Previews: PreviewProvider {
id: 1, id: 1,
date: Date(), date: Date(),
senderId: "contact-id".data(using: .utf8)!, senderId: "contact-id".data(using: .utf8)!,
text: "Hello!" text: "Hello!",
status: .received
), ),
.init( .init(
id: 2, id: 2,
date: Date(), date: Date(),
senderId: "my-contact-id".data(using: .utf8)!, senderId: "my-contact-id".data(using: .utf8)!,
text: "Hi!" text: "Hi!",
status: .sent
), ),
] ]
), ),
......
...@@ -87,13 +87,15 @@ final class ChatFeatureTests: XCTestCase { ...@@ -87,13 +87,15 @@ final class ChatFeatureTests: XCTestCase {
id: 1, id: 1,
date: Date(timeIntervalSince1970: 1), date: Date(timeIntervalSince1970: 1),
senderId: contactId, senderId: contactId,
text: "Message 1" text: "Message 1",
status: .received
), ),
.init( .init(
id: 2, id: 2,
date: Date(timeIntervalSince1970: 2), date: Date(timeIntervalSince1970: 2),
senderId: myContactId, 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