Cotton code
146 lines · 6.7 KB · SwiftRaw
// YOU (assets/design/albums/DECISIONS.md "You", the family's order): the card, Albums' own rows (Faces, Bin, Privacy),// then Sync, Your Claude, Storage, Help and About as every Cotton app has them (the shared Settings parts). And, in// the Dev build only, what the pass measured (`AlbumsLookedScreen`), for the lane's report.#if os(iOS)import CottonKitimport CottonWritingimport SwiftUI@MainActorextension SettingsLook {    static var albums: SettingsLook {        SettingsLook(            ink: Olive.ink, quiet: Olive.quiet, rule: Olive.rule, ground: Olive.ground,            body: AlbumsType.body, small: AlbumsType.line,            heading: { AnyView(Text(verbatim: $0).font(AlbumsType.heading).foregroundStyle(Olive.quiet)) },            act: { words, id, enabled, tap in                AnyView(Button(action: tap) { Text(verbatim: words) }.buttonStyle(AlbumsPillStyle()).disabled(!enabled).opacity(enabled ? 1 : 0.45)                    .accessibilityIdentifier(id))            },            choice: { words, on, id, enabled, tap in                AnyView(Button(action: tap) {                    Text(verbatim: words).font(AlbumsType.line).foregroundStyle(on ? Olive.onAccent : Olive.ink)                        .padding(.horizontal, 14).frame(minHeight: 36)                        .background(Capsule().fill(on ? Olive.accent : .clear))                        .overlay(Capsule().stroke(on ? .clear : Olive.rule, lineWidth: 1))                }                .buttonStyle(.plain).disabled(!enabled).accessibilityIdentifier(id))            },            danger: Olive.ink,            title: AlbumsType.title        )    }}struct AlbumsYouScreen: View {    let model: AlbumsModel    @State private var home = SettingsHome()    @State private var answer: AlbumsYou?    @Environment(\.cottonSync) private var sync    var body: some View {        AlbumsPage(tag: "albums-you") {            if home.place != nil {                AlbumsBar(back: AlbumsWords.line("tabs.you")) { home.back {} }.padding(.horizontal, -Olive.side)                AlbumsTitle(text: home.title(own: { _ in nil }) ?? "")            } else {                Spacer().frame(height: 8)                AlbumsTitle(text: AlbumsWords.line("tabs.you"))            }            page.padding(.top, 6)        }        .task(id: sync?.revision ?? 0) { await home.read(model.core) }        .task(id: model.changed) { answer = try? await model.book.you() }        .onChange(of: model.tab) { _, now in if now == .you { Task { answer = try? await model.book.you() } } }        .onChange(of: model.placed) { _, _ in if model.tab == .you { home.place = SyncSeenOpens.take() ? .sync : nil } }    }    @ViewBuilder private var page: some View {        switch home.place {        case nil:            SettingsHomeList(home: home, look: .albums, own: own) {                SettingsYouCard(home: home, core: model.core, look: .albums, pageTitle: AlbumsWords.line("tabs.you")) { model.tell($0) }            }            if let first = answer?.firstLook {                AlbumsHeading(first.heading)                VStack(spacing: 0) {                    ForEach(first.rows) { row in                        HStack(alignment: .firstTextBaseline, spacing: 12) {                            Text(verbatim: row.label).font(AlbumsType.body).foregroundStyle(Olive.ink)                                .fixedSize(horizontal: false, vertical: true)                            Spacer(minLength: 8)                            Text(verbatim: row.value ?? "").font(AlbumsType.mono(15, .body)).foregroundStyle(Olive.quiet)                                .multilineTextAlignment(.trailing)                        }                        .padding(.vertical, 11)                        .overlay(alignment: .bottom) { AlbumsRule() }                        .accessibilityElement(children: .combine)                        .accessibilityIdentifier("albums-first-\(row.row)")                    }                }            }            if let privacy = answer?.privacy {                Text(verbatim: privacy).font(AlbumsType.small).foregroundStyle(Olive.quiet).fixedSize(horizontal: false, vertical: true).padding(.top, 16)                    .accessibilityIdentifier("albums-you-privacy")            }        case .profile?:            SettingsProfileHead(home: home, look: .albums)            SettingsProfileFoot(home: home, core: model.core, look: .albums, said: { model.tell($0) }) {                home.place = nil                model.place(.albums)            }        case .own?:            EmptyView()        case let shared?:            SettingsSharedPage(place: shared, home: home, core: model.core, look: .albums, said: { model.tell($0) }) {                Task { await home.read(model.core) }            }        }    }    /// Albums' own rows, in the core's words: Faces (on with its count, or off), the Bin.    private var own: [SettingsOwnRow] {        var rows: [SettingsOwnRow] = (answer?.rows ?? []).filter { !(AlbumsBook.lookOnly && $0.row == "bin") }.map { row in            SettingsOwnRow(id: row.row, label: row.label, line: row.value) {                switch row.row {                case "faces":                    if model.pass.faces, let ask = answer?.facesOff { model.askFacesOff(ask) } else { Task { await model.setFaces(true) } }                case "bin": model.open(.bin(back: AlbumsWords.line("tabs.you")))                default: break                }            }        }        #if COTTON_DEV        let c = model.pass.counts        rows.append(SettingsOwnRow(id: "looked", label: "Looked", line: "\(c.looked.formatted()) of \(c.photos.formatted())") { model.open(.looked) })        #endif        return rows    }}/// What the pass found and how fast, as measured on this phone: the lane's numbers for the report (Dev only).struct AlbumsLookedScreen: View {    let model: AlbumsModel    @State private var lines: [(String, String)] = []    var body: some View {        VStack(alignment: .leading, spacing: 0) {            AlbumsBar(back: AlbumsWords.line("tabs.you"), tap: model.back)            AlbumsPage(tag: "albums-looked") {                AlbumsTitle(text: "Looked")                ForEach(lines, id: \.0) { line in                    HStack(alignment: .firstTextBaseline) {                        Text(verbatim: line.0).font(AlbumsType.line).foregroundStyle(Olive.quiet)                        Spacer()                        Text(verbatim: line.1).font(AlbumsType.figure).foregroundStyle(Olive.ink).accessibilityIdentifier("albums-looked-\(line.0)")                    }                    .padding(.vertical, 8)                    AlbumsRule()                }            }        }        .task(id: model.pass.revision) { lines = await AlbumsMeasure.lines() }    }}#endif