Cotton code
110 lines · 4.2 KB · SwiftRaw
// `/rejected`, drawn once for both hosts.//// One screen, no platform branch: the phone pushes it from the join sheet's// merge report and from Settings › Devices, and the Mac's settings column// renders this same view over its own served file. `ScreenPlatformSweepTests`// holds that.//// The reason on each row is the CORE's sentence and is drawn exactly as given.// Nothing here writes prose about somebody's failed write.import CottonKitimport SwiftUIpublic struct RejectedScreen: View {    @Bindable private var model: RejectedModel    @Environment(\.cottonHaptics) private var haptics    public init(model: RejectedModel) {        self.model = model    }    public var body: some View {        PaperScreen(title: ShellLines.line("devices", "writes_that_did_not")) {            // A settings page is a form, and a form has a measure — see            // `Platform/SettingsFormWidth.swift`.            VStack(alignment: .leading, spacing: 0) {                if let refusal = model.refusal, model.rows.isEmpty {                    ObjectEmpty(                        sheet: .cream,                        line1: ShellLines.line("devices", "this_list_could_not"),                        line2: refusal,                        actionLabel: CottonStrings.tryAgain,                        action: { Task { await model.load() } }                    )                    .accessibilityIdentifier("rejected-unreadable")                } else if model.isFirstRead {                    SkeletonText(lines: 3, lastLineWidth: 0.5, lineWidth: 0.8, lineHeight: 16)                        .accessibilityIdentifier("rejected-skeleton")                } else if model.rows.isEmpty {                    ObjectEmpty(                        sheet: .cream,                        line1: ShellLines.line("devices", "everything_synced"),                        line2: ShellLines.line("devices", "no_write_has_been")                    )                    .accessibilityIdentifier("rejected-empty")                } else {                    list                }            }            .settingsFormWidth()        }        .refreshable { await model.load() }        .task { await model.load() }    }    @ViewBuilder private var list: some View {        if !model.rows.isEmpty { parked }    }    @ViewBuilder private var parked: some View {        PaperSection(title: ShellLines.line("devices", "parked_here"), count: String(model.rows.count))        VStack(spacing: 12) {            ForEach(model.rows) { row in                RejectedRow(row: row)            }        }        .accessibilityIdentifier("rejected-rows")        // The verb. Below the list, because it acts on all of it.        VStack(alignment: .leading, spacing: 6) {            PaperTypedButton(ShellLines.line("devices", "retry_all")) {                haptics.warning()                Task { await model.retryAll() }            }            .disabled(model.isBusy)            .accessibilityIdentifier("rejected-retry-all")            if !model.everyRowCanBeRetried {                // Said before the tap rather than discovered after it: a write                // this device SENT was turned away by the server, and no retry                // on this side can change that verdict.                Text(RejectedScreen.retryLimit(retryable: model.retryableCount, total: model.rows.count))                    .paperMeta(12)                    .accessibilityIdentifier("rejected-retry-limit")            }        }        .padding(.top, 16)    }    /// What `Retry all` can actually move, when it is not all of it.    static func retryLimit(retryable: Int, total: Int) -> String {        let stuck = total - retryable        return ShellLines.line("devices", stuck == 1 ? "rejected.retry_limit.one" : "rejected.retry_limit.many", ["n": "\(stuck)"])    }}/// One parked write.private struct RejectedRow: View {    let row: RejectedModel.Row    var body: some View {        VStack(alignment: .leading, spacing: 4) {            Text(row.table).paperBody(15)            Text(row.reason).paperRed(13)            Text("\(row.direction) · \(row.stuckSince)").paperMeta(12)        }        .frame(maxWidth: .infinity, alignment: .leading)        .accessibilityIdentifier("rejected-row")    }}