Add lead workflows, PDF signing, AR projects and photo gallery integration
This commit is contained in:
62
GasTankAR/Views/Leads/Detail/LeadPDFPreview.swift
Normal file
62
GasTankAR/Views/Leads/Detail/LeadPDFPreview.swift
Normal file
@ -0,0 +1,62 @@
|
||||
import SwiftUI
|
||||
import PDFKit
|
||||
|
||||
struct LeadPDFPreview: View {
|
||||
let document: LeadDocument
|
||||
let leadID: String
|
||||
let salesCode: String
|
||||
let repository: any LeadDetailRepository
|
||||
let onLogout: () -> Void
|
||||
var signedURL: URL? = nil
|
||||
@State private var model = LeadFileViewModel()
|
||||
@State private var retryID = 0
|
||||
@State private var showsPreview = false
|
||||
@Environment(\.dismiss) private var dismiss
|
||||
|
||||
var body: some View {
|
||||
NavigationStack {
|
||||
ZStack {
|
||||
if let url = signedURL ?? model.url {
|
||||
LeadPDFView(url: url)
|
||||
.fullScreenCover(isPresented: $showsPreview) {
|
||||
LeadDocumentPreview(url: url)
|
||||
}
|
||||
} else if let message = model.message {
|
||||
ContentUnavailableView {
|
||||
Label("PDF konnte nicht geöffnet werden", systemImage: "doc.badge.ellipsis")
|
||||
} description: { Text(message) } actions: {
|
||||
if model.needsLogin {
|
||||
Button("Erneut anmelden", action: onLogout)
|
||||
} else if model.allowsRetry {
|
||||
Button("Erneut versuchen") { retryID += 1 }
|
||||
}
|
||||
}
|
||||
} else {
|
||||
ProgressView("PDF wird heruntergeladen …")
|
||||
}
|
||||
}
|
||||
.navigationTitle(document.title)
|
||||
.navigationBarTitleDisplayMode(.inline)
|
||||
.toolbar {
|
||||
ToolbarItem(placement: .cancellationAction) {
|
||||
Button(role: .cancel) { dismiss() }
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
ToolbarItem(placement: .topBarTrailing) {
|
||||
Button("In Vorschau öffnen", systemImage: "arrow.up.left.and.arrow.down.right") {
|
||||
showsPreview = true
|
||||
}
|
||||
.labelStyle(.iconOnly)
|
||||
.disabled(signedURL == nil && model.url == nil)
|
||||
}
|
||||
}
|
||||
.task(id: retryID) {
|
||||
guard signedURL == nil else { return }
|
||||
await model.load {
|
||||
try await DownloadLeadDocumentUseCase(repository: repository)
|
||||
.execute(document, leadID: leadID, salesCode: salesCode)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user