@@ -10,47 +10,64 @@ module ViewChat =
1010 open Store
1111 open AppTypes
1212 open Buttons
13+ open TextFields
1314
1415 let viewChat model pk compose =
1516 let name = contactName model.Contacts pk
1617 let msgs = messagesFor pk model.Messages
1718
18− (Grid([ Dimension.Auto; Dimension.Auto; Dimension.Star; Dimension.Auto ], [ Dimension.Star ]) {
19− (HStack(8.) {
20− backButton (SetPage Conversations)
19+ let bar =
20+ (Grid([ Dimension.Auto; Dimension.Star; Dimension.Auto ], [ Dimension.Auto ]) {
21+ (backButton (SetPage Conversations)).gridColumn (0)
2122
22− TextBlock(name).fontSize(20.).centerVertical ()
23+ (textField compose (fun text -> SetPage(Chat(pk, text))))
24+ .verticalAlignment(VerticalAlignment.Stretch)
25+ .margin(8.)
26+ .gridColumn (1)
27+
28+ (smallButton Primary "Send" DoSend).gridColumn (2)
2329 })
24− .gridRow (0)
25−
26− (viewErrorBanner model.Error).gridRow (1)
27−
28− (if msgs.IsEmpty then
29− AnyView(TextBlock("No messages yet").padding(8.).fontSize (14.))
30− else
31− let reversed = List.rev msgs
32−
33− AnyView(
34− ScrollViewer(
35− ItemsRepeater(reversed, fun m ->
36− let prefix, tick =
37− match m.Direction with
38− | Outgoing DeliveryStatus.Delivered -> "You: ", " \u2713"
39− | Outgoing DeliveryStatus.Sent -> "You: ", ""
40− | Incoming -> "", ""
41−
42− TextBlock($"{prefix}{m.Body}{tick}").padding(8.).fontSize (14.))
43− )
44− ))
45− .gridRow (2)
46−
47− (HStack(8.) {
48− TextBox(compose, fun text -> SetPage(Chat(pk, text)))
49− .watermark("Message...")
50− .horizontalAlignment (HorizontalAlignment.Stretch)
51−
52− Button("Send", DoSend)
30+ .horizontalAlignment (HorizontalAlignment.Stretch)
31+
32+ let content =
33+ (Grid([ Dimension.Star ], [ Dimension.Auto; Dimension.Auto; Dimension.Star ]) {
34+ TextBlock(name).fontSize(20.).padding(8.).gridRow (0)
35+
36+ (viewErrorBanner model.Error).gridRow (1)
37+
38+ (if msgs.IsEmpty then
39+ AnyView(TextBlock("No messages yet").padding(8.).fontSize (14.))
40+ else
41+ let layout = Avalonia.Layout.StackLayout()
42+ layout.DisableVirtualization <- true
43+
44+ AnyView(
45+ ScrollViewer(
46+ ItemsRepeater(msgs, fun m ->
47+ let tick =
48+ match m.Direction with
49+ | Outgoing DeliveryStatus.Delivered -> " ✓"
50+ | Outgoing DeliveryStatus.Sent -> ""
51+ | Incoming -> ""
52+
53+ let align =
54+ match m.Direction with
55+ | Incoming -> HorizontalAlignment.Right
56+ | Outgoing _ -> HorizontalAlignment.Left
57+
58+ Border(
59+ TextBlock($"{m.Body}{tick}")
60+ .fontSize(14.)
61+ .padding (8.))
62+ .borderThickness(Avalonia.Thickness(2.))
63+ .borderBrush(Avalonia.Media.SolidColorBrush(Avalonia.Media.Colors.Black))
64+ .horizontalAlignment(align)
65+ .margin (4.))
66+ .layout(layout)
67+ )
68+ .horizontalScrollBarVisibility(Avalonia.Controls.Primitives.ScrollBarVisibility.Disabled)
69+ .offset(Avalonia.Vector(0., System.Double.MaxValue))))
70+ .gridRow (2)
5371 })
54− .gridRow (3)
55− })
56− .margin (12.)
72+
73+ Styles.withBottomBar bar content