ChWebsiteApp/CHDataManagement/Views/Generic/OptionalImagePropertyView.swift
2025-01-25 22:14:31 +01:00

54 lines
1.5 KiB
Swift

import SwiftUI
struct OptionalImagePropertyView: View {
let title: LocalizedStringKey
@Binding
var selectedImage: FileResource?
let transferImage: (language: ContentLanguage, image: FileResource)?
let footer: LocalizedStringKey
@State
private var showSelectionSheet = false
var body: some View {
VStack(alignment: .leading) {
HStack {
Text(title)
.font(.headline)
Spacer()
if let transferImage {
Button("From \(transferImage.language.shortText)") {
selectedImage = transferImage.image
}
}
}
if let image = selectedImage {
(image.imageToDisplay ?? Image(systemSymbol: .exclamationmarkTriangle))
.resizable()
.aspectRatio(contentMode: .fit)
.frame(maxHeight: 300)
.cornerRadius(8)
}
HStack {
Text(selectedImage?.id ?? "No file selected")
Spacer()
Button("Select") {
showSelectionSheet = true
}
}
Text(footer)
.foregroundStyle(.secondary)
.padding(.bottom)
}
.sheet(isPresented: $showSelectionSheet) {
FileSelectionView(selectedFile: $selectedImage, allowedType: .image)
}
}
}