Integrated the FolderItem and the DocumentItem components into the BrowseView view for the Browse module.
This commit is contained in:
parent
c7f5d0db40
commit
37490ba3d7
@ -18,7 +18,7 @@ public struct BrowseView: View {
|
|||||||
|
|
||||||
// MARK: States
|
// MARK: States
|
||||||
|
|
||||||
@State private var items: [any ModelIdentifiable] = []
|
@State private var items: [any FileSystemIdIdentifiable] = []
|
||||||
|
|
||||||
// MARK: Properties
|
// MARK: Properties
|
||||||
|
|
||||||
@ -48,99 +48,21 @@ public struct BrowseView: View {
|
|||||||
public var body: some View {
|
public var body: some View {
|
||||||
List {
|
List {
|
||||||
ForEach(items, id: \.id) { item in
|
ForEach(items, id: \.id) { item in
|
||||||
if let folder = item as? Folder {
|
switch item {
|
||||||
FolderItem(name: folder.name)
|
case is Folder:
|
||||||
} else if let file = item as? File {
|
FolderItem(item: item) { id in
|
||||||
DocumentItem(
|
// TODO: delete the item id from the backend.
|
||||||
name: file.name,
|
}
|
||||||
lastModified: "-",
|
case is Document:
|
||||||
fileSize: "-"
|
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)
|
.listStyle(.inset)
|
||||||
.navigationTitle(folder.name)
|
.navigationTitle(folder.name)
|
||||||
@ -162,28 +84,19 @@ public struct BrowseView: View {
|
|||||||
private extension BrowseView {
|
private extension BrowseView {
|
||||||
func getItemsOrStop() async {
|
func getItemsOrStop() async {
|
||||||
guard let account else { return }
|
guard let account else { return }
|
||||||
|
|
||||||
do {
|
do {
|
||||||
items = try await getItems(
|
items = try await getItems(
|
||||||
id: folder.id,
|
id: folder.id,
|
||||||
username: account.username,
|
username: account.username,
|
||||||
password: account.password
|
password: account.password
|
||||||
)
|
)
|
||||||
} catch let error {
|
} catch {
|
||||||
print(folder)
|
// TODO: handle the error appropriately.
|
||||||
print(error)
|
|
||||||
// TODO: Handle the error.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// MARK: - Image+Constants
|
|
||||||
|
|
||||||
private extension Image {
|
|
||||||
static let trash = Image(systemName: "trash")
|
|
||||||
static let download = Image(systemName: "arrow.down.doc")
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: - Previews
|
// MARK: - Previews
|
||||||
|
|
||||||
struct BrowseView_Previews: PreviewProvider {
|
struct BrowseView_Previews: PreviewProvider {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user