aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-04 09:12:58 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-04 09:12:58 -0800
commit471546236b8991f61d26c0e3aa8ee48b83b983af (patch)
treeb74331a8c8ea61ee7e1eaedfc7bbd1686bbc4702 /Hotline/Views
parent885119acdd27bd53ed3096285c3eca3e2d99ad70 (diff)
Starting to hash out a server view and tabs. Added research pdfs. etc.
Diffstat (limited to 'Hotline/Views')
-rw-r--r--Hotline/Views/AgreementView.swift35
-rw-r--r--Hotline/Views/ChatView.swift63
-rw-r--r--Hotline/Views/HotlineView.swift20
-rw-r--r--Hotline/Views/ServerView.swift62
-rw-r--r--Hotline/Views/TrackerServerView.swift47
-rw-r--r--Hotline/Views/TrackerView.swift73
6 files changed, 300 insertions, 0 deletions
diff --git a/Hotline/Views/AgreementView.swift b/Hotline/Views/AgreementView.swift
new file mode 100644
index 0000000..c61c9d7
--- /dev/null
+++ b/Hotline/Views/AgreementView.swift
@@ -0,0 +1,35 @@
+import SwiftUI
+
+struct AgreementView: View {
+ @Environment(\.dismiss) var dismiss
+
+ let text: String
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ ScrollView {
+ VStack(alignment: .leading) {
+ Text(text)
+ .fontDesign(.monospaced)
+ .padding()
+ .dynamicTypeSize(.small)
+ .textSelection(.enabled)
+ }
+ }
+ Button("OK") {
+ print("DONE")
+ }
+ .bold()
+ .padding(EdgeInsets(top: 16, leading: 24, bottom: 16, trailing: 24))
+ .frame(maxWidth: .infinity)
+ }
+ }
+}
+
+#Preview {
+ AgreementView(text: """
+Welcome!
+
+Take it on real one.
+""")
+}
diff --git a/Hotline/Views/ChatView.swift b/Hotline/Views/ChatView.swift
new file mode 100644
index 0000000..532a890
--- /dev/null
+++ b/Hotline/Views/ChatView.swift
@@ -0,0 +1,63 @@
+import SwiftUI
+
+struct ChatView: View {
+// @Binding private var input: String
+ @State var input: String = ""
+ @State private var scrollPos: Int?
+ @State private var contentHeight: CGFloat = 0
+
+ var body: some View {
+ VStack(spacing: 0) {
+ GeometryReader { geometry in
+ ScrollView(.vertical) {
+ ScrollViewReader { scrollReader in
+ VStack(alignment: .leading) {
+ Spacer()
+ LazyVStack(alignment: .leading, spacing: 10) {
+ HStack(alignment: .firstTextBaseline) {
+ Text("bolt:").bold().fontDesign(.monospaced).frame(minWidth: 60)
+ Text("hello!").fontDesign(.monospaced).textSelection(.enabled)
+ }
+ ForEach(0..<50) { i in
+ HStack(alignment: .firstTextBaseline) {
+ Text("mierau:").bold().fontDesign(.monospaced)
+ Text("g'day to you. what's going on this afternoon?")
+ .fontDesign(.monospaced)
+ .textSelection(.enabled)
+ }
+ }
+ Text("").font(.system(size: 0)).id("bottomScroll")
+ }
+ .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("This is a chat topic", text: $input, axis: .vertical)
+ .lineLimit(1...5)
+ .onSubmit {
+ // HotlineClient.shared.sendChat(message: self.input)
+ self.input = ""
+ }
+ }.padding()
+ }
+ }
+}
+
+#Preview {
+ ChatView()
+}
diff --git a/Hotline/Views/HotlineView.swift b/Hotline/Views/HotlineView.swift
new file mode 100644
index 0000000..67ef067
--- /dev/null
+++ b/Hotline/Views/HotlineView.swift
@@ -0,0 +1,20 @@
+import SwiftUI
+
+struct HotlineView: View {
+ @Environment(HotlineClient.self) private var hotline
+ @Environment(HotlineTrackerClient.self) private var tracker
+
+ @State private var isTrackerVisible = false
+
+ var body: some View {
+ NavigationStack {
+ TrackerView()
+ }
+ }
+}
+
+#Preview {
+ HotlineView()
+ .environment(HotlineClient())
+ .environment(HotlineTrackerClient(tracker: HotlineTracker("hltracker.com")))
+}
diff --git a/Hotline/Views/ServerView.swift b/Hotline/Views/ServerView.swift
new file mode 100644
index 0000000..1610aa7
--- /dev/null
+++ b/Hotline/Views/ServerView.swift
@@ -0,0 +1,62 @@
+import SwiftUI
+
+struct ServerView: View {
+ @Environment(HotlineClient.self) private var hotline
+ @Environment(HotlineTrackerClient.self) private var tracker
+
+ @State private var isTrackerVisible = false
+
+ var body: some View {
+ TabView {
+ NavigationView {
+ ChatView()
+ .navigationTitle("Badmoon")
+ .navigationBarItems(
+ leading: Button(action: {
+ withAnimation {
+ isTrackerVisible.toggle()
+ }
+ }) {
+ Image(systemName: "line.horizontal.3") // Hamburger icon or similar
+ .imageScale(.large)
+ }
+ )
+ .toolbarBackground(.visible, for: .navigationBar)
+ .toolbarBackground(.red, for: .navigationBar)
+ }
+ .navigationBarTitleDisplayMode(.inline)
+ .tabItem {
+ Image(systemName: "message")
+ }
+
+ Text("Users")
+ .tabItem {
+ Image(systemName: "person.fill")
+ }
+
+ Text("News")
+ .tabItem {
+ Image(systemName: "newspaper")
+ }
+
+ Text("Files")
+ .tabItem {
+ Image(systemName: "folder")
+ }
+
+ Text("Transfers")
+ .tabItem {
+ Image(systemName: "network")
+ }
+ }
+// .sheet(isPresented: Binding(get: { hotline.connectionStatus != .loggedIn }, set: { _ in })) {
+// TrackerView()
+// }
+ }
+}
+
+#Preview {
+ ServerView()
+ .environment(HotlineClient())
+ .environment(HotlineTrackerClient(tracker: HotlineTracker("hltracker.com")))
+}
diff --git a/Hotline/Views/TrackerServerView.swift b/Hotline/Views/TrackerServerView.swift
new file mode 100644
index 0000000..5be6f7a
--- /dev/null
+++ b/Hotline/Views/TrackerServerView.swift
@@ -0,0 +1,47 @@
+import SwiftUI
+
+struct TrackerServerView: View {
+ @Environment(\.dismiss) var dismiss
+
+ let server: HotlineServer
+
+ var body: some View {
+ VStack(alignment: .leading) {
+ HStack {
+ Text("🌎").dynamicTypeSize(.xxxLarge)
+ Text(server.name!).bold().dynamicTypeSize(.xxxLarge)
+ }
+ .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)).textSelection(.enabled)
+ Text(server.address).opacity(0.3).dynamicTypeSize(.medium).textSelection(.enabled)
+
+ Spacer()
+
+ HStack(alignment: .center) {
+ Button("Connect") {
+ print("WHAT", "HELLO", server.address)
+// HotlineClient.shared.connect(to: server)
+ dismiss()
+ }
+ .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)
+ }
+}
+
+#Preview {
+ TrackerServerView(server: HotlineServer(address: "192.168.1.1", port: 5050, users: 5, name: "Ye Olde Server", description: "This is a server"))
+}
diff --git a/Hotline/Views/TrackerView.swift b/Hotline/Views/TrackerView.swift
new file mode 100644
index 0000000..5d1afe2
--- /dev/null
+++ b/Hotline/Views/TrackerView.swift
@@ -0,0 +1,73 @@
+import SwiftUI
+
+struct TrackerView: View {
+
+ // @Environment(\.modelContext) private var modelContext
+ // @Query private var items: [Item]
+
+ @Environment(HotlineClient.self) private var hotline
+ @Environment(HotlineTrackerClient.self) private var tracker
+
+ // @StateObject var tracker = HotlineTrackerClient(address: "hltracker.com")
+ // @StateObject var client = HotlineClient.shared
+
+ @State private var selectedServer: HotlineServer?
+ @State private var showingAgreement = false
+ @State private var showingConnectSheet = false
+
+ // @Bindable var trackerTest = tracker
+
+ var body: some View {
+ List(selection: $selectedServer) {
+ ForEach(tracker.servers) { server in
+ HStack {
+ Text("🌎")
+ Text(server.name!).bold()
+ Spacer()
+ Text("\(server.users)").opacity(0.6)
+ }
+ .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)
+ }
+ }
+ .background(Color(white: 0.96))
+ .listStyle(.plain)
+ .frame(maxWidth: .infinity)
+ .task {
+ tracker.fetch()
+ }
+ .sheet(item: $selectedServer) { item in
+ TrackerServerView(server: item)
+ }
+ .sheet(isPresented: Binding(get: { hotline.agreement != nil }, set: { _ in })) {
+ AgreementView(text: hotline.agreement!)
+ }
+ .navigationTitle("Tracker")
+ .navigationBarTitleDisplayMode(.inline)
+ .toolbar {
+ ToolbarItem(placement: .topBarTrailing) {
+ Image(systemName: "gearshape.fill")
+ }
+ // ToolbarItem(placement: .topBarTrailing) {
+ // Image(systemName: "camera.fill")
+ // }
+ // ToolbarItem(placement: .principal) {
+ // Text("Username")
+ // }
+ }
+ .refreshable {
+ tracker.fetch()
+ }
+ .interactiveDismissDisabled()
+ }
+}
+
+#Preview {
+ TrackerView()
+ .environment(HotlineClient())
+ .environment(HotlineTrackerClient(tracker: HotlineTracker("hltracker.com")))
+ // .modelContainer(for: Item.self, inMemory: true)
+}