Open files in subfolders on the first tap !205
1 file changed, +12 −4
Layout: unified · split
Sources/OrgstarMobile/FoldersScreen.swift +12 −4
| @@ -21,6 +21,10 @@ struct FoldersScreen: View { | |||
| 21 | } | 21 | } |
| 22 | } | 22 | } |
| 23 | .navigationTitle("Folders") | 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 | .overlay { | 28 | .overlay { |
| 25 | if workspace.rootPaths.isEmpty { | 29 | if workspace.rootPaths.isEmpty { |
| 26 | ContentUnavailableView { | 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 | /// One folder's subfolders, which open their own contents, then its org files and the files | 64 | /// One folder's subfolders, which open their own contents, then its org files and the files |
| 55 | /// still downloading into it. `folder` is relative to `root`, empty for the root itself. | 65 | /// still downloading into it. `folder` is relative to `root`, empty for the root itself. |
| 56 | private struct FolderContents: View { | 66 | private struct FolderContents: View { |
| @@ -72,10 +82,8 @@ private struct FolderContents: View { | |||
| 72 | path.firstIndex(of: "/").map { String(path[..<$0]) } | 82 | path.firstIndex(of: "/").map { String(path[..<$0]) } |
| 73 | }).sorted { $0.localizedStandardCompare($1) == .orderedAscending } | 83 | }).sorted { $0.localizedStandardCompare($1) == .orderedAscending } |
| 74 | ForEach(subfolders, id: \.self) { name in | 84 | ForEach(subfolders, id: \.self) { name in |
| 75 | NavigationLink { | 85 | // A value, as the files' links are: a stack mixing the two kinds pushes wrongly. |
| 76 | List { FolderContents(workspace: workspace, root: root, folder: prefix + name) } | 86 | NavigationLink(value: FolderRoute(root: root, folder: prefix + name)) { |
| 77 | .navigationTitle(name) | ||
| 78 | } label: { | ||
| 79 | Label(name, systemImage: "folder") | 87 | Label(name, systemImage: "folder") |
| 80 | } | 88 | } |
| 81 | } | 89 | } |