2022-12-03 06:56:38 +01:00
|
|
|
//
|
|
|
|
// DocumentItem.swift
|
|
|
|
// Browse
|
|
|
|
//
|
|
|
|
// Created by Javier Cicchelli on 03/12/2022.
|
|
|
|
// Copyright © 2022 Röck+Cöde. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct DocumentItem: View {
|
|
|
|
|
|
|
|
// MARK: Properties
|
|
|
|
|
2022-12-14 01:17:26 +01:00
|
|
|
let item: FileSystemItem
|
|
|
|
let download: ItemIdClosure
|
|
|
|
let delete: ItemIdClosure
|
|
|
|
|
2022-12-03 06:56:38 +01:00
|
|
|
// MARK: Body
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
HStack(spacing: 16) {
|
|
|
|
Image.document
|
|
|
|
.icon(size: 32)
|
|
|
|
.foregroundColor(.red)
|
|
|
|
|
2022-12-14 01:17:26 +01:00
|
|
|
VStack(spacing: 8) {
|
|
|
|
Text(item.name)
|
2022-12-03 06:56:38 +01:00
|
|
|
.itemName()
|
|
|
|
|
|
|
|
HStack {
|
2022-12-14 01:17:26 +01:00
|
|
|
Text("lastModified")
|
2022-12-03 06:56:38 +01:00
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
2022-12-14 01:17:26 +01:00
|
|
|
Text("fileSize")
|
2022-12-03 06:56:38 +01:00
|
|
|
}
|
|
|
|
.font(.subheadline)
|
|
|
|
.foregroundColor(.secondary)
|
|
|
|
}
|
|
|
|
}
|
2022-12-14 01:17:26 +01:00
|
|
|
.padding(.vertical, 4)
|
|
|
|
.swipeActions(
|
|
|
|
edge: .trailing,
|
|
|
|
allowsFullSwipe: true
|
|
|
|
) {
|
|
|
|
Button {
|
|
|
|
delete(item.id)
|
|
|
|
} label: {
|
|
|
|
Label {
|
|
|
|
Text(
|
|
|
|
"browse.swipe_action.delete_item.text",
|
|
|
|
bundle: .module
|
|
|
|
)
|
|
|
|
} icon: {
|
|
|
|
Image.trash
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.tint(.red)
|
|
|
|
|
|
|
|
Button {
|
|
|
|
download(item.id)
|
|
|
|
} label: {
|
|
|
|
Label {
|
|
|
|
Text(
|
|
|
|
"browse.swipe_action.download_item.text",
|
|
|
|
bundle: .module
|
|
|
|
)
|
|
|
|
} icon: {
|
|
|
|
Image.download
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.tint(.orange)
|
|
|
|
}
|
2022-12-03 06:56:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-12-14 01:17:26 +01:00
|
|
|
// MARK: - Helpers
|
|
|
|
|
|
|
|
private extension DocumentItem {
|
|
|
|
var document: Document? { item as? Document }
|
|
|
|
}
|
|
|
|
|
2022-12-03 06:56:38 +01:00
|
|
|
// MARK: - Image+Constants
|
|
|
|
|
|
|
|
private extension Image {
|
|
|
|
static let document = Image(systemName: "doc.fill")
|
|
|
|
}
|
|
|
|
|
|
|
|
// MARK: - Previews
|
|
|
|
|
|
|
|
struct DocumentItem_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
2022-12-14 01:17:26 +01:00
|
|
|
DocumentItem(item: Document(
|
|
|
|
id: "1234567890",
|
2022-12-03 06:56:38 +01:00
|
|
|
name: "Some document name goes in here...",
|
2022-12-14 01:17:26 +01:00
|
|
|
contentType: "some content type",
|
|
|
|
size: .random(in: 1 ... 100),
|
|
|
|
lastModifiedAt: .now
|
|
|
|
)) { _ in
|
|
|
|
// download closure with item id.
|
|
|
|
} delete: { _ in
|
|
|
|
// delete closure with item id.
|
|
|
|
}
|
2022-12-03 06:56:38 +01:00
|
|
|
.previewDisplayName("Document item")
|
|
|
|
|
2022-12-14 01:17:26 +01:00
|
|
|
DocumentItem(item: Document(
|
|
|
|
id: "1234567890",
|
2022-12-03 06:56:38 +01:00
|
|
|
name: "Some very, extremely long document name goes in here...",
|
2022-12-14 01:17:26 +01:00
|
|
|
contentType: "some content type",
|
|
|
|
size: .random(in: 1 ... 100),
|
|
|
|
lastModifiedAt: .now
|
|
|
|
)) { _ in
|
|
|
|
// download closure with item id.
|
|
|
|
} delete: { _ in
|
|
|
|
// delete closure with item id.
|
|
|
|
}
|
2022-12-03 06:56:38 +01:00
|
|
|
.previewDisplayName("Document item with long name")
|
|
|
|
}
|
|
|
|
}
|