48 lines
1.5 KiB
Swift
48 lines
1.5 KiB
Swift
import SwiftUI
|
|
import SwiftData
|
|
|
|
/// Composition boundary: the AR picker receives only neutral project data.
|
|
struct LeadARProjectsSheet: View {
|
|
let detail: LeadDetail
|
|
@Environment(\.modelContext) private var context
|
|
@State private var service: LeadARProjectsService?
|
|
|
|
var body: some View {
|
|
Group {
|
|
if let service {
|
|
LeadARProjectsContent(service: service)
|
|
} else {
|
|
ProgressView()
|
|
}
|
|
}
|
|
.task {
|
|
if service == nil {
|
|
service = LeadARProjectsService(detail: detail, container: context.container)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private struct LeadARProjectsContent: View {
|
|
let service: LeadARProjectsService
|
|
@State private var activeProject: Project?
|
|
@State private var errorMessage: String?
|
|
|
|
var body: some View {
|
|
ARProjectsSheet(service: service) { id in
|
|
do { activeProject = try service.resolveProject(id: id) }
|
|
catch { errorMessage = error.localizedDescription }
|
|
}
|
|
.fullScreenCover(item: $activeProject) { project in
|
|
if let context = project.modelContext {
|
|
ARExperienceView(project: project).modelContext(context)
|
|
}
|
|
}
|
|
.alert("AR-Projekt konnte nicht geöffnet werden",
|
|
isPresented: Binding(get: { errorMessage != nil },
|
|
set: { if !$0 { errorMessage = nil } })) {
|
|
Button("OK", role: .cancel) { errorMessage = nil }
|
|
} message: { Text(errorMessage ?? "") }
|
|
}
|
|
}
|