Skip to content

Commit dccf091

Browse files
committed
Refactor KFSFileManager to use FileEntry struct for entries and update FileManagerView list rendering
1 parent 9d17aca commit dccf091

2 files changed

Lines changed: 13 additions & 3 deletions

File tree

lara/classes/KFSFileManager.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,18 @@ import Combine
33

44
final class KFSFileManager: ObservableObject {
55
static let shared = KFSFileManager()
6+
struct FileEntry: Identifiable, Hashable {
7+
let id: String
8+
let name: String
9+
let isDir: Bool
10+
init(name: String, isDir: Bool) {
11+
self.id = name
12+
self.name = name
13+
self.isDir = isDir
14+
}
15+
}
616
@Published var currentPath: String = "/"
7-
@Published var entries: [(name: String, isDir: Bool)] = []
17+
@Published var entries: [FileEntry] = []
818
@Published var lastError: String? = nil
919
@Published var status: String = "idle"
1020

@@ -17,7 +27,7 @@ final class KFSFileManager: ObservableObject {
1727
if let list = laramgr.shared.kfslistdir(path: p) {
1828
DispatchQueue.main.async {
1929
self.currentPath = p
20-
self.entries = list
30+
self.entries = list.map { FileEntry(name: $0.name, isDir: $0.isDir) }
2131
self.status = "listed"
2232
}
2333
} else {

lara/views/FileManagerView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ struct FileManagerView: View {
2020
}
2121
}.padding()
2222

23-
List(kfs.entries, id: \.(name)) { entry in
23+
List(kfs.entries) { entry in
2424
HStack {
2525
if entry.isDir { Image(systemName: "folder") }
2626
else { Image(systemName: "doc.text") }

0 commit comments

Comments
 (0)