Improved the FolderItem and the DocumentItem components to support the item selection.
This commit is contained in:
parent
98db94d180
commit
0ecc4810fa
@ -13,12 +13,16 @@ struct DocumentItem: View {
|
||||
// MARK: Properties
|
||||
|
||||
let item: FileSystemItem
|
||||
let select: ItemIdClosure
|
||||
let download: ItemIdClosure
|
||||
let delete: ItemIdClosure
|
||||
|
||||
// MARK: Body
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
select(item.id)
|
||||
} label: {
|
||||
HStack(spacing: 16) {
|
||||
Image.document
|
||||
.icon(size: 32)
|
||||
@ -40,6 +44,7 @@ struct DocumentItem: View {
|
||||
}
|
||||
}
|
||||
.padding(.vertical, 4)
|
||||
}
|
||||
.swipeActions(
|
||||
edge: .trailing,
|
||||
allowsFullSwipe: true
|
||||
@ -99,6 +104,8 @@ struct DocumentItem_Previews: PreviewProvider {
|
||||
size: .random(in: 1 ... 100),
|
||||
lastModifiedAt: .now
|
||||
)) { _ in
|
||||
// select closure with item id.
|
||||
} download: { _ in
|
||||
// download closure with item id.
|
||||
} delete: { _ in
|
||||
// delete closure with item id.
|
||||
@ -112,6 +119,8 @@ struct DocumentItem_Previews: PreviewProvider {
|
||||
size: .random(in: 1 ... 100),
|
||||
lastModifiedAt: .now
|
||||
)) { _ in
|
||||
// select closure with item id.
|
||||
} download: { _ in
|
||||
// download closure with item id.
|
||||
} delete: { _ in
|
||||
// delete closure with item id.
|
||||
|
@ -13,11 +13,15 @@ struct FolderItem: View {
|
||||
// MARK: Properties
|
||||
|
||||
let item: FileSystemItem
|
||||
let select: ItemIdClosure
|
||||
let delete: ItemIdClosure
|
||||
|
||||
// MARK: Body
|
||||
|
||||
var body: some View {
|
||||
Button {
|
||||
select(item.id)
|
||||
} label: {
|
||||
HStack(spacing: 16) {
|
||||
Image.folder
|
||||
.icon(size: 32)
|
||||
@ -32,6 +36,7 @@ struct FolderItem: View {
|
||||
.font(.headline)
|
||||
}
|
||||
.padding(.vertical, 8)
|
||||
}
|
||||
.swipeActions(
|
||||
edge: .trailing,
|
||||
allowsFullSwipe: true
|
||||
@ -69,6 +74,8 @@ struct BrowseItem_Previews: PreviewProvider {
|
||||
id: "1234567890",
|
||||
name: "Some folder name goes in here..."
|
||||
)) { _ in
|
||||
// select closure with item id.
|
||||
} delete: { _ in
|
||||
// delete closure with item id.
|
||||
}
|
||||
.previewDisplayName("Folder item")
|
||||
@ -77,7 +84,9 @@ struct BrowseItem_Previews: PreviewProvider {
|
||||
id: "1234567890",
|
||||
name: "Some very, extremely long folder name goes in here..."
|
||||
)) { _ in
|
||||
// delete closire with item id.
|
||||
// select closure with item id.
|
||||
} delete: { _ in
|
||||
// delete closure with item id.
|
||||
}
|
||||
.previewDisplayName("Folder item with long name")
|
||||
}
|
||||
|
@ -18,7 +18,7 @@ public struct BrowseView: View {
|
||||
|
||||
// MARK: States
|
||||
|
||||
@State private var items: [any FileSystemIdIdentifiable] = []
|
||||
@State private var items: [any FileSystemItemIdentifiable] = []
|
||||
|
||||
// MARK: Properties
|
||||
|
||||
@ -46,15 +46,18 @@ public struct BrowseView: View {
|
||||
// MARK: Body
|
||||
|
||||
public var body: some View {
|
||||
List {
|
||||
ForEach(items, id: \.id) { item in
|
||||
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.
|
||||
}
|
||||
case is Document:
|
||||
DocumentItem(item: item) { id in
|
||||
// TODO: show the item id in a viewer...
|
||||
} download: { id in
|
||||
// TODO: download the item id from the backend.
|
||||
} delete: { id in
|
||||
// TODO: delete the item id from the backend.
|
||||
@ -63,7 +66,6 @@ public struct BrowseView: View {
|
||||
EmptyView()
|
||||
}
|
||||
}
|
||||
}
|
||||
.listStyle(.inset)
|
||||
.navigationTitle(folder.name)
|
||||
.toolbar {
|
||||
|
Loading…
x
Reference in New Issue
Block a user