~ knotless Search/
↑↓ move↵ open⇧↵ all results

geesawra.industries/old-fella

Old people's social media app

0
1
main
49 lines · 1.8 KB Raw History
#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