106 lines · 5.0 KB · SwiftRaw
// PEOPLE (assets/design/albums/albums.html "People"; DECISIONS "People"): faces are on by default (the coordinator,// 27 Nov), said once at first run with a switch; turned off, People says the four facts before the choice, and both// answers are the same size. On: named people first with their counts, then "Who is this?" groups by size, each with// Name. Only groups of 5 photos or more are shown; every word and count is the core's answer.#if os(iOS)import CottonKitimport SwiftUIstruct AlbumsPeopleScreen: View { @Bindable var model: AlbumsModel @State private var answer: AlbumsPeople? var body: some View { AlbumsPage(tag: "albums-people", pull: read) { AlbumsTitle(text: answer?.title ?? AlbumsWords.line("people.title")).padding(.top, 8) if let answer { if let off = answer.off { offPage(off) } else { onPage(answer) } } } .task(id: model.changed) { await read() } .onChange(of: model.tab) { _, now in if now == .people { Task { await read() } } } } @ViewBuilder private func offPage(_ off: AlbumsPeople.Off) -> some View { Text(verbatim: off.lead).font(AlbumsType.lead).foregroundStyle(Olive.ink).fixedSize(horizontal: false, vertical: true).padding(.top, 14) VStack(spacing: 0) { AlbumsRule() ForEach(off.points, id: \.self) { point in HStack(alignment: .firstTextBaseline, spacing: 10) { Circle().stroke(Olive.ink, lineWidth: 1.2).frame(width: 7, height: 7).accessibilityHidden(true) Text(verbatim: point).font(AlbumsType.body).foregroundStyle(Olive.ink).fixedSize(horizontal: false, vertical: true) Spacer(minLength: 0) } .padding(.vertical, 11) AlbumsRule() } } .padding(.top, 16) HStack(spacing: 10) { Button(off.notNow) { model.place(.albums) }.buttonStyle(AlbumsOutlineButtonStyle()).accessibilityIdentifier("albums-faces-not-now") Button(off.turnOn) { Task { await model.setFaces(true) } }.buttonStyle(AlbumsOutlineButtonStyle()).accessibilityIdentifier("albums-faces-on") } .padding(.top, 28) } @ViewBuilder private func onPage(_ answer: AlbumsPeople) -> some View { if let head = answer.head { Text(verbatim: head).font(AlbumsType.body).foregroundStyle(Olive.quiet).padding(.top, 4) } if !answer.named.isEmpty { LazyVGrid(columns: Array(repeating: GridItem(.flexible(), spacing: 8), count: 4), spacing: 14) { ForEach(answer.named) { person in VStack(spacing: 3) { AlbumsFaceRound(id: person.cover, side: 62) Text(verbatim: person.name).font(AlbumsType.sans(14, .semibold, .subheadline)).foregroundStyle(Olive.ink).lineLimit(1) Text(verbatim: person.count).font(AlbumsType.mono(12, .caption1)).foregroundStyle(Olive.quiet) } .accessibilityElement(children: .combine) .accessibilityIdentifier("albums-person-\(person.id)") } } .padding(.top, 16) } if let who = answer.who { AlbumsHeading(who.heading) Rectangle().fill(Olive.ink).frame(height: 2) ForEach(who.groups) { group in HStack(alignment: .center, spacing: 12) { VStack(alignment: .leading, spacing: 8) { HStack(spacing: -8) { ForEach(group.covers, id: \.self) { AlbumsFaceRound(id: $0, side: 44) } } Text(verbatim: group.line).font(AlbumsType.body).foregroundStyle(Olive.quiet) } Spacer() Button(group.name) { model.sheet = .name(group: group.id) } .buttonStyle(AlbumsActStyle()) .accessibilityIdentifier("albums-name-\(group.id)") } .padding(.vertical, 12) .overlay(alignment: .bottom) { AlbumsRule() } } } if let looking = answer.looking { Text(verbatim: looking).font(AlbumsType.line).foregroundStyle(Olive.quiet).fixedSize(horizontal: false, vertical: true).padding(.top, 16) .accessibilityIdentifier("albums-people-looking") } } private func read() async { do { answer = try await model.book.people() } catch { model.refused(error) } }}/// A person's round: the photo they are in (the core's crop once it lands), on the well while it loads.struct AlbumsFaceRound: View { let id: String? let side: CGFloat var body: some View { ZStack { Circle().fill(Olive.well) if let id { AlbumsTile(id: id, side: side).clipShape(Circle()) } } .frame(width: side, height: side) .overlay(Circle().stroke(Olive.ground, lineWidth: 2)) .accessibilityHidden(true) }}#endif