diff options
| author | Dustin Mierau <dustin@mierau.me> | 2023-12-05 17:41:22 -0800 |
|---|---|---|
| committer | Dustin Mierau <dustin@mierau.me> | 2023-12-05 17:41:22 -0800 |
| commit | 06a2166415bca7e5fe32eac505859bdd690ab8e0 (patch) | |
| tree | d47d4ea30766a8e382deafa607a7abe66f47f9ab | |
| parent | b99219f16792be4a06a89f1f32a59f0bf97bba68 (diff) | |
Some styling work. Files showing. Message board tweaks.
| -rw-r--r-- | Hotline/Hotline/HotlineClient.swift | 13 | ||||
| -rw-r--r-- | Hotline/Hotline/HotlineProtocol.swift | 2 | ||||
| -rw-r--r-- | Hotline/Views/ChatView.swift | 10 | ||||
| -rw-r--r-- | Hotline/Views/FileListView.swift | 28 | ||||
| -rw-r--r-- | Hotline/Views/FilesView.swift | 27 | ||||
| -rw-r--r-- | Hotline/Views/MessageBoardView.swift | 24 | ||||
| -rw-r--r-- | Hotline/Views/ServerView.swift | 3 | ||||
| -rw-r--r-- | 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..<range.lowerBound])) + start = range.upperBound + } + DispatchQueue.main.async { self.messageBoard = text + self.messageBoardMessages = messages } } case .getFileNameList: diff --git a/Hotline/Hotline/HotlineProtocol.swift b/Hotline/Hotline/HotlineProtocol.swift index 3eb4a7d..a7392ec 100644 --- a/Hotline/Hotline/HotlineProtocol.swift +++ b/Hotline/Hotline/HotlineProtocol.swift @@ -37,7 +37,7 @@ struct HotlineFile: Identifiable, Hashable { let name: String var isExpanded: Bool = false - var files: [HotlineFile] = [] + var files: [HotlineFile]? = nil let isFolder: Bool diff --git a/Hotline/Views/ChatView.swift b/Hotline/Views/ChatView.swift index 6dc7318..e28e076 100644 --- a/Hotline/Views/ChatView.swift +++ b/Hotline/Views/ChatView.swift @@ -10,18 +10,18 @@ struct ChatView: View { var body: some View { VStack(spacing: 0) { List(hotline.chatMessages) { msg in - if msg.username == "" { - - } HStack(alignment: .firstTextBaseline) { - Text("\(msg.username):").bold().fontDesign(.monospaced).font(.system(size: 12)) + if !msg.username.isEmpty { + Text("\(msg.username):").bold().fontDesign(.monospaced).font(.system(size: 12)) + } Text(msg.message) .fontDesign(.monospaced) .textSelection(.enabled) .font(.system(size: 12)) } + .listRowSeparator(.hidden) } - .padding() + .listStyle(.plain) // GeometryReader { geometry in // ScrollView(.vertical) { diff --git a/Hotline/Views/FileListView.swift b/Hotline/Views/FileListView.swift index 852fce4..a315757 100644 --- a/Hotline/Views/FileListView.swift +++ b/Hotline/Views/FileListView.swift @@ -1,22 +1,26 @@ import SwiftUI struct FileListView: View { - var item: HotlineFile + @State var files: [HotlineFile] var body: some View { - List { - ForEach(item.files) { f in - if f.isFolder { - DisclosureGroup(f.name, isExpanded: false) - } - else { - Text("HELLO") - } - } - } + Text("HI") +// @Bindable var fls = files +// List { +// ForEach($fls, id: \.self) { f in +// if f.isFolder { +// DisclosureGroup(f.name, isExpanded: false) +// } +// else { +// Text("HELLO") +// } +// } +// } } } #Preview { - FileListView(item: HotlineFile(type: "fldr", creator: "", fileSize: 0, fileName: "Folder")) + FileListView(files: [ + HotlineFile(type: "fldr", creator: "", fileSize: 0, fileName: "Folder") + ]) } diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift index d910af2..7bacbce 100644 --- a/Hotline/Views/FilesView.swift +++ b/Hotline/Views/FilesView.swift @@ -5,10 +5,33 @@ struct FilesView: View { @State private var fetched = false + static let byteFormatter = ByteCountFormatter() + + private func formattedFileSize(_ fileSize: UInt32) -> 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() } } |