Integrated the DownloadView view into the BrowseView view for the Browse module.

This commit is contained in:
Javier Cicchelli 2022-12-18 01:06:11 +01:00
parent 49b9b78f57
commit e78a326595

View File

@ -23,7 +23,7 @@ public struct BrowseView: View {
@State private var stack: Stack?
@State private var itemToDelete: (any FileSystemItem)?
@State private var showCreateFolder: Bool = false
@State private var showUploadFile: Bool = false
@State private var showSheet: SheetView?
// MARK: Properties
@ -56,15 +56,25 @@ public struct BrowseView: View {
showCreateFolder = true
},
uploadFile: {
showUploadFile = true
showSheet = .upload(id: folder.id)
},
showProfile: showProfile
)
}
.sheet(isPresented: $showUploadFile) {
UploadView(id: folder.id) {
.sheet(item: $showSheet) { sheet in
switch sheet {
case let .upload(id):
UploadView(id: id) {
Task { await loadItems() }
}
case let .download(id, name):
DownloadView(
id: id,
name: name
) {
Task { await loadItems() }
}
}
}
.createFolder(
isPresenting: $showCreateFolder,
@ -118,7 +128,7 @@ private extension BrowseView {
MessageView(
type: .empty,
action: {
showUploadFile = true
showSheet = .upload(id: folder.id)
}
)
case .error:
@ -162,7 +172,10 @@ private extension BrowseView {
DocumentItem(item: item) {
stack = .open(document)
} download: {
// TODO: download the item id from the backend.
showSheet = .download(
id: document.id,
name: document.name
)
} delete: {
itemToDelete = item
}
@ -211,6 +224,17 @@ private extension BrowseView {
}
}
// MARK: - Enumerations
private extension BrowseView {
enum SheetView: Identifiable {
case upload(id: String)
case download(id: String, name: String)
var id: String { UUID().uuidString }
}
}
// MARK: - Previews
struct BrowseView_Previews: PreviewProvider {