Implemented the stack navigation of the folder items in the BrowseView view for the Browse module.

This commit is contained in:
Javier Cicchelli 2022-12-15 00:16:59 +01:00
parent 0f0773992f
commit 58a73fa637

View File

@ -19,6 +19,7 @@ public struct BrowseView: View {
// MARK: States
@State private var items: [any FileSystemItemIdentifiable] = []
@State private var stack: Stack?
// MARK: Properties
@ -49,17 +50,13 @@ public struct BrowseView: View {
List(items, id: \.id) { item in
switch item {
case is Folder:
FolderItem(item: item) { id in
// TODO: browse to the item id in another view.
} delete: { id in
// TODO: delete the item id from the backend.
}
makeFolderItem(for: item)
case is Document:
DocumentItem(item: item) { id in
DocumentItem(item: item) {
// TODO: show the item id in a viewer...
} download: { id in
} download: {
// TODO: download the item id from the backend.
} delete: { id in
} delete: {
// TODO: delete the item id from the backend.
}
default:
@ -80,6 +77,35 @@ public struct BrowseView: View {
}
}
}
// MARK: - UI
private extension BrowseView {
@ViewBuilder func makeFolderItem(
for item: any FileSystemItemIdentifiable
) -> some View {
let folder = Folder(
id: item.id,
name: item.name
)
FolderItem(item: item) {
stack = .browse(folder)
} delete: {
// TODO: delete the item id from the backend.
}
.navigate(
to: BrowseView(
folder: folder,
createFolder: createFolder,
uploadFile: uploadFile,
showProfile: showProfile
),
tagged: .browse(folder),
in: $stack
)
}
}
// MARK: - Helpers