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

Update ChatView

parent dd53d9f1
No related branches found
No related tags found
2 merge requests!102Release 1.0.0,!87Messenger example - chat
...@@ -13,12 +13,14 @@ public struct ChatView: View { ...@@ -13,12 +13,14 @@ public struct ChatView: View {
var myContactId: Data? var myContactId: Data?
var messages: IdentifiedArrayOf<ChatState.Message> var messages: IdentifiedArrayOf<ChatState.Message>
var failure: String? var failure: String?
var sendFailure: String?
var text: String var text: String
init(state: ChatState) { init(state: ChatState) {
myContactId = state.myContactId myContactId = state.myContactId
messages = state.messages messages = state.messages
failure = state.failure failure = state.failure
sendFailure = state.sendFailure
text = state.text text = state.text
} }
} }
...@@ -28,22 +30,47 @@ public struct ChatView: View { ...@@ -28,22 +30,47 @@ public struct ChatView: View {
ScrollView { ScrollView {
LazyVStack { LazyVStack {
if let failure = viewStore.failure { if let failure = viewStore.failure {
Text(failure) VStack {
.frame(maxWidth: .infinity, alignment: .leading) Text(failure)
.padding() .frame(maxWidth: .infinity, alignment: .leading)
Button { Button {
viewStore.send(.start) viewStore.send(.start)
} label: { } label: {
Text("Retry") Text("Retry").padding()
}
}
.padding()
.background {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Material.ultraThick)
} }
.padding() .padding()
} }
ForEach(viewStore.messages) { message in ForEach(viewStore.messages) { message in
MessageView( MessageView(
message: message, message: message,
myContactId: viewStore.myContactId myContactId: viewStore.myContactId
) )
} }
if let sendFailure = viewStore.sendFailure {
VStack {
Text(sendFailure)
.frame(maxWidth: .infinity, alignment: .leading)
Button {
viewStore.send(.dismissSendFailureTapped)
} label: {
Text("Dismiss").padding()
}
}
.padding()
.background {
RoundedRectangle(cornerRadius: 12, style: .continuous)
.fill(Material.ultraThick)
}
.padding()
}
} }
} }
.toolbar( .toolbar(
...@@ -69,7 +96,7 @@ public struct ChatView: View { ...@@ -69,7 +96,7 @@ public struct ChatView: View {
} }
.padding() .padding()
} }
.background(Material.regularMaterial) .background(Material.bar)
} }
.navigationTitle("Chat") .navigationTitle("Chat")
.task { viewStore.send(.start) } .task { viewStore.send(.start) }
...@@ -85,10 +112,6 @@ public struct ChatView: View { ...@@ -85,10 +112,6 @@ public struct ChatView: View {
message.senderId == myContactId ? .trailing : .leading message.senderId == myContactId ? .trailing : .leading
} }
var backgroundColor: Color {
message.senderId == myContactId ? Color.blue : Color.gray.opacity(0.5)
}
var textColor: Color? { var textColor: Color? {
message.senderId == myContactId ? Color.white : nil message.senderId == myContactId ? Color.white : nil
} }
...@@ -105,8 +128,13 @@ public struct ChatView: View { ...@@ -105,8 +128,13 @@ public struct ChatView: View {
.padding(.horizontal, 16) .padding(.horizontal, 16)
.padding(.vertical, 8) .padding(.vertical, 8)
.background { .background {
RoundedRectangle(cornerRadius: 16, style: .continuous) if message.senderId == myContactId {
.fill(backgroundColor) RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(Color.blue)
} else {
RoundedRectangle(cornerRadius: 16, style: .continuous)
.fill(Material.ultraThick)
}
} }
.frame(maxWidth: .infinity, alignment: alignment) .frame(maxWidth: .infinity, alignment: alignment)
} }
...@@ -150,7 +178,9 @@ public struct ChatView_Previews: PreviewProvider { ...@@ -150,7 +178,9 @@ public struct ChatView_Previews: PreviewProvider {
text: "Hi!", text: "Hi!",
status: .sent status: .sent
), ),
] ],
failure: "Something went wrong when fetching messages from database.",
sendFailure: "Something went wrong when sending message."
), ),
reducer: .empty, reducer: .empty,
environment: () environment: ()
......
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