aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-05 15:57:27 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-05 15:57:27 -0800
commitb99219f16792be4a06a89f1f32a59f0bf97bba68 (patch)
tree4503d6f8b8c980c073c0e899da014bbffc4f7e94 /Hotline/Views
parentb1a176ba3da2c7cf815084f0f8109008fe763809 (diff)
Experimenting with files.
Diffstat (limited to 'Hotline/Views')
-rw-r--r--Hotline/Views/FileListView.swift22
-rw-r--r--Hotline/Views/FilesView.swift11
-rw-r--r--Hotline/Views/HotlineView.swift7
-rw-r--r--Hotline/Views/ServerView.swift155
-rw-r--r--Hotline/Views/TrackerServerView.swift100
-rw-r--r--Hotline/Views/TrackerView.swift86
6 files changed, 253 insertions, 128 deletions
diff --git a/Hotline/Views/FileListView.swift b/Hotline/Views/FileListView.swift
new file mode 100644
index 0000000..852fce4
--- /dev/null
+++ b/Hotline/Views/FileListView.swift
@@ -0,0 +1,22 @@
+import SwiftUI
+
+struct FileListView: View {
+ var item: HotlineFile
+
+ var body: some View {
+ List {
+ ForEach(item.files) { f in
+ if f.isFolder {
+ DisclosureGroup(f.name, isExpanded: false)
+ }
+ else {
+ Text("HELLO")
+ }
+ }
+ }
+ }
+}
+
+#Preview {
+ FileListView(item: HotlineFile(type: "fldr", creator: "", fileSize: 0, fileName: "Folder"))
+}
diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift
index 0e1bb91..d910af2 100644
--- a/Hotline/Views/FilesView.swift
+++ b/Hotline/Views/FilesView.swift
@@ -6,15 +6,8 @@ struct FilesView: View {
@State private var fetched = false
var body: some View {
- ScrollView {
- VStack(spacing: 0) {
- List(hotline.userList) { u in
- HStack(alignment: .firstTextBaseline) {
- Text(u.name).bold().foregroundStyle(u.isAdmin ? Color.red : Color.black)
- }
- }
- .padding()
- }
+ List(hotline.fileList) {
+ FileListView(item: $0)
}
.task {
if !fetched {
diff --git a/Hotline/Views/HotlineView.swift b/Hotline/Views/HotlineView.swift
index fe67f79..713691f 100644
--- a/Hotline/Views/HotlineView.swift
+++ b/Hotline/Views/HotlineView.swift
@@ -5,20 +5,15 @@ struct HotlineView: View {
@Environment(HotlineClient.self) private var hotline
@Environment(HotlineTrackerClient.self) private var tracker
- @State private var isTrackerVisible = true
-
var body: some View {
@Bindable var config = appState
NavigationStack {
- ServerView()
+ TrackerView()
}
.sheet(isPresented: $config.agreementPresented) {
AgreementView(text: hotline.agreement!)
}
- .sheet(isPresented: $config.trackerPresented) {
- TrackerView()
- }
}
}
diff --git a/Hotline/Views/ServerView.swift b/Hotline/Views/ServerView.swift
index 0dafbce..98fd515 100644
--- a/Hotline/Views/ServerView.swift
+++ b/Hotline/Views/ServerView.swift
@@ -4,70 +4,123 @@ struct ServerView: View {
@Environment(HotlineState.self) private var appState
@Environment(HotlineClient.self) private var hotline
@Environment(HotlineTrackerClient.self) private var tracker
-
+
+ let server: HotlineServer
+
+ func connectionStatusTitle(status: HotlineClientStatus) -> String {
+ switch(status) {
+ case .disconnected:
+ return "Disconnected"
+ case .connecting:
+ return "Connecting"
+ case .connected:
+ return "Connected"
+ case .loggingIn:
+ return "Logging In"
+ case .loggedIn:
+ return "Logged In"
+ }
+ }
+
+ func connectionProgress(status: HotlineClientStatus) -> Double {
+ return Double(status.rawValue) / Double(HotlineClientStatus.loggedIn.rawValue)
+ }
+
var body: some View {
@Bindable var config = appState
- TabView {
- NavigationView {
- ChatView()
- .navigationTitle(hotline.server?.name ?? "Hotline")
- .navigationBarTitleDisplayMode(.inline)
- .navigationBarItems(
- leading: Button(action: {
- appState.presentTracker()
- }) {
- Image(systemName: "globe.americas.fill") // Hamburger icon or similar
- .imageScale(.large)
+ NavigationStack {
+ if hotline.connectionStatus != .loggedIn {
+ VStack {
+ Spacer()
+ VStack(alignment: .center) {
+ Text("🌎").font(.largeTitle)
+ Text(server.name!).font(.title3).fontWeight(.medium)
+ Text(server.description!).opacity(0.6).font(.title3)
+ Text(server.address).opacity(0.6).font(.title3)
+ }
+ Spacer()
+ HStack(alignment: .center) {
+ if hotline.connectionStatus == .disconnected {
+ ProgressView(connectionStatusTitle(status: hotline.connectionStatus), value: connectionProgress(status: hotline.connectionStatus))
+ Button("Connect") {
+ hotline.connect(to: server)
+ // config.dismissTracker()
+ }
+ .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)
}
- )
-// .toolbarBackground(.visible, for: .navigationBar)
-// .toolbarBackground(.red, for: .navigationBar)
- }
- .tabItem {
- Image(systemName: "message")
- }
-
- NavigationView {
- UserListView()
- .navigationTitle("User List")
- .navigationBarTitleDisplayMode(.inline)
- }
- .tabItem {
- Image(systemName: "person.fill")
- }
-
- Text("News")
- .tabItem {
- Image(systemName: "newspaper")
+ else {
+ ProgressView("", value: Double(hotline.connectionStatus.rawValue / HotlineClientStatus.loggedIn.rawValue))
+ }
+ }
}
-
- NavigationView {
- MessageBoardView()
- .navigationTitle("Message Board")
- .navigationBarTitleDisplayMode(.inline)
+ .padding()
}
- .tabItem {
- Image(systemName: "pin")
+ else {
+ TabView {
+ ChatView()
+ .navigationTitle(hotline.server?.name ?? "Hotline")
+ .navigationBarTitleDisplayMode(.inline)
+ .navigationBarItems(
+ leading: Button(action: {
+ appState.presentTracker()
+ }) {
+ Image(systemName: "globe.americas.fill") // Hamburger icon or similar
+ .imageScale(.large)
+ }
+ )
+ // .toolbarBackground(.visible, for: .navigationBar)
+ // .toolbarBackground(.red, for: .navigationBar)
+ .tabItem {
+ Image(systemName: "message")
+ }
+
+ UserListView()
+ .navigationTitle("User List")
+ .navigationBarTitleDisplayMode(.inline)
+ .tabItem {
+ Image(systemName: "person.fill")
+ }
+
+ Text("News")
+ .tabItem {
+ Image(systemName: "newspaper")
+ }
+
+ MessageBoardView()
+ .navigationTitle("Message Board")
+ .navigationBarTitleDisplayMode(.inline)
+ .tabItem {
+ Image(systemName: "pin")
+ }
+
+ FilesView()
+ .navigationTitle("Files")
+ .navigationBarTitleDisplayMode(.inline)
+ .tabItem {
+ Image(systemName: "folder")
+ }
+ }
}
- NavigationView {
- FilesView()
- .navigationTitle("Files")
- .navigationBarTitleDisplayMode(.inline)
- }
- .tabItem {
- Image(systemName: "folder")
- }
+ // .sheet(isPresented: Binding(get: { hotline.connectionStatus != .loggedIn }, set: { _ in })) {
+ // TrackerView()
+ // }
}
-// .sheet(isPresented: Binding(get: { hotline.connectionStatus != .loggedIn }, set: { _ in })) {
-// TrackerView()
-// }
}
}
#Preview {
- ServerView()
+ ServerView(server: HotlineServer(address: "192.168.1.1", port: 5050, users: 5, name: "Ye Olde Server", description: "This is a server"))
.environment(HotlineClient())
.environment(HotlineTrackerClient(tracker: HotlineTracker("hltracker.com")))
+ .environment(HotlineState())
}
diff --git a/Hotline/Views/TrackerServerView.swift b/Hotline/Views/TrackerServerView.swift
index 2c0f3e3..5288496 100644
--- a/Hotline/Views/TrackerServerView.swift
+++ b/Hotline/Views/TrackerServerView.swift
@@ -3,50 +3,92 @@ import SwiftUI
struct TrackerServerView: View {
@Environment(HotlineState.self) private var appState
@Environment(HotlineClient.self) private var hotline
- @Environment(\.dismiss) private var dismiss
let server: HotlineServer
+ @State private var expanded = false
+
+ func shouldDisplayDescription(server: HotlineServer) -> Bool {
+ guard let name = server.name, let desc = server.description else {
+ return false
+ }
+
+ return desc.count > 0 && desc != name && !desc.contains(/^-+/)
+ }
+
var body: some View {
@Bindable var config = appState
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") {
- hotline.connect(to: server)
- config.dismissTracker()
-// dismiss()
+ HStack(alignment: .firstTextBaseline) {
+ Text("🌎").font(.title3)
+ VStack(alignment: .leading) {
+ Text(server.name!).font(.title3).fontWeight(.medium)
+ if shouldDisplayDescription(server: server) {
+ Text(server.description!).opacity(0.6).font(.title3)
+ }
}
- .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()
+ .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
+ .listRowSeparator(.hidden)
+ .listRowBackground(Color(white: 0.96))
+
+ // .padding(EdgeInsets(top: 0, leading: 0, bottom: 8.0, trailing: 0))
+// ProgressView(value: 0.5)
+//
+// HStack(alignment: .center) {
+// Button("Connect") {
+// hotline.connect(to: server)
+// config.dismissTracker()
+// // 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))
+// label: {
+// HStack(alignment: .firstTextBaseline) {
+// Text("🌎").font(.title3)
+// VStack(alignment: .leading) {
+// Text(server.name!).font(.title3).fontWeight(.medium)
+// if shouldDisplayDescription(server: server) {
+// Spacer()
+// Text(server.description!).opacity(0.6).font(.title3)
+// }
+// }
+// }
+// .padding()
+// .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0))
+// .listRowSeparator(.hidden)
+// .listRowBackground(Color(white: 0.96))
+// }
+ .popover(isPresented: $expanded) {
+ Text("Popover Content")
+ .padding()
+ }
+ .background(Color(white: 0.96))
+ .padding(EdgeInsets(top: 8.0, leading: 24.0, bottom: 8.0, trailing: 24.0))
.presentationDetents([.fraction(0.4)])
- .presentationDragIndicator(.automatic)
+ .presentationDragIndicator(.visible)
+ .onTapGesture {
+ expanded = true
+// withAnimation {
+// expanded.toggle()
+// }
+ }
}
}
#Preview {
TrackerServerView(server: HotlineServer(address: "192.168.1.1", port: 5050, users: 5, name: "Ye Olde Server", description: "This is a server"))
.environment(HotlineClient())
+ .environment(HotlineState())
}
diff --git a/Hotline/Views/TrackerView.swift b/Hotline/Views/TrackerView.swift
index edb2330..83a4ebf 100644
--- a/Hotline/Views/TrackerView.swift
+++ b/Hotline/Views/TrackerView.swift
@@ -11,48 +11,67 @@ struct TrackerView: View {
@State private var selectedServer: HotlineServer?
+ func shouldDisplayDescription(server: HotlineServer) -> Bool {
+ guard let name = server.name, let desc = server.description else {
+ return false
+ }
+
+ return desc.count > 0 && desc != name && !desc.contains(/^-+/)
+ }
+
var body: some View {
@Bindable var config = appState
- NavigationView {
- List(selection: $selectedServer) {
- ForEach(tracker.servers) { server in
- TrackerServerView(server: server)
+ List(selection: $selectedServer) {
+ ForEach(tracker.servers) { server in
+ NavigationLink {
+ ServerView(server: server)
+ } label: {
+ HStack(alignment: .firstTextBaseline) {
+ Text("🌎").font(.title3)
+ VStack(alignment: .leading) {
+ Text(server.name!).font(.title3).fontWeight(.medium)
+ if shouldDisplayDescription(server: server) {
+ Text(server.description!).opacity(0.6).font(.title3)
+ }
+ }
+ }
}
}
- .background(Color(white: 0.96))
- .listStyle(.plain)
- .frame(maxWidth: .infinity)
- .task {
- tracker.fetch()
- }
-// .sheet(item: $selectedServer) { item in
-// TrackerServerView(server: item)
-// }
- .refreshable {
- tracker.fetch()
+ }
+ .background(Color.white)
+ .listStyle(.plain)
+ .listRowSpacing(1)
+ .frame(maxWidth: .infinity)
+ .task {
+ tracker.fetch()
+ }
+ // .sheet(item: $selectedServer) { item in
+ //// Text("HELLO")
+ // TrackerServerView(server: item)
+ // }
+ .refreshable {
+ await withCheckedContinuation { continuation in
+ tracker.fetch() {
+ continuation.resume()
+ }
}
- .navigationTitle("Tracker")
- .navigationBarTitleDisplayMode(.inline)
- .toolbar {
- ToolbarItem(placement: .topBarTrailing) {
- Button {
- config.dismissTracker()
- } label: {
- Image(systemName: "xmark.circle.fill")
- .symbolRenderingMode(.hierarchical)
- .foregroundColor(.gray)
- }
+ }
+ .navigationTitle("Tracker")
+ .navigationBarTitleDisplayMode(.inline)
+ .toolbar {
+ ToolbarItem(placement: .topBarTrailing) {
+ Button {
+ config.dismissTracker()
+ } label: {
+ Image(systemName: "xmark.circle.fill")
+ .symbolRenderingMode(.hierarchical)
+ .foregroundColor(.gray)
}
- // ToolbarItem(placement: .topBarTrailing) {
- // Image(systemName: "camera.fill")
- // }
- // ToolbarItem(placement: .principal) {
- // Text("Username")
- // }
}
}
-// .interactiveDismissDisabled()
+
+ // .interactiveDismissDisabled()
}
}
@@ -60,5 +79,6 @@ struct TrackerView: View {
TrackerView()
.environment(HotlineClient())
.environment(HotlineTrackerClient(tracker: HotlineTracker("hltracker.com")))
+ .environment(HotlineState())
// .modelContainer(for: Item.self, inMemory: true)
}