aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Models
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-19 20:38:13 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-19 20:38:13 -0800
commit4fd69c02a3e7b581bb9229865336c315153f3b18 (patch)
treee6e11d872424196f2b4033077902126ad5556e40 /Hotline/Models
parent5e87b5927cd931d46fb5f72fb035480a95969a9f (diff)
Beginnings of a UI for macOS as well as some visual changes to iOS client. :)
Diffstat (limited to 'Hotline/Models')
-rw-r--r--Hotline/Models/FileInfo.swift10
-rw-r--r--Hotline/Models/Hotline.swift113
-rw-r--r--Hotline/Models/NewsInfo.swift5
-rw-r--r--Hotline/Models/Server.swift13
-rw-r--r--Hotline/Models/User.swift2
5 files changed, 83 insertions, 60 deletions
diff --git a/Hotline/Models/FileInfo.swift b/Hotline/Models/FileInfo.swift
index 0e2c76d..5976b8f 100644
--- a/Hotline/Models/FileInfo.swift
+++ b/Hotline/Models/FileInfo.swift
@@ -1,7 +1,7 @@
import SwiftUI
-@Observable class FileInfo: Identifiable {
- let id: UUID = UUID()
+@Observable class FileInfo: Identifiable, Hashable {
+ let id: UUID
let path: [String]
let name: String
@@ -11,9 +11,11 @@ import SwiftUI
let fileSize: UInt
let isFolder: Bool
+ var expanded: Bool = false
var children: [FileInfo]? = nil
init(hotlineFile: HotlineFile) {
+ self.id = UUID()
self.path = hotlineFile.path
self.name = hotlineFile.name
self.type = hotlineFile.type
@@ -28,4 +30,8 @@ import SwiftUI
static func == (lhs: FileInfo, rhs: FileInfo) -> Bool {
return lhs.id == rhs.id
}
+
+ func hash(into hasher: inout Hasher) {
+ hasher.combine(self.id)
+ }
}
diff --git a/Hotline/Models/Hotline.swift b/Hotline/Models/Hotline.swift
index c7474b2..f9ae41d 100644
--- a/Hotline/Models/Hotline.swift
+++ b/Hotline/Models/Hotline.swift
@@ -29,8 +29,11 @@ import SwiftUI
var users: [User] = []
var chat: [ChatMessage] = []
var messageBoard: [String] = []
+ var messageBoardLoaded: Bool = false
var files: [FileInfo] = []
+ var filesLoaded: Bool = false
var news: [NewsInfo] = []
+ var newsLoaded: Bool = false
// MARK: -
@@ -92,6 +95,8 @@ import SwiftUI
}
}
+ self.messageBoardLoaded = true
+
return self.messageBoard
}
@@ -110,14 +115,18 @@ import SwiftUI
newFiles.append(FileInfo(hotlineFile: f))
}
- if let parent = parentFile {
- parent.children = newFiles
- }
- else if path.isEmpty {
- self?.files = newFiles
+ DispatchQueue.main.async {
+ if let parent = parentFile {
+ parent.children = newFiles
+ }
+ else if path.isEmpty {
+ self?.filesLoaded = true
+
+ self?.files = newFiles
+ }
+
+ continuation.resume(returning: newFiles)
}
-
- continuation.resume(returning: newFiles)
})
}
}
@@ -180,20 +189,25 @@ import SwiftUI
newCategories.append(NewsInfo(hotlineNewsCategory: category))
}
- if let parent = existingNewsItem {
- parent.children = newCategories
- }
- else if path.isEmpty {
- self?.news = newCategories
+ DispatchQueue.main.async {
+ if let parent = existingNewsItem {
+ parent.children = newCategories
+ }
+ else if path.isEmpty {
+ self?.newsLoaded = true
+ self?.news = newCategories
+ }
+
+ continuation.resume(returning: newCategories)
}
-
- continuation.resume(returning: newCategories)
})
}
else {
self?.client.sendGetNewsArticles(path: path, sent: { success in
if !success {
- continuation.resume(returning: [])
+ DispatchQueue.main.async {
+ continuation.resume(returning: [])
+ }
return
}
@@ -207,17 +221,19 @@ import SwiftUI
newArticles.append(NewsInfo(hotlineNewsArticle: article))
}
- if let parent = existingNewsItem {
- print("UNDER PARENT:", parent.name)
- parent.children = newArticles
+ DispatchQueue.main.async {
+ if let parent = existingNewsItem {
+ print("UNDER PARENT:", parent.name)
+ parent.children = newArticles
+
+ print(parent.children)
+ }
+ else if path.isEmpty {
+ self?.news = newArticles
+ }
- print(parent.children)
+ continuation.resume(returning: newArticles)
}
- else if path.isEmpty {
- self?.news = newArticles
- }
-
- continuation.resume(returning: newArticles)
})
}
}
@@ -227,7 +243,9 @@ import SwiftUI
return await withCheckedContinuation { [weak self] continuation in
self?.client.sendGetNewsCategories(path: path, sent: { success in
if !success {
- continuation.resume(returning: [])
+ DispatchQueue.main.async {
+ continuation.resume(returning: [])
+ }
return
}
@@ -240,14 +258,16 @@ import SwiftUI
newCategories.append(NewsInfo(hotlineNewsCategory: category))
}
- if let parent = parentNews {
- parent.children = newCategories
- }
- else if path.isEmpty {
- self?.news = newCategories
+ DispatchQueue.main.async {
+ if let parent = parentNews {
+ parent.children = newCategories
+ }
+ else if path.isEmpty {
+ self?.news = newCategories
+ }
+
+ continuation.resume(returning: newCategories)
}
-
- continuation.resume(returning: newCategories)
})
}
}
@@ -256,28 +276,16 @@ import SwiftUI
return await withCheckedContinuation { [weak self] continuation in
self?.client.sendGetNewsArticles(path: path, sent: { success in
if !success {
- continuation.resume(returning: [])
+ DispatchQueue.main.async {
+ continuation.resume(returning: [])
+ }
return
}
- }, reply: { [weak self] articles in
- print("ARTICLES?", articles)
-
- continuation.resume(returning: [])
+ }, reply: { articles in
+ DispatchQueue.main.async {
+ continuation.resume(returning: [])
+ }
})
-// self?.client.sendGetNewsCategories(sent: { success in
-// if !success {
-// continuation.resume(returning: [])
-// return
-// }
-// }, reply: { [weak self] categories in
-// var newCategories: [NewsCategory] = []
-// for category in categories {
-// newCategories.append(NewsCategory(hotlineNewsCategory: category))
-// }
-// self?.news = newCategories
-//
-// continuation.resume(returning: newCategories)
-// })
}
}
@@ -302,8 +310,11 @@ import SwiftUI
self.users = []
self.chat = []
self.messageBoard = []
+ self.messageBoardLoaded = false
self.files = []
+ self.filesLoaded = false
self.news = []
+ self.newsLoaded = false
}
self.status = status
diff --git a/Hotline/Models/NewsInfo.swift b/Hotline/Models/NewsInfo.swift
index ad6bfcd..daab71f 100644
--- a/Hotline/Models/NewsInfo.swift
+++ b/Hotline/Models/NewsInfo.swift
@@ -17,9 +17,12 @@ enum NewsInfoType {
let articleID: UInt?
let path: [String]
+ var expanded: Bool = false
var children: [NewsInfo] = []
var articleFlavors: [String]?
+ var articleUsername: String?
+ var articleDate: Date?
init(hotlineNewsCategory: HotlineNewsCategory) {
self.categoryID = hotlineNewsCategory.id
@@ -46,6 +49,8 @@ enum NewsInfoType {
self.type = .article
self.articleFlavors = hotlineNewsArticle.flavors.map { $0.0 }
+ self.articleUsername = hotlineNewsArticle.username
+ self.articleDate = hotlineNewsArticle.date
}
func hash(into hasher: inout Hasher) {
diff --git a/Hotline/Models/Server.swift b/Hotline/Models/Server.swift
index 8b5ea56..495d236 100644
--- a/Hotline/Models/Server.swift
+++ b/Hotline/Models/Server.swift
@@ -1,9 +1,9 @@
import SwiftUI
-@Observable final class Server: Identifiable, Equatable {
+@Observable final class Server: Identifiable, Equatable, Hashable, Codable {
static let defaultPort: Int = 5500
- let id: UUID = UUID()
+ let id: UUID
let name: String?
let description: String?
let users: Int
@@ -11,6 +11,7 @@ import SwiftUI
let port: Int
init(name: String?, description: String?, address: String, port: Int, users: Int = 0) {
+ self.id = UUID()
self.name = name
self.description = description
self.address = address
@@ -18,11 +19,11 @@ import SwiftUI
self.users = users
}
- static func == (lhs: Server, rhs: Server) -> Bool {
- return lhs.id == rhs.id
+ func hash(into hasher: inout Hasher) {
+ hasher.combine(self.id)
}
- static func == (lhs: HotlineServer, rhs: Server) -> Bool {
- return lhs.name == rhs.name && lhs.address == rhs.address && lhs.port == rhs.port
+ static func == (lhs: Server, rhs: Server) -> Bool {
+ return lhs.id == rhs.id
}
}
diff --git a/Hotline/Models/User.swift b/Hotline/Models/User.swift
index 9011e56..1a921e2 100644
--- a/Hotline/Models/User.swift
+++ b/Hotline/Models/User.swift
@@ -1,7 +1,7 @@
import SwiftUI
struct UserStatus: OptionSet {
- let rawValue: Int
+ let rawValue: UInt
static let idle = UserStatus(rawValue: 1 << 0)
static let admin = UserStatus(rawValue: 1 << 1)