aboutsummaryrefslogtreecommitdiff
path: root/Hotline/TrackerView.swift
blob: 0bc9762f3f6139fefacdde690d6a0c325c8cdd86 (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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import SwiftUI
import SwiftData

struct TrackerView: View {
  //  @Environment(\.modelContext) private var modelContext
  //  @Query private var items: [Item]
  
  @StateObject var tracker = HotlineTracker(address: "hltracker.com")
  @State private var selectedServer: HotlineServer?
  
  private var client: HotlineClient?
  
  var body: some View {
    List(selection: $selectedServer) {
      ForEach(tracker.servers) { server in
        HStack {
          Text(server.name!).bold()
          Spacer()
          HStack {
            Text("\(server.users)").font(.system(size: 12)).bold().opacity(0.3)
  //          Image(systemName: "person.fill").font(.system(size: 12)).opacity(0.3)
          }
          .padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
          .background(Color(white: 0.94))
          .cornerRadius(20.0)
        }
//        .contentShape(Rectangle())
        .listRowSeparator(.hidden)
        .tag(server)
  //      .padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 0))
//        .onTapGesture {
//          self.selectedServer = server
//        }
      }
    }
    .listStyle(.plain)
    .frame(maxWidth: .infinity)
    .task {
      tracker.fetch()
    }
    .sheet(item: $selectedServer) { item in
      VStack(alignment: .leading) {
        Text(item.name!).bold().dynamicTypeSize(.xxLarge).padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0))
        Text(item.description!).opacity(0.4).dynamicTypeSize(.xLarge).padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0))
        Text(item.address).opacity(0.2).dynamicTypeSize(.medium)
        Spacer()
        HStack(alignment: .center) {
          Button("Connect") {
            print("WHAT", "HELLO", selectedServer!.address)
            HotlineClient.shared.connect(to: selectedServer!)
//            client = HotlineClient(server: selectedServer)
          }
          .bold()
          .padding(EdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24))
          .frame(maxWidth: .infinity)
          .foregroundColor(.white)
          .background(Color(.black))
          .cornerRadius(8.0)
        }
      }
      .padding(EdgeInsets(top: 28.0, leading: 24.0, bottom: 24.0, trailing: 24.0))
      .presentationDetents([.fraction(0.4)])
      .presentationDragIndicator(.visible)
    }
//    List(tracker.servers) { server in
//      HStack {
//        Text(server.name!).bold()
//        Spacer()
//        HStack {
//          Text("\(server.users)").font(.system(size: 12)).bold().opacity(0.3)
////          Image(systemName: "person.fill").font(.system(size: 12)).opacity(0.3)
//        }
//        .padding(EdgeInsets(top: 5, leading: 10, bottom: 5, trailing: 10))
//        .background(Color(white: 0.94))
//        .cornerRadius(20.0)
//      }
//      .contentShape(Rectangle())
//      .listRowSeparator(.hidden)
////      .padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 0))
//      .onTapGesture {
//        self.selectedServer = server
//      }
//    }
//    .listStyle(.plain)
//    .frame(maxWidth: .infinity)
//    .task {
//      tracker.fetch()
//    }
//    .sheet(item: $selectedServer) { item in
//      VStack(alignment: .leading) {
//        Text(item.name!).bold().dynamicTypeSize(.xxLarge).padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0))
//        Text(item.description!).opacity(0.4).dynamicTypeSize(.xLarge)
//        Spacer()
//        HStack(alignment: .center) {
//          Button("Connect") {
//            print("WHAT")
//          }
//          .bold()
//          .padding(EdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24))
//          .frame(maxWidth: .infinity)
//          .foregroundColor(.white)
//          .background(Color(.black))
//          .cornerRadius(8.0)
//        }
//      }
//      .padding(EdgeInsets(top: 28.0, leading: 24.0, bottom: 24.0, trailing: 24.0))
//      .presentationDetents([.fraction(0.3)])
//      .presentationDragIndicator(.visible)
//    }
  }
}

#Preview {
  TrackerView()
  //    .modelContainer(for: Item.self, inMemory: true)
}