From 18c4b8643df09be4ce52a4b110ea21ac1ad053fc Mon Sep 17 00:00:00 2001 From: Dustin Mierau Date: Mon, 11 Dec 2023 23:32:28 -0800 Subject: Move to new Hotline model for data observation and let client exist standalone. --- Hotline/Views/FilesView.swift | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'Hotline/Views/FilesView.swift') 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) -- cgit