diff options
Diffstat (limited to 'Hotline/Views')
| -rw-r--r-- | Hotline/Views/ChatView.swift | 3 | ||||
| -rw-r--r-- | Hotline/Views/FilesView.swift | 4 | ||||
| -rw-r--r-- | Hotline/Views/MessageBoardView.swift | 29 | ||||
| -rw-r--r-- | Hotline/Views/NewsView.swift | 53 | ||||
| -rw-r--r-- | Hotline/Views/TrackerView.swift | 34 | ||||
| -rw-r--r-- | Hotline/Views/UsersView.swift | 2 |
6 files changed, 67 insertions, 58 deletions
diff --git a/Hotline/Views/ChatView.swift b/Hotline/Views/ChatView.swift index ce3942e..60951c3 100644 --- a/Hotline/Views/ChatView.swift +++ b/Hotline/Views/ChatView.swift @@ -7,7 +7,6 @@ extension View { } struct ChatView: View { -// @Environment(HotlineClient.self) private var hotline @Environment(Hotline.self) private var model: Hotline @Environment(\.colorScheme) var colorScheme @@ -180,5 +179,5 @@ struct ChatView: View { #Preview { ChatView() - .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineNewClient())) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift index 11db93c..23b19b1 100644 --- a/Hotline/Views/FilesView.swift +++ b/Hotline/Views/FilesView.swift @@ -2,7 +2,6 @@ import SwiftUI import UniformTypeIdentifiers struct FileView: View { -// @Environment(HotlineClient.self) private var hotline @Environment(Hotline.self) private var model: Hotline @State var expanded = false @@ -84,7 +83,6 @@ struct FileView: View { } struct FilesView: View { -// @Environment(HotlineClient.self) private var hotline @Environment(Hotline.self) private var model: Hotline @State var initialLoad = false @@ -125,5 +123,5 @@ struct FilesView: View { #Preview { FilesView() - .environment(HotlineClient()) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } diff --git a/Hotline/Views/MessageBoardView.swift b/Hotline/Views/MessageBoardView.swift index 473162e..8a1c831 100644 --- a/Hotline/Views/MessageBoardView.swift +++ b/Hotline/Views/MessageBoardView.swift @@ -2,13 +2,11 @@ import SwiftUI struct MessageBoardView: View { @Environment(Hotline.self) private var model: Hotline -// @Environment(HotlineState.self) private var appState -// @Environment(HotlineClient.self) private var hotline + @State private var initialLoadComplete = false @State private var fetched = false var body: some View { -// @Bindable var config = appState NavigationStack { ScrollView { LazyVStack(alignment: .leading) { @@ -23,16 +21,23 @@ struct MessageBoardView: View { Spacer() } .task { - if !fetched { + if !initialLoadComplete { let _ = await model.getMessageBoard() -// hotline.sendGetMessageBoard() { - fetched = true -// } + initialLoadComplete = true + } + } + .overlay { + if !initialLoadComplete { + VStack { + ProgressView() + .controlSize(.large) + } + .frame(maxWidth: .infinity) } } .refreshable { let _ = await model.getMessageBoard() -// hotline.sendGetMessageBoard() + initialLoadComplete = true } .navigationBarTitleDisplayMode(.inline) .toolbar { @@ -43,7 +48,6 @@ struct MessageBoardView: View { ToolbarItem(placement: .navigationBarLeading) { Button { model.disconnect() -// hotline.disconnect() } label: { Text(Image(systemName: "xmark.circle.fill")) .symbolRenderingMode(.hierarchical) @@ -56,10 +60,7 @@ struct MessageBoardView: View { } label: { Image(systemName: "square.and.pencil") -// .symbolRenderingMode(.hierarchical) -// .foregroundColor(.secondary) } - } } } @@ -69,7 +70,5 @@ struct MessageBoardView: View { #Preview { MessageBoardView() - .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineNewClient())) -// .environment(HotlineState()) -// .environment(HotlineClient()) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } diff --git a/Hotline/Views/NewsView.swift b/Hotline/Views/NewsView.swift index 539ead8..431b3ce 100644 --- a/Hotline/Views/NewsView.swift +++ b/Hotline/Views/NewsView.swift @@ -1,12 +1,11 @@ import SwiftUI struct NewsView: View { - @Environment(HotlineState.self) private var appState - @Environment(HotlineClient.self) private var hotline + @Environment(Hotline.self) private var model: Hotline @Environment(\.colorScheme) var colorScheme @State private var fetched = false - @State private var selectedCategory: HotlineNewsCategory? = nil + @State private var selectedCategory: NewsCategory? = nil @State private var topListHeight: CGFloat = 200 @State private var dividerHeight: CGFloat = 30 @@ -14,17 +13,17 @@ struct NewsView: View { // Your list content goes here List { - ForEach(hotline.newsCategories, id: \.self) { cat in + ForEach(model.news, id: \.self) { category in DisclosureGroup { ProgressView(value: 0.4) .task { - print("EXPANDED?", cat.name) - hotline.sendGetNewsArticles(path: [cat.name]) { - print("OK") - } + print("EXPANDED?", category.name) +// hotline.sendGetNewsArticles(path: [cat.name]) { +// print("OK") +// } } } label: { - Text(cat.name) + Text(category.name) .fontWeight(.medium) .lineLimit(1) .truncationMode(.tail) @@ -60,13 +59,8 @@ struct NewsView: View { .fill(.tertiary) .frame(width: 50, height: 6, alignment: .center) .cornerRadius(10) -// .opacity(0.3) -// Image(systemName: "line.3.horizontal") -// .opacity(0.2) -// .font(.system(size: 14)) } Spacer() -// Divider() } .background(colorScheme == .dark ? Color(white: 0.1) : Color(uiColor: UIColor.systemBackground)) .frame(maxWidth: .infinity) @@ -83,9 +77,8 @@ struct NewsView: View { } .task { if !fetched { - hotline.sendGetNewsCategories() { - fetched = true - } + let _ = await model.getNewsCategories() + fetched = true // hotline.sendGetNewsArticles(path: ["News"]) { // print("GOT ARTICLES?") @@ -98,12 +91,12 @@ struct NewsView: View { .navigationBarTitleDisplayMode(.inline) .toolbar { ToolbarItem(placement: .principal) { - Text(hotline.server?.name ?? "") + Text(model.server?.name ?? "") .font(.headline) } ToolbarItem(placement: .navigationBarLeading) { Button { - hotline.disconnect() + model.disconnect() } label: { Text(Image(systemName: "xmark.circle.fill")) .symbolRenderingMode(.hierarchical) @@ -111,16 +104,16 @@ struct NewsView: View { .foregroundColor(.secondary) } } - ToolbarItem(placement: .navigationBarTrailing) { - Button { - - } label: { - Image(systemName: "square.and.pencil") - // .symbolRenderingMode(.hierarchical) - // .foregroundColor(.secondary) - } - - } +// ToolbarItem(placement: .navigationBarTrailing) { +// Button { +// +// } label: { +// Image(systemName: "square.and.pencil") +// // .symbolRenderingMode(.hierarchical) +// // .foregroundColor(.secondary) +// } +// +// } } } @@ -130,5 +123,5 @@ struct NewsView: View { #Preview { MessageBoardView() .environment(HotlineState()) - .environment(HotlineClient()) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } diff --git a/Hotline/Views/TrackerView.swift b/Hotline/Views/TrackerView.swift index 2fc27c7..01f4311 100644 --- a/Hotline/Views/TrackerView.swift +++ b/Hotline/Views/TrackerView.swift @@ -11,7 +11,7 @@ struct TrackerConnectView: View { @State private var password = "" @State private var connecting = false - func connectionStatusToProgress(status: HotlineNewClientStatus) -> Double { + func connectionStatusToProgress(status: HotlineClientStatus) -> Double { switch status { case .disconnected: return 0.0 @@ -26,8 +26,6 @@ struct TrackerConnectView: View { } } - - var body: some View { VStack(alignment: .leading) { if !connecting { @@ -176,7 +174,7 @@ struct TrackerView: View { return desc.count > 0 && desc != server.name } - func connectionStatusToProgress(status: HotlineNewClientStatus) -> Double { + func connectionStatusToProgress(status: HotlineClientStatus) -> Double { switch status { case .disconnected: return 0.0 @@ -196,7 +194,12 @@ struct TrackerView: View { } func updateServers() async { - self.servers = await model.getServers(address: "tracker.preterhuman.net") +// "hltracker.com" +// "tracker.preterhuman.net" +// "hotline.ubersoft.org" +// "tracked.nailbat.com" +// "hotline.duckdns.org" + self.servers = await model.getServers(address: "tracked.agent79.org") } var body: some View { @@ -347,11 +350,28 @@ struct TrackerView: View { await updateServers() initialLoadComplete = true } + .onOpenURL(perform: { url in + guard url.scheme == "hotline" else { + return + } + + if let address = url.host() { + let login = url.user(percentEncoded: false) ?? "" + let password = url.password(percentEncoded: false) ?? "" + let port = url.port ?? Server.defaultPort + + Task { + model.disconnect() + let _ = await model.login(server: Server(name: address, description: nil, address: address, port: port, users: 0), login: login, password: password, username: "bolt", iconID: 128) + } + + // TODO: Find a better way to show login status when trying to connect outside of the Tracker server list. Perhaps this opens the connect sheet prefilled. + } + }) } } #Preview { TrackerView() - .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineNewClient())) - // .modelContainer(for: Item.self, inMemory: true) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } diff --git a/Hotline/Views/UsersView.swift b/Hotline/Views/UsersView.swift index 0397ef7..ad43131 100644 --- a/Hotline/Views/UsersView.swift +++ b/Hotline/Views/UsersView.swift @@ -37,5 +37,5 @@ struct UsersView: View { #Preview { ChatView() - .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineNewClient())) + .environment(Hotline(trackerClient: HotlineTrackerClient(), client: HotlineClient())) } |