BusinessCard/BusinessCardClip/Views/ClipRootView.swift

35 lines
1.0 KiB
Swift

import SwiftUI
/// Root view for the App Clip that manages the card loading and display flow.
struct ClipRootView: View {
@State private var store = ClipCardStore()
let recordName: String
var body: some View {
ZStack {
Color.Clip.background
.ignoresSafeArea()
Group {
switch store.state {
case .loading:
ClipLoadingView()
case .loaded(let snapshot):
ClipCardPreview(snapshot: snapshot) {
Task { await store.cleanupAfterShare() }
}
case .saved:
ClipSuccessView()
case .error(let message):
ClipErrorView(message: message) {
Task { await store.load(recordName: recordName) }
}
}
}
}
.task(id: recordName) {
await store.load(recordName: recordName)
}
}
}