From 06a2166415bca7e5fe32eac505859bdd690ab8e0 Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Tue, 5 Dec 2023 17:41:22 -0800 Subject: Some styling work. Files showing. Message board tweaks. --- Hotline/Hotline/HotlineClient.swift | 13 ++++++++++++- Hotline/Hotline/HotlineProtocol.swift | 2 +- Hotline/Views/ChatView.swift | 10 +++++----- Hotline/Views/FileListView.swift | 28 ++++++++++++++++------------ Hotline/Views/FilesView.swift | 27 +++++++++++++++++++++++++-- Hotline/Views/MessageBoardView.swift | 24 +++++++++++++++--------- Hotline/Views/ServerView.swift | 3 ++- Hotline/Views/UserListView.swift | 3 ++- 8 files changed, 78 insertions(+), 32 deletions(-) diff --git a/Hotline/Hotline/HotlineClient.swift b/Hotline/Hotline/HotlineClient.swift index d2e3954..aaf2168 100644 --- a/Hotline/Hotline/HotlineClient.swift +++ b/Hotline/Hotline/HotlineClient.swift @@ -48,6 +48,7 @@ class HotlineClient { var userList: [HotlineUser] = [] var chatMessages: [HotlineChat] = [] var messageBoard: String = "" + var messageBoardMessages: [String] = [] var fileList: [HotlineFile] = [] var userName: String = "bolt" @@ -401,10 +402,20 @@ class HotlineClient { print("\(self.userList)\n\n") } case .getMessages: - print("GOT MESSAGE BOARD") if let textField = transaction.getField(type: .data), let text = textField.getString() { + var messages: [String] = [] + let messageBoardRegex = /([\s\r\n]*[_\-]+[\s\r\n]+)/ + let matches = text.matches(of: messageBoardRegex) + var start = text.startIndex + for match in matches { + let range = match.range + messages.append(String(text[start.. String { +// let bcf = ByteCountFormatter() + FilesView.byteFormatter.allowedUnits = [.useAll] + FilesView.byteFormatter.countStyle = .file + return FilesView.byteFormatter.string(fromByteCount: Int64(fileSize)) + } + var body: some View { - List(hotline.fileList) { - FileListView(item: $0) + List(hotline.fileList, id: \.self, children: \.files) { tree in + HStack { + if tree.isFolder { + Image(systemName: "folder") + Text(tree.name).bold() + Spacer() + Text("\(tree.fileSize)").foregroundStyle(.gray) + } + else { + Image(systemName: "doc") + Text(tree.name).bold() + Spacer() + Text(formattedFileSize(tree.fileSize)).foregroundStyle(.gray) + } + } } + .listStyle(.plain) .task { if !fetched { hotline.sendGetFileList() { diff --git a/Hotline/Views/MessageBoardView.swift b/Hotline/Views/MessageBoardView.swift index e5f1521..8b1a30c 100644 --- a/Hotline/Views/MessageBoardView.swift +++ b/Hotline/Views/MessageBoardView.swift @@ -9,19 +9,25 @@ struct MessageBoardView: View { var body: some View { // @Bindable var config = appState - VStack(alignment: .leading) { - ScrollView { - VStack(alignment: .leading) { - Text(hotline.messageBoard) - .fontDesign(.monospaced) + ScrollView { + LazyVStack(alignment: .leading) { + ForEach(hotline.messageBoardMessages, id: \.self) { + Text($0) + .lineLimit(100) .padding() - .dynamicTypeSize(.small) - .textSelection(.enabled) + Divider() } } } - .presentationDetents([.fraction(0.6)]) - .presentationDragIndicator(.visible) +// List(hotline.messageBoardMessages, id: \.self) { +// Text($0) +// .lineLimit(100) +// .padding() +// Divider() +// .listRowSeparator(.hidden) +// .listRowInsets(EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0)) +// } +// .listStyle(.plain) .task { if !fetched { hotline.sendGetNews() { diff --git a/Hotline/Views/ServerView.swift b/Hotline/Views/ServerView.swift index 98fd515..ecb13a1 100644 --- a/Hotline/Views/ServerView.swift +++ b/Hotline/Views/ServerView.swift @@ -106,9 +106,10 @@ struct ServerView: View { .navigationTitle("Files") .navigationBarTitleDisplayMode(.inline) .tabItem { - Image(systemName: "folder") + Image(systemName: "folder").tint(.black) } } + .accentColor(.black) } // .sheet(isPresented: Binding(get: { hotline.connectionStatus != .loggedIn }, set: { _ in })) { diff --git a/Hotline/Views/UserListView.swift b/Hotline/Views/UserListView.swift index cbb029d..70b58b9 100644 --- a/Hotline/Views/UserListView.swift +++ b/Hotline/Views/UserListView.swift @@ -7,9 +7,10 @@ struct UserListView: View { VStack(spacing: 0) { List(hotline.userList) { u in HStack(alignment: .firstTextBaseline) { - Text(u.name).bold().foregroundStyle(u.isAdmin ? Color.red : Color.black) + Text(u.name).bold().foregroundStyle(u.isAdmin ? Color.red : Color.black).opacity(u.isIdle ? 0.5 : 1.0) } } + .listStyle(.plain) .padding() } } -- cgit