aboutsummaryrefslogtreecommitdiff
path: root/Hotline/Views/FilesView.swift
diff options
context:
space:
mode:
authorDustin Mierau <dustin@mierau.me>2023-12-11 23:32:28 -0800
committerDustin Mierau <dustin@mierau.me>2023-12-11 23:32:28 -0800
commit18c4b8643df09be4ce52a4b110ea21ac1ad053fc (patch)
tree335d4f0a6b430b983b6f00567b91eb1ee6b16b4b /Hotline/Views/FilesView.swift
parent84aaa9ef0a1be6986e38d7e4f58e07d3cb84979e (diff)
Move to new Hotline model for data observation and let client exist standalone.
Diffstat (limited to 'Hotline/Views/FilesView.swift')
-rw-r--r--Hotline/Views/FilesView.swift31
1 files changed, 15 insertions, 16 deletions
diff --git a/Hotline/Views/FilesView.swift b/Hotline/Views/FilesView.swift
index 23cd914..11db93c 100644
--- a/Hotline/Views/FilesView.swift
+++ b/Hotline/Views/FilesView.swift
@@ -2,16 +2,17 @@ import SwiftUI
import UniformTypeIdentifiers
struct FileView: View {
- @Environment(HotlineClient.self) private var hotline
+// @Environment(HotlineClient.self) private var hotline
+ @Environment(Hotline.self) private var model: Hotline
@State var expanded = false
- var file: HotlineFile
+ var file: FileInfo
var body: some View {
if file.isFolder {
DisclosureGroup(isExpanded: $expanded) {
- ForEach(file.files!) { childFile in
+ ForEach(file.children!) { childFile in
FileView(file: childFile)
.frame(height: 44)
}
@@ -27,9 +28,9 @@ struct FileView: View {
}
}
.onChange(of: expanded) {
- print("EXPANDED CHANGED")
-
- hotline.sendGetFileList(path: file.path)
+ Task {
+ await model.getFileList(path: file.path)
+ }
}
}
else {
@@ -48,7 +49,7 @@ struct FileView: View {
static let byteFormatter = ByteCountFormatter()
- private func formattedFileSize(_ fileSize: UInt32) -> String {
+ private func formattedFileSize(_ fileSize: UInt) -> String {
// let bcf = ByteCountFormatter()
FileView.byteFormatter.allowedUnits = [.useAll]
FileView.byteFormatter.countStyle = .file
@@ -83,35 +84,33 @@ struct FileView: View {
}
struct FilesView: View {
- @Environment(HotlineClient.self) private var hotline
+// @Environment(HotlineClient.self) private var hotline
+ @Environment(Hotline.self) private var model: Hotline
@State var initialLoad = false
var body: some View {
NavigationStack {
- List(hotline.fileList) { file in
-// OutlineGroup(hotline.fileList, children: \.files, expanded: $expandedFolders) { file in
+ List(model.files) { file in
FileView(file: file)
.frame(height: 44)
-// }
}
.task {
if !initialLoad {
- hotline.sendGetFileList(path: []) {
- initialLoad = true
- }
+ let _ = await model.getFileList()
+ initialLoad = true
}
}
.listStyle(.plain)
.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)