Caps-iOS/Caps/Views/CapRowView.swift
2022-06-21 19:38:51 +02:00

77 lines
2.2 KiB
Swift

import SwiftUI
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 imageCountText: String {
guard cap.imageCount != 1 else {
return "\(cap.id) (1 image)"
}
return "\(cap.id) (\(cap.imageCount) images)"
}
var body: some View {
HStack(alignment: .center) {
VStack(alignment: .leading, spacing: 0) {
HStack(spacing: 8) {
Text(imageCountText)
.font(.footnote)
if !cap.classifiable(by: database.classifierVersion) {
Text("📵")
}
if cap.imageCount < sufficientImageCount {
Text("⚠️")
}
if database.hasPendingUpdates(for: cap.id) {
Text("")
}
if database.hasPendingOperations(for: cap.id) {
ProgressView()
}
}
.padding(.top, 0)
.font(.footnote)
Text(cap.name)
.font(.headline)
.padding(.bottom, 3)
if let match = match {
Text("\(Int((match * 100).rounded())) % match")
.font(.footnote)
}
}//.padding(.vertical)
Spacer()
CachedCapImage(cap, cap.image, cache: database.images) { image in
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)
}
}