diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-11-30 23:46:57 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-11-30 23:46:57 -0800 |
| commit | 885119acdd27bd53ed3096285c3eca3e2d99ad70 (patch) | |
| tree | 7dce98c071859684ff2aaa157f090b7cdc941a04 /Hotline/TrackerView.swift | |
| parent | 30255476781789df318a571622ab732681696139 (diff) | |
Bunch of work to and now login, user list, handling replies, etc. works. Or at least the framework is there for them to work.
Diffstat (limited to 'Hotline/TrackerView.swift')
| -rw-r--r-- | Hotline/TrackerView.swift | 150 |
1 files changed, 67 insertions, 83 deletions
diff --git a/Hotline/TrackerView.swift b/Hotline/TrackerView.swift index 0bc9762..1b5cce5 100644 --- a/Hotline/TrackerView.swift +++ b/Hotline/TrackerView.swift @@ -1,112 +1,96 @@ import SwiftUI import SwiftData +struct AgreementView: View { + @Environment(\.dismiss) var dismiss + + let text: String + + var body: some View { + Text(text) + } +} + +struct TrackerServerView: View { + @Environment(\.dismiss) var dismiss + + let server: HotlineServer + + var body: some View { + VStack(alignment: .leading) { + HStack { + Text("🌎") + Text(server.name!).bold().dynamicTypeSize(.xxLarge) + } + .padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0)) + Text(server.description!).opacity(0.6).dynamicTypeSize(.xLarge).padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0)) + Text(server.address).opacity(0.3).dynamicTypeSize(.medium) + Spacer() + HStack(alignment: .center) { + Button("Connect") { + print("WHAT", "HELLO", server.address) + HotlineClient.shared.connect(to: server) + dismiss() +// client = HotlineClient(server: selectedServer) + } + .bold() + .padding(EdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24)) + .frame(maxWidth: .infinity) + .foregroundColor(.black) + .background(LinearGradient(gradient: Gradient(colors: [Color(white: 0.95), Color(white: 0.91)]), startPoint: .top, endPoint: .bottom)) + . + overlay( + RoundedRectangle(cornerRadius: 10.0).stroke(.black, lineWidth: 3).opacity(0.4) + ) + .cornerRadius(10.0) + } + } + .padding(EdgeInsets(top: 28.0, leading: 24.0, bottom: 24.0, trailing: 24.0)) + .presentationDetents([.fraction(0.4)]) + .presentationDragIndicator(.automatic) + } +} + 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? + @StateObject var client = HotlineClient.shared + @State private var selectedServer: HotlineServer? + @State private var showingAgreement = false + @State private var showingConnectSheet = false + var body: some View { List(selection: $selectedServer) { ForEach(tracker.servers) { server in HStack { + Text("🌎") 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) + Text("\(server.users)").opacity(0.6) } -// .contentShape(Rectangle()) - .listRowSeparator(.hidden) + .listRowBackground(Color(white: 0.96)) + .listRowInsets(EdgeInsets(top: 0, leading: 16.0, bottom: 0, trailing: 16.0)) + .listRowSeparator(.visible, edges: VerticalEdge.Set.all) + .listRowSeparatorTint(Color(white: 1.0)) .tag(server) - // .padding(EdgeInsets(top: 4, leading: 8, bottom: 4, trailing: 0)) -// .onTapGesture { -// self.selectedServer = server -// } } } + .background(Color(white: 0.96)) .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) + TrackerServerView(server: item) + } + .sheet(isPresented: Binding(get: { client.agreement != nil }, set: { _ in })) { + AgreementView(text: client.agreement!) } -// 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) -// } } } |