Commit f85e3ec801
Verified · cmc
Layout: unified · split
Sources/OrgstarMobile/FoldersScreen.swift +12 −4
| @@ -21,6 +21,10 @@ struct FoldersScreen: View { | ||
| 21 | 21 | } |
| 22 | 22 | } |
| 23 | 23 | .navigationTitle("Folders") |
| 24 | .navigationDestination(for: FolderRoute.self) { route in | |
| 25 | List { FolderContents(workspace: workspace, root: route.root, folder: route.folder) } | |
| 26 | .navigationTitle((route.folder as NSString).lastPathComponent) | |
| 27 | } | |
| 24 | 28 | .overlay { |
| 25 | 29 | if workspace.rootPaths.isEmpty { |
| 26 | 30 | ContentUnavailableView { |
| @@ -51,6 +55,12 @@ struct FoldersScreen: View { | ||
| 51 | 55 | } |
| 52 | 56 | } |
| 53 | 57 | } |
| 58 | /// A subfolder to show, relative to its root. | |
| 59 | struct FolderRoute: Hashable { | |
| 60 | let root: String | |
| 61 | let folder: String | |
| 62 | } | |
| 63 | ||
| 54 | 64 | /// One folder's subfolders, which open their own contents, then its org files and the files |
| 55 | 65 | /// still downloading into it. `folder` is relative to `root`, empty for the root itself. |
| 56 | 66 | private struct FolderContents: View { |
| @@ -72,10 +82,8 @@ private struct FolderContents: View { | ||
| 72 | 82 | path.firstIndex(of: "/").map { String(path[..<$0]) } |
| 73 | 83 | }).sorted { $0.localizedStandardCompare($1) == .orderedAscending } |
| 74 | 84 | ForEach(subfolders, id: \.self) { name in |
| 75 | NavigationLink { | |
| 76 | List { FolderContents(workspace: workspace, root: root, folder: prefix + name) } | |
| 77 | .navigationTitle(name) | |
| 78 | } label: { | |
| 85 | // A value, as the files' links are: a stack mixing the two kinds pushes wrongly. | |
| 86 | NavigationLink(value: FolderRoute(root: root, folder: prefix + name)) { | |
| 79 | 87 | Label(name, systemImage: "folder") |
| 80 | 88 | } |
| 81 | 89 | } |