aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views/ChatView.swift
blob: 6dc731800c43e3bdc033d9d5143b0d18daaa9814 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import SwiftUI

struct ChatView: View {
  @Environment(HotlineClient.self) private var hotline
  
  @State var input: String = ""
  @State private var scrollPos: Int?
  @State private var contentHeight: CGFloat = 0
  
  var body: some View {
    VStack(spacing: 0) {
      List(hotline.chatMessages) { msg in
        if msg.username == "" {
          
        }
        HStack(alignment: .firstTextBaseline) {
          Text("\(msg.username):").bold().fontDesign(.monospaced).font(.system(size: 12))
          Text(msg.message)
            .fontDesign(.monospaced)
            .textSelection(.enabled)
            .font(.system(size: 12))
        }
      }
      .padding()
      
//      GeometryReader { geometry in
//        ScrollView(.vertical) {
//          ScrollViewReader { scrollReader in
//            VStack(alignment: .leading) {
//              Spacer()
//              List(hotline.chatMessages) { msg in
//                HStack(alignment: .firstTextBaseline) {
//                  Text("\(msg.username):").bold().fontDesign(.monospaced)
//                  Text(msg.message)
//                    .fontDesign(.monospaced)
//                    .textSelection(.enabled)
//                }
//              }
//              .padding()
//            }
//            //          .frame(width: geometry.size.width)
//            .frame(minHeight: geometry.size.height)
////            .background(Color.red)
//            .onAppear() {
////              scrollReader.scrollTo("bottomScroll", anchor: .bottom)
//            }
//            //          .onChange() {
//            //            scrollReader.scrollTo(10000, anchor: .bottomTrailing)
//            //          }
//          }
//        }
//      }
      
      Divider()
      
      HStack(alignment: .top) {
        Image(systemName: "chevron.right")
        TextField("", text: $input, axis: .vertical)
          .lineLimit(1...5)
          .onSubmit {
            hotline.sendChat(message: self.input)
            //        HotlineClient.shared.sendChat(message: self.input)
            self.input = ""
          }
      }.padding()
    }
  }
}

#Preview {
  ChatView()
    .environment(HotlineClient())
}