Caps-iOS/Caps/Views/CapRowView.swift

76 lines
2.4 KiB
Swift
Raw Normal View History

2022-06-10 21:20:49 +02:00
import SwiftUI
2023-04-17 14:20:25 +02:00
import SFSafeSymbols
2022-06-10 21:20:49 +02:00
struct CapRowView: View {
private let imageSize: CGFloat = 70
private let sufficientImageCount = 10
let cap: Cap
let match: Float?
@EnvironmentObject
var database: Database
var imageUrl: URL {
database.serverUrl.appendingPathComponent(cap.mainImagePath)
}
var body: some View {
HStack(alignment: .center) {
VStack(alignment: .leading, spacing: 0) {
2023-04-17 14:20:25 +02:00
Text(cap.name)
.font(.headline)
.padding(.bottom, 3)
HStack(spacing: 4) {
Image(systemSymbol: .tag)
Text("\(cap.id)")
.padding(.trailing, 8)
Image(systemSymbol: .photoCircle)
Text("\(cap.imageCount)")
.padding(.trailing, 8)
2022-06-10 21:20:49 +02:00
if cap.imageCount < sufficientImageCount {
2023-04-17 14:20:25 +02:00
Image(systemSymbol: .eyeTrianglebadgeExclamationmark)
.padding(.trailing, 8)
}
if !database.canClassify(cap: cap.id) {
Image(systemSymbol: .eyeSlash)
.padding(.trailing, 8)
2022-06-10 21:20:49 +02:00
}
if database.hasPendingUpdates(for: cap.id) {
2023-04-17 14:20:25 +02:00
Image(systemSymbol: .arrowUpArrowDownCircle)
.padding(.trailing, 8)
2022-06-10 21:20:49 +02:00
}
2023-04-17 14:20:25 +02:00
if let match = match {
Image(systemSymbol: .target)
Text("\(Int((match * 100).rounded())) %")
.padding(.trailing, 8)
2022-06-10 21:20:49 +02:00
}
}
2023-04-17 14:20:25 +02:00
.foregroundColor(.secondary)
2022-06-10 21:20:49 +02:00
.padding(.top, 0)
.font(.footnote)
}//.padding(.vertical)
Spacer()
2022-06-21 19:38:51 +02:00
CachedCapImage(cap, cap.image, cache: database.images) { image in
2022-06-10 21:20:49 +02:00
image.resizable()
} placeholder: {
ProgressView()
}
.frame(width: imageSize, height: imageSize)
.cornerRadius(imageSize / 2)
}
}
}
struct CapRowView_Previews: PreviewProvider {
static var previews: some View {
CapRowView(cap: Cap(id: 123, name: "My new cap"),
match: 0.13)
.previewLayout(.fixed(width: 375, height: 80))
.environmentObject(Database.mock)
}
}