1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
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 }
}
}
}