Integrated the FolderItem and the DocumentItem components into the BrowseView view for the Browse module.

This commit is contained in:
Javier Cicchelli 2022-12-14 01:21:20 +01:00
parent c7f5d0db40
commit 37490ba3d7

View File

@ -18,7 +18,7 @@ public struct BrowseView: View {
// MARK: States
@State private var items: [any ModelIdentifiable] = []
@State private var items: [any FileSystemIdIdentifiable] = []
// MARK: Properties
@ -48,99 +48,21 @@ public struct BrowseView: View {
public var body: some View {
List {
ForEach(items, id: \.id) { item in
if let folder = item as? Folder {
FolderItem(name: folder.name)
} else if let file = item as? File {
DocumentItem(
name: file.name,
lastModified: "-",
fileSize: "-"
)
switch item {
case is Folder:
FolderItem(item: item) { id in
// TODO: delete the item id from the backend.
}
case is Document:
DocumentItem(item: item) { id in
// TODO: download the item id from the backend.
} delete: { id in
// TODO: delete the item id from the backend.
}
default:
EmptyView()
}
}
// Group {
// Group {
// FolderItem(name: "Some folder #1 name")
// FolderItem(name: "Some folder #2 name")
// FolderItem(name: "Some folder #3 name")
// FolderItem(name: "Some folder #4 name")
// FolderItem(name: "Some folder #5 name")
// FolderItem(name: "Some folder #6 name")
// FolderItem(name: "Some folder #7 name")
// }
// Group {
// DocumentItem(
// name: "Some document #1 name",
// lastModified: "3 months ago",
// fileSize: "1,23 Mbytes"
// )
// DocumentItem(
// name: "Some document #2 name",
// lastModified: "2 years ago",
// fileSize: "123 Kbytes"
// )
// DocumentItem(
// name: "Some document #3 name",
// lastModified: "13 days ago",
// fileSize: "12 bytes"
// )
// DocumentItem(
// name: "Some document #4 name",
// lastModified: "13 hours ago",
// fileSize: "12,3 Gbytes"
// )
// DocumentItem(
// name: "Some document #5 name",
// lastModified: "13 minutes ago",
// fileSize: "123 Tbytes"
// )
// DocumentItem(
// name: "Some document #6 name",
// lastModified: "13 seconds ago",
// fileSize: "123 Tbytes"
// )
// DocumentItem(
// name: "Some document #7 name",
// lastModified: "13 nanoseconds ago",
// fileSize: "123 Tbytes"
// )
// }
// }
// .swipeActions(
// edge: .trailing,
// allowsFullSwipe: true
// ) {
// Button {
// // TODO: Implement the removal of the item from the API.
// } label: {
// Label {
// Text(
// "browse.swipe_action.delete_item.text",
// bundle: .module,
// comment: "Delete item swipe action text."
// )
// } icon: {
// Image.trash
// }
// }
// .tint(.red)
//
// // TODO: allow download only if item is a file.
// Button {
// // TODO: Implement the downloading of the data of the item from the API into the device.
// } label: {
// Label {
// Text(
// "browse.swipe_action.download_item.text",
// bundle: .module,
// comment: "Download item swipe action text."
// )
// } icon: {
// Image.download
// }
// }
// .tint(.orange)
// }
}
.listStyle(.inset)
.navigationTitle(folder.name)
@ -162,28 +84,19 @@ public struct BrowseView: View {
private extension BrowseView {
func getItemsOrStop() async {
guard let account else { return }
do {
items = try await getItems(
id: folder.id,
username: account.username,
password: account.password
)
} catch let error {
print(folder)
print(error)
// TODO: Handle the error.
} catch {
// TODO: handle the error appropriately.
}
}
}
// MARK: - Image+Constants
private extension Image {
static let trash = Image(systemName: "trash")
static let download = Image(systemName: "arrow.down.doc")
}
// MARK: - Previews
struct BrowseView_Previews: PreviewProvider {