import SwiftUI struct SharedComposerRoot: View { let model: AppModel let altTextTestMode: String? let load: () async throws -> SharedComposeContent let onCancel: () -> Void let onPost: () -> Void @State private var content: SharedComposeContent? @State private var loading = true @State private var loadError: String? @State private var loadRetry = 0 var body: some View { Group { if loading || model.isRestoringSession { NavigationStack { ProgressView("Preparing post") .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel", action: onCancel) } } } } else if let message = loadError { NavigationStack { ContentUnavailableView { Label("Shared items unavailable", systemImage: "exclamationmark.triangle") } description: { Text(message) } actions: { Button("Try again") { loadError = nil loading = true loadRetry += 1 } } .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel", action: onCancel) } } } } else if let content, model.account != nil { NavigationStack { ComposeView( replyTo: nil, quotePostID: nil, sharedContent: content, onSharedCancel: onCancel, onSharedPost: onPost, altTextTestMode: altTextTestMode) } .environment(model) } else { NavigationStack { ContentUnavailableView { Label("Cannot post", systemImage: "person.crop.circle.badge.exclamationmark") } description: { Text(model.errorMessage ?? "Sign in to Old Fella to post.") } actions: { Button("Retry") { Task { await model.restoreSession() } } } .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Cancel", action: onCancel) } } } } } .appDefaultFont() .defaultAppStorage(UserDefaults(suiteName: AppGroup.identifier) ?? .standard) .tint(AppPalette.accent) .progressViewStyle(AppProgressViewStyle()) .task(id: loadRetry) { do { content = try await load() } catch { if !Task.isCancelled { loadError = NetworkFailure.message(for: error) } } if !Task.isCancelled { loading = false } } } }