Add lead workflows, PDF signing, AR projects and photo gallery integration
This commit is contained in:
33
GasTankAR/Views/Leads/Detail/LeadFileViewModel.swift
Normal file
33
GasTankAR/Views/Leads/Detail/LeadFileViewModel.swift
Normal file
@ -0,0 +1,33 @@
|
||||
import Foundation
|
||||
import Observation
|
||||
|
||||
@MainActor
|
||||
@Observable
|
||||
final class LeadFileViewModel {
|
||||
private(set) var url: URL?
|
||||
private(set) var message: LocalizedStringResource?
|
||||
private(set) var needsLogin = false
|
||||
private(set) var allowsRetry = true
|
||||
private var generation = 0
|
||||
|
||||
func load(using download: () async throws -> URL) async {
|
||||
generation += 1
|
||||
let request = generation
|
||||
url = nil
|
||||
message = nil
|
||||
needsLogin = false
|
||||
allowsRetry = true
|
||||
do {
|
||||
let result = try await download()
|
||||
try Task.checkCancellation()
|
||||
guard request == generation else { return }
|
||||
url = result
|
||||
} catch is CancellationError {
|
||||
} catch {
|
||||
guard request == generation, !Task.isCancelled else { return }
|
||||
message = error.leadFileMessage
|
||||
needsLogin = error as? LeadError == .unauthorized
|
||||
allowsRetry = (error as? LeadError)?.allowsRetry ?? true
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user