diff options
Diffstat (limited to 'Hotline/TrackerView.swift')
| -rw-r--r-- | Hotline/TrackerView.swift | 139 |
1 files changed, 93 insertions, 46 deletions
diff --git a/Hotline/TrackerView.swift b/Hotline/TrackerView.swift index 04498b1..0bc9762 100644 --- a/Hotline/TrackerView.swift +++ b/Hotline/TrackerView.swift @@ -2,68 +2,115 @@ import SwiftUI import SwiftData struct TrackerView: View { - @Environment(\.modelContext) private var modelContext - @Query private var items: [Item] + // @Environment(\.modelContext) private var modelContext + // @Query private var items: [Item] - @StateObject var tracker = HotlineTracker(address: "hltracker.com", callback: { s in - print("ALL DONE") - }) + @StateObject var tracker = HotlineTracker(address: "hltracker.com") + @State private var selectedServer: HotlineServer? + + private var client: HotlineClient? var body: some View { - ScrollView { - VStack(alignment: .leading) { - ForEach(tracker.servers) { server in + List(selection: $selectedServer) { + ForEach(tracker.servers) { server in + HStack { + Text(server.name!).bold() + Spacer() HStack { - VStack(alignment: .leading) { - Text(server.name!).bold() - Image(systemName: "person.fill").opacity(0.3) - Text("\(server.users)").font(.system(size: 12)) - Text(server.description!).foregroundColor(.secondary).font(.system(size: 14)) - } - .padding(EdgeInsets(top: 15, leading: 18, bottom: 15, trailing: 18)) - Spacer() + Text("\(server.users)").font(.system(size: 12)).bold().opacity(0.3) + // Image(systemName: "person.fill").font(.system(size: 12)).opacity(0.3) } - .background(.white) - .cornerRadius(16) - .padding(EdgeInsets(top: 5, leading: 8, bottom: 5, trailing: 8)) - .frame(minWidth: 0, maxWidth: .infinity) + .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 +// } } - .padding() } - .background(Color(white: 0.9)) -// .toolbar { -// ToolbarItem(placement: .navigationBarTrailing) { -// EditButton() -// } -// ToolbarItem { -// Button(action: addItem) { -// Label("Add Item", systemImage: "plus") -// } -// } -// } + .listStyle(.plain) + .frame(maxWidth: .infinity) .task { tracker.fetch() } - } - - private func addItem() { - withAnimation { - let newItem = Item(timestamp: Date()) - modelContext.insert(newItem) - } - } - - private func deleteItems(offsets: IndexSet) { - withAnimation { - for index in offsets { - modelContext.delete(items[index]) + .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) + // .modelContainer(for: Item.self, inMemory: true) } |