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

geesawra.industries/old-fella

Old people's social media app

0
1
main
60 lines · 1.8 KB Raw History
import SwiftUI

struct PostDivider: View {
    @Environment(\.displayScale) private var displayScale

    var body: some View {
        Rectangle()
            .fill(Color(uiColor: .separator))
            .frame(height: 1 / displayScale)
            .accessibilityHidden(true)
    }
}

struct RepostAttributionRow: View {
    @AppStorage("handlesOnly") private var handlesOnly = false
    @Environment(AppModel.self) private var model
    let postID: String
    let author: Post.Author
    let openProfile: () -> Void

    var body: some View {
        if !model.isHidden(author.id), model.contentDecision(author: author)?.action == .allow {
            Button(action: openProfile) {
                Label(
                    "Reposted by \(DisplayPreferences(handlesOnly: handlesOnly).name(author))",
                    systemImage: "arrow.2.squarepath"
                )
                .appFont(.subheadline, weight: .medium)
                .foregroundStyle(AppPalette.reply)
            }
            .buttonStyle(.plain)
            .accessibilityIdentifier("repostAttribution-\(postID)")
        }
    }
}

struct PostTimestamp: View {
    let date: Date

    var body: some View {
        TimelineView(.periodic(from: .now, by: 60)) { context in
            Text(PostElapsedTime.text(since: date, now: context.date))
        }
        .appFont(.caption)
        .foregroundStyle(Color(uiColor: .secondaryLabel))
    }
}

#if DEBUG && !SHARE_EXTENSION
    #Preview("Post metadata") {
        PreviewHost { _ in
            VStack(alignment: .leading, spacing: 16) {
                RepostAttributionRow(postID: "post-1", author: PreviewContent.author, openProfile: {})
                PostDivider()
                PostTimestamp(date: PreviewContent.date)
            }
            .padding()
        }
    }
#endif