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
#if DEBUG
import SwiftUI
@MainActor
struct PreviewHost<Content: View>: View {
@State private var model: AppModel
@State private var isReady = false
private let signedIn: Bool
private let content: (AppModel) -> Content
init(signedIn: Bool = true, @ViewBuilder content: @escaping (AppModel) -> Content) {
let defaults = UserDefaults(suiteName: "com.oldfella.previews.\(UUID().uuidString)")!
_model = State(initialValue: AppModel(service: MockBlueskyService(), feedDefaults: defaults))
self.signedIn = signedIn
self.content = content
}
var body: some View {
Group {
if isReady {
content(model)
} else {
ProgressView("Preparing preview")
}
}
.environment(model)
.progressViewStyle(AppProgressViewStyle())
.task {
guard !isReady else { return }
await model.restoreSession()
if signedIn { await model.signInWithDemo() }
isReady = true
}
}
}
@MainActor
enum PreviewContent {
static let author = Post.Author(id: "mae", name: "Mae Rivers", handle: "mae.example")
static let account = Account(handle: "mae.example", displayName: "Mae Rivers", id: "mae")
static let post = Post(
id: "post-1", author: author,
text: "A quiet morning by the water. Small things worth noticing.",
likeCount: 24, repostCount: 3, isLiked: false, isReposted: false,
imageURLs: [], quote: nil, replyIDs: []
)
static let date = Date(timeIntervalSince1970: 1_800_000_000)
}
#endif