// YOU'S PAGES, in the Warm look (you-grouped.html; CONTRACT.md "You,
// grouped"), as Android's YouPages: the frame each page stands in (Back, its
// title, then what it holds, scrolling), the parts they share, and the pages
// that read for themselves: Your Claude (`assistant.screen`'s `groups` and
// `reading`), Storage, Help and feedback, and About (`shell.settings`).
// Every word is the core's or a kit line; these only lay it out.
#if os(iOS)
import CottonKit
import SwiftUI
// MARK: the parts
/// A page of You: Back, its title, then `content`, scrolling.
struct ChatYouPageFrame: View {
let title: String?
let id: String
/// None on a main tab's own page: the title stands where Back would.
let back: (() -> Void)?
@ViewBuilder var content: () -> Content
@Environment(\.chatLook) private var look
var body: some View {
ScrollView {
VStack(alignment: .leading, spacing: 0) {
if let back {
HStack {
WarmRound(symbol: "chevron.left", label: ShellLines.line("words", "back"), id: "\(id)-back", tap: back)
Spacer()
}
.padding(.leading, -6)
}
if let title {
Text(verbatim: title)
.font(look.font(back == nil ? 34 : 30, .bold))
.kerning(-0.6)
.foregroundStyle(look.colours.text)
.fixedSize(horizontal: false, vertical: true)
.accessibilityAddTraits(.isHeader)
.padding(.top, 12)
.padding(.bottom, 4)
}
content()
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.horizontal, Warm.side)
.padding(.top, 8)
.padding(.bottom, 32)
}
.scrollIndicators(.hidden)
.background(look.colours.ground.ignoresSafeArea())
.accessibilityIdentifier(id)
}
}
/// A row that opens a page: its mark on a chip, its name, how it stands, the chevron.
struct ChatYouGoRow: View {
let symbol: String
let name: String
let line: String?
let id: String
let tap: () -> Void
@Environment(\.chatLook) private var look
var body: some View {
Button(action: tap) {
HStack(spacing: 13) {
Image(systemName: symbol)
.font(.system(size: 17 * min(look.scale, 1.3), weight: .regular))
.foregroundStyle(look.colours.text)
.frame(width: 38 * min(look.scale, 1.3), height: 38 * min(look.scale, 1.3))
.background(Circle().fill(look.colours.bar))
VStack(alignment: .leading, spacing: 1) {
Text(verbatim: name).font(look.font(17, .semibold)).foregroundStyle(look.colours.text)
if let line, !line.isEmpty {
Text(verbatim: line).font(look.font(14)).foregroundStyle(look.colours.dim)
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
Image(systemName: "chevron.right")
.font(.system(size: 13 * min(look.scale, 1.3), weight: .semibold))
.foregroundStyle(look.colours.faint)
}
.frame(maxWidth: .infinity, minHeight: 56, alignment: .leading)
.padding(.vertical, 5)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text(verbatim: [name, line].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: ", ")))
.accessibilityAddTraits(.isButton)
.accessibilityIdentifier(id)
}
}
/// A row drawn like `ChatYouGoRow` that opens nothing: no chevron, not a button (You's Mail row while Post is not on
/// the phone and not yet listed).
struct ChatYouStillRow: View {
let symbol: String
let name: String
let line: String?
let id: String
@Environment(\.chatLook) private var look
var body: some View {
HStack(spacing: 13) {
Image(systemName: symbol)
.font(.system(size: 17 * min(look.scale, 1.3), weight: .regular))
.foregroundStyle(look.colours.text)
.frame(width: 38 * min(look.scale, 1.3), height: 38 * min(look.scale, 1.3))
.background(Circle().fill(look.colours.bar))
VStack(alignment: .leading, spacing: 1) {
Text(verbatim: name).font(look.font(17, .semibold)).foregroundStyle(look.colours.text)
if let line, !line.isEmpty {
Text(verbatim: line).font(look.font(14)).foregroundStyle(look.colours.dim)
.fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
}
.frame(maxWidth: .infinity, minHeight: 56, alignment: .leading)
.padding(.vertical, 5)
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text(verbatim: [name, line].compactMap { $0 }.filter { !$0.isEmpty }.joined(separator: ", ")))
.accessibilityIdentifier(id)
}
}
/// Words that tell, quiet, under a part of a page.
struct ChatYouQuiet: View {
let words: String
@Environment(\.chatLook) private var look
var body: some View {
Text(verbatim: words).font(look.font(14)).foregroundStyle(look.colours.dim)
.fixedSize(horizontal: false, vertical: true)
}
}
/// A field's small label (Your name, Phone number).
struct ChatYouSmall: View {
let words: String
@Environment(\.chatLook) private var look
var body: some View {
Text(verbatim: words).font(look.font(13)).foregroundStyle(look.colours.dim)
}
}
/// A block on the chip, or on the person's own tint.
struct ChatYouBlock: View {
var tint = false
@ViewBuilder var content: () -> Content
@Environment(\.chatLook) private var look
var body: some View {
VStack(alignment: .leading, spacing: 6, content: content)
.padding(.horizontal, 14).padding(.vertical, 12)
.frame(maxWidth: .infinity, alignment: .leading)
.background(RoundedRectangle(cornerRadius: 20, style: .continuous).fill(tint ? look.colours.bubbleOut : look.colours.bar))
.padding(.vertical, 8)
}
}
/// The act at a page's foot: the accent for the main one, else the chip (in the danger colour for Sign out).
struct ChatYouFootButton: View {
let words: String
let id: String
var main = true
var danger = false
var enabled = true
let tap: () -> Void
@Environment(\.chatLook) private var look
var body: some View {
Button(action: tap) {
Text(verbatim: words)
.font(look.font(16, .semibold))
.foregroundStyle(main ? look.colours.onAccent : (danger ? look.colours.danger : look.colours.text))
.multilineTextAlignment(.center)
.padding(.horizontal, 16).padding(.vertical, 12)
.frame(maxWidth: .infinity, minHeight: 50)
.background(Capsule().fill(main ? look.colours.accent : look.colours.bar))
.contentShape(Capsule())
}
.buttonStyle(.plain)
.disabled(!enabled)
.opacity(enabled ? 1 : 0.45)
.accessibilityIdentifier(id)
}
}
/// A switch with its words and what it means.
struct ChatYouSwitch: View {
let words: String
let line: String
@Binding var on: Bool
let id: String
let set: (Bool) -> Void
@Environment(\.chatLook) private var look
var body: some View {
Toggle(isOn: Binding(get: { on }, set: { on = $0; set($0) })) {
VStack(alignment: .leading, spacing: 2) {
Text(verbatim: words).font(look.font(16)).foregroundStyle(look.colours.text)
Text(verbatim: line).font(look.font(13)).foregroundStyle(look.colours.dim).fixedSize(horizontal: false, vertical: true)
}
}
.tint(look.colours.accent)
.frame(minHeight: 56)
.accessibilityIdentifier(id)
}
}
// MARK: Your Claude
/// YOUR CLAUDE: one page of groups a person knows. Connected, it says so and
/// never offers Connect; then how Claude reads now, standing ("Claude can
/// read any time", with Ask each time instead) or for a while ("until 10:30",
/// with Stop now); then what it may read, each group On, Ask each time or
/// Off; Disconnect quietly at the foot. Not connected: the promise and
/// Connect Claude. Widening (On, Connect) goes behind the phone's lock; the
/// rest do not.
struct ChatYouClaudePage: View {
let core: any CottonCalling
let back: () -> Void
@Environment(\.chatLook) private var look
@Environment(\.cottonSync) private var sync
@State private var screen: JSONValue?
@State private var asked = 0
@State private var busy = false
/// What an act said (Connect's address to add in Claude, a refusal), under the acts.
@State private var said: String?
var body: some View {
let mine = YourClaude(screen)
ChatYouPageFrame(title: mine?.heading, id: "you-claude-page", back: back) {
if let mine { page(mine) }
}
.task(id: "\(sync?.revision ?? 0)-\(asked)") {
if let read = try? await core.callJSON(CottonMethod.assistantScreen) { screen = read }
}
}
@ViewBuilder private func page(_ mine: YourClaude) -> some View {
let reading = mine.reading
if let connected = reading?.connected {
VStack(alignment: .leading, spacing: 2) {
Text(verbatim: connected).font(look.font(17, .semibold)).foregroundStyle(look.colours.text)
ForEach(Array(mine.connections.enumerated()), id: \.offset) { _, one in ChatYouQuiet(words: one) }
}
.frame(maxWidth: .infinity, alignment: .leading)
.padding(.vertical, 4)
.accessibilityElement(children: .combine)
.accessibilityIdentifier("you-claude-connected")
} else {
ChatYouQuiet(words: mine.promise).padding(.vertical, 4)
ForEach(Array(mine.connections.enumerated()), id: \.offset) { _, one in
Text(verbatim: one).font(look.font(15)).foregroundStyle(look.colours.text)
.accessibilityIdentifier("you-claude-waiting")
}
if let none = mine.none { ChatYouQuiet(words: none).accessibilityIdentifier("you-claude-none") }
if let connect = mine.connect {
ChatYouFootButton(words: connect, id: "you-claude-connect", enabled: !busy) { Task { await connectClaude() } }
.padding(.top, 10)
}
}
if let reading, let title = reading.title {
ChatYouBlock {
Text(verbatim: title).font(look.font(20, .bold)).kerning(-0.2).foregroundStyle(look.colours.text)
.fixedSize(horizontal: false, vertical: true)
.accessibilityIdentifier("you-claude-state-title")
if let line = reading.line { ChatYouQuiet(words: line) }
if let act = reading.act {
// On the page's ground, so it stands out of the chip it sits on.
Button {
guard !busy else { return }
Task { await call(act.id == "stop" ? CottonMethod.assistantStop : CottonMethod.assistantAskEachTime) }
} label: {
Text(verbatim: act.label)
.font(look.font(14, .semibold))
.foregroundStyle(look.colours.text)
.padding(.horizontal, 16)
.frame(minHeight: 40)
.background(Capsule().fill(look.colours.ground))
.contentShape(Capsule())
}
.buttonStyle(.plain)
.accessibilityIdentifier("you-claude-act-\(act.id)")
.padding(.top, 4)
}
}
.accessibilityElement(children: .contain)
.accessibilityIdentifier("you-claude-state")
}
if let said {
ChatYouBlock(tint: true) {
Text(verbatim: said).font(look.font(15)).foregroundStyle(look.colours.bubbleOutText)
.fixedSize(horizontal: false, vertical: true)
}
.accessibilityElement(children: .combine)
.accessibilityIdentifier("you-claude-said")
}
if !mine.groups.isEmpty {
WarmHeading(words: mine.mayRead)
ForEach(mine.groups, id: \.id) { group in
ViewThatFits(in: .horizontal) {
HStack(spacing: 10) {
named(group)
Spacer(minLength: 0)
segments(group)
}
// At a large text size the three choices wrap under the group's name, never wider than the page.
VStack(alignment: .leading, spacing: 8) {
named(group)
segments(group, wrapping: true)
}
}
.padding(.vertical, 8)
.accessibilityElement(children: .contain)
.accessibilityIdentifier("you-claude-group-\(group.id)")
}
if let note = reading?.note { ChatYouQuiet(words: note).padding(.top, 4).accessibilityIdentifier("you-claude-note") }
}
if let disconnect = reading?.disconnect {
Button {
guard !busy else { return }
Task { await call(CottonMethod.assistantRemove) }
} label: {
Text(verbatim: disconnect).font(look.font(16)).foregroundStyle(look.colours.danger)
.frame(maxWidth: .infinity, minHeight: 48, alignment: .leading)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.padding(.top, 16)
.accessibilityIdentifier("you-claude-disconnect")
}
}
private func named(_ group: YourClaude.Group) -> some View {
VStack(alignment: .leading, spacing: 1) {
Text(verbatim: group.label).font(look.font(16, .medium)).foregroundStyle(look.colours.text)
Text(verbatim: group.line).font(look.font(13)).foregroundStyle(look.colours.dim)
}
.fixedSize(horizontal: false, vertical: true)
}
/// Three choices on one chip, the one standing inked; `wrapping`, each its own chip, wrapping to the page.
@ViewBuilder private func segments(_ group: YourClaude.Group, wrapping: Bool = false) -> some View {
if wrapping {
SettingsFlow(spacing: 6) { choices(group, apart: true) }
} else {
HStack(spacing: 2) { choices(group, apart: false) }
.padding(3)
.background(Capsule().fill(look.colours.bar))
}
}
private func choices(_ group: YourClaude.Group, apart: Bool) -> some View {
ForEach(group.choices, id: \.access) { choice in
Button {
guard !busy, !choice.on else { return }
Task { await scope(group, to: choice.access) }
} label: {
Text(verbatim: choice.label)
.font(look.font(13, choice.on ? .semibold : .regular))
.foregroundStyle(choice.on ? look.colours.ground : look.colours.dim)
.lineLimit(apart ? nil : 1)
// In one row each choice keeps its whole words; where they cannot, the row wraps instead.
.fixedSize(horizontal: !apart, vertical: false)
.padding(.horizontal, 10).padding(.vertical, 7)
.background(Capsule().fill(choice.on ? look.colours.text : (apart ? look.colours.bar : Color.clear)))
.contentShape(Capsule())
}
.buttonStyle(.plain)
.accessibilityAddTraits(choice.on ? [.isButton, .isSelected] : .isButton)
.accessibilityLabel(Text(verbatim: "\(group.label), \(choice.label)"))
.accessibilityIdentifier("you-claude-\(group.id)-\(choice.access)")
}
}
/// A group's choice: On (where it widens) behind the phone's lock; Ask each time and Off at once.
private func scope(_ group: YourClaude.Group, to access: String) async {
if access == "on", group.needsLock {
busy = true
let id = group.id
let handed = await VaultAccess().handing(CottonMethod.assistantScope, through: core) { key in
YourClaude.SignedGroupScope(group: id, access: access, privateKey: key)
}
take(handed, sayDone: false)
busy = false
asked += 1
} else {
await call(CottonMethod.assistantScope, YourClaude.GroupScope(group: group.id, access: access), sayDone: false)
}
}
/// Connect Claude: behind the phone's lock; the core says where to add it.
private func connectClaude() async {
busy = true
let handed = await VaultAccess().handing(CottonMethod.assistantConnect, through: core) { key in YourClaude.Signed(privateKey: key) }
take(handed, sayDone: true)
busy = false
asked += 1
}
private func take(_ handed: VaultHanding, sayDone: Bool) {
switch handed {
case .answered(let answered): said = sayDone ? answered.text("said") : nil
case .cancelled: return
case .noPresence: said = ShellLines.line("unlock", "no_presence")
case .refused(let words): said = words
}
}
private func call(_ method: String, _ request: some Encodable & Sendable = EmptyRequest(), sayDone: Bool = true) async {
busy = true
do {
let answered = try await core.callJSON(method, request)
said = sayDone ? answered.text("said") : nil
} catch {
said = (error as? CottonCallError)?.message ?? ActionRefused.words(for: error)
}
busy = false
asked += 1
}
}
// MARK: Storage
/// `chat.storage`'s answer: what each chat keeps on this phone, measured, largest first.
struct ChatStorageAnswer: Decodable, Equatable, Sendable {
struct Part: Decodable, Equatable, Sendable {
let id: String
let label: String
let bytes: Int64
let said: String
}
struct Chat: Decodable, Equatable, Sendable {
let thread: String
let name: String
var picture: ChatAvatar?
let bytes: Int64
let said: String
let parts: [Part]
/// Free this chat, in Free up space's shape: its label, what it frees, the line saying what stays, the ask.
let free: SettingsAnswer.FreeUp
}
let title: String
let chats: [Chat]
var none: String?
}
private struct ChatStorageFreeAsk: Encodable, Sendable {
let thread: String
let expected: Int64
}
/// STORAGE: what Comms keeps on this phone, measured (`shell.settings`'
/// `storage`): the whole, the shared four (Your data, Photos and files,
/// Downloads, Other) as a bar and as lines, and Free up space, which says
/// what it frees and asks before anything goes. Under them, By chat
/// (`chat.storage`): each chat with what it keeps, largest first; a tap
/// opens its breakdown (the kinds it holds, then Free this chat, asked
/// first, with the line saying what stays).
struct ChatYouStoragePage: View {
let core: any CottonCalling
let storage: SettingsAnswer.Storage?
let said: (String) -> Void
let again: () -> Void
let back: () -> Void
@Environment(\.chatLook) private var look
@State private var asking = false
@State private var byChat: ChatStorageAnswer?
/// The chat whose breakdown stands, by thread.
@State private var open: String?
@State private var freeing = false
@State private var reads = 0
private var tints: [Color] { [look.colours.accent, look.colours.text, look.colours.dim, look.colours.faint] }
private var opened: ChatStorageAnswer.Chat? { open.flatMap { thread in byChat?.chats.first { $0.thread == thread } } }
var body: some View {
Group {
if let chat = opened {
breakdown(chat)
} else {
whole
}
}
.task(id: reads) {
guard let read = try? await core.call(ChatYouMethod.storage, EmptyRequest(), as: ChatStorageAnswer.self) else { return }
byChat = read
}
}
// MARK: the whole
private var whole: some View {
ChatYouPageFrame(title: storage?.title, id: "you-storage-page", back: back) {
if let storage {
if let whole = storage.said {
Text(verbatim: whole).font(look.font(30, .bold)).kerning(-0.6).foregroundStyle(look.colours.text)
.padding(.top, 6)
.accessibilityIdentifier("you-storage-total")
}
ChatYouQuiet(words: ChatWords.line("you.storage_kept"))
bar(storage.parts.map { ($0.id, max($0.bytes ?? 0, 0)) })
ForEach(Array(storage.parts.enumerated()), id: \.element.id) { at, part in
partLine(label: part.label, line: part.line, said: part.said, tint: tints[at % tints.count], id: "settings-storage-\(part.id)")
}
ChatYouQuiet(words: ChatWords.line("you.storage_measured")).padding(.top, 4)
if let free = storage.freeUp {
if let line = free.line { freeLine(line) }
ChatYouFootButton(words: free.label, id: "settings-free-up", enabled: free.bytes > 0) { asking = true }
.padding(.top, 8)
}
}
if let byChat { chats(byChat) }
}
.confirmDecision(
isPresented: $asking,
title: storage?.freeUp?.ask ?? "",
message: storage?.freeUp?.askBody ?? "",
confirmLabel: storage?.freeUp?.confirm ?? "",
identifier: "settings-free-up-confirm"
) {
guard let bytes = storage?.freeUp?.bytes, bytes > 0 else { return }
Task {
if let words = await SettingsAnswer.freeUp(core, bytes: bytes) { said(words) }
reads += 1
again()
}
}
}
/// By chat: one line each, its picture, its name and what it keeps, largest first, as the core orders them.
@ViewBuilder
private func chats(_ answer: ChatStorageAnswer) -> some View {
WarmHeading(words: answer.title)
if let none = answer.none {
ChatYouQuiet(words: none).accessibilityIdentifier("you-storage-chats-none")
}
ForEach(answer.chats, id: \.thread) { chat in
Button { open = chat.thread } label: {
HStack(spacing: 12) {
ChatAvatarView(avatar: chat.picture ?? ChatAvatar(photo: nil, initials: String(chat.name.prefix(1)), tint: 0), side: 34 * min(look.scale, 1.3))
.accessibilityHidden(true)
Text(verbatim: chat.name).font(look.font(16, .medium)).foregroundStyle(look.colours.text)
.frame(maxWidth: .infinity, alignment: .leading)
Text(verbatim: chat.said).font(look.font(15)).foregroundStyle(look.colours.dim)
Image(systemName: "chevron.right")
.font(.system(size: 13 * min(look.scale, 1.3), weight: .semibold))
.foregroundStyle(look.colours.faint)
.accessibilityHidden(true)
}
.frame(maxWidth: .infinity, minHeight: 52, alignment: .leading)
.contentShape(Rectangle())
}
.buttonStyle(.plain)
.accessibilityElement(children: .ignore)
.accessibilityLabel(Text(verbatim: "\(chat.name), \(chat.said)"))
.accessibilityAddTraits(.isButton)
.accessibilityIdentifier("you-storage-chat-\(chat.thread)")
}
}
// MARK: one chat
private func breakdown(_ chat: ChatStorageAnswer.Chat) -> some View {
ChatYouPageFrame(title: chat.name, id: "you-storage-chat-page", back: { open = nil }) {
Text(verbatim: chat.said).font(look.font(30, .bold)).kerning(-0.6).foregroundStyle(look.colours.text)
.padding(.top, 6)
.accessibilityIdentifier("you-storage-chat-total")
bar(chat.parts.map { ($0.id, $0.bytes) })
ForEach(Array(chat.parts.enumerated()), id: \.element.id) { at, part in
partLine(label: part.label, line: nil, said: part.said, tint: tints[at % tints.count], id: "you-storage-chat-\(part.id)")
}
ChatYouQuiet(words: ChatWords.line("you.storage_measured")).padding(.top, 4)
if let line = chat.free.line { freeLine(line) }
ChatYouFootButton(words: chat.free.label, id: "you-storage-chat-free", enabled: chat.free.bytes > 0) { freeing = true }
.padding(.top, 8)
}
.confirmDecision(
isPresented: $freeing,
title: chat.free.ask ?? "",
message: chat.free.askBody ?? "",
confirmLabel: chat.free.confirm ?? "",
identifier: "you-storage-chat-free-confirm"
) {
let ask = ChatStorageFreeAsk(thread: chat.thread, expected: chat.free.bytes)
guard ask.expected > 0 else { return }
Task {
do {
if let words = try await core.callJSON(ChatYouMethod.storageFree, ask).text("said") { said(words) }
} catch {
said((error as? CottonCallError)?.message ?? ActionRefused.words(for: error))
}
reads += 1
again()
}
}
}
// MARK: the parts
private func partLine(label: String, line: String?, said: String, tint: Color, id: String) -> some View {
HStack(spacing: 10) {
Circle().fill(tint).frame(width: 10, height: 10).accessibilityHidden(true)
VStack(alignment: .leading, spacing: 1) {
Text(verbatim: label).font(look.font(16)).foregroundStyle(look.colours.text)
if let line {
Text(verbatim: line).font(look.font(13)).foregroundStyle(look.colours.dim).fixedSize(horizontal: false, vertical: true)
}
}
.frame(maxWidth: .infinity, alignment: .leading)
Text(verbatim: said).font(look.font(15)).foregroundStyle(look.colours.dim)
}
.frame(minHeight: 40)
.padding(.vertical, 3)
.accessibilityElement(children: .combine)
.accessibilityIdentifier(id)
}
private func freeLine(_ line: String) -> some View {
ChatYouBlock(tint: true) {
Text(verbatim: line).font(look.font(15)).foregroundStyle(look.colours.bubbleOutText)
.fixedSize(horizontal: false, vertical: true)
}
.accessibilityElement(children: .combine)
.padding(.top, 8)
}
/// The parts by what each measures, side by side on one rounded bar.
private func bar(_ parts: [(id: String, bytes: Int64)]) -> some View {
let total = max(parts.reduce(Int64(0)) { $0 + $1.bytes }, 1)
return GeometryReader { box in
let room = box.size.width - CGFloat(max(parts.count - 1, 0)) * 2
HStack(spacing: 2) {
ForEach(Array(parts.enumerated()), id: \.offset) { at, part in
if part.bytes > 0 {
Rectangle().fill(tints[at % tints.count]).frame(width: max(room * CGFloat(part.bytes) / CGFloat(total), 2))
}
}
Spacer(minLength: 0)
}
}
.frame(height: 12)
.clipShape(Capsule())
.padding(.vertical, 10)
.accessibilityHidden(true)
}
}
// MARK: Help and feedback
/// HELP AND FEEDBACK: Something's wrong, Share a report (the whole report
/// shown before anything goes), and Write to us.
struct ChatYouHelpPage: View {
let core: any CottonCalling
let help: SettingsAnswer.Help?
let said: (String) -> Void
let back: () -> Void
@Environment(\.chatLook) private var look
@State private var report: SettingsReport?
/// The report Share was pressed on, shared once its preview has gone.
@State private var sharing: SettingsReport?
var body: some View {
ChatYouPageFrame(title: help?.title, id: "you-help-page", back: back) {
if let share = help?.share {
WarmHeading(words: ChatWords.line("you.help_wrong"))
Text(verbatim: share.label).font(look.font(16, .medium)).foregroundStyle(look.colours.text)
if let line = share.line { ChatYouQuiet(words: line).padding(.vertical, 4) }
ChatYouFootButton(words: share.label, id: "settings-share-report", main: false) { Task { await readReport() } }
.padding(.top, 10)
}
WarmHeading(words: ChatWords.line("you.tell_us"))
ChatYouGoRow(symbol: "envelope", name: ChatWords.line("you.write_us"), line: ChatWords.line("you.write_us_line"), id: "you-write-us") {
// The shared Report a problem: what the person writes, read whole before it goes.
NotificationCenter.default.post(name: .cottonReportProblem, object: nil)
}
// The privacy policy and Help and contact, each opening its page on cottondb.com (both stores ask), as
// every web link in Comms does: in Cotton Sites when it is on the phone, else Safari's sheet (ChatLinks.swift).
ForEach(help?.links ?? []) { link in
ChatYouGoRow(symbol: link.id == "privacy" ? "hand.raised" : "questionmark.circle", name: link.label, line: nil, id: "settings-link-\(link.id)") {
if let url = URL(string: link.url) { ChatLinks.shared.open(url) }
}
}
}
// A card, never a sheet (NoBottomSheetsTests): raised at the window, over the app, in its look.
.cottonCard(item: $report, detents: [.tall], onDismiss: shareAfterPreview) { shown in
if let share = help?.share {
SettingsReportSheet(share: share, text: shown.text, look: .warm(look), close: { report = nil }) {
sharing = shown
report = nil
}
}
}
}
private func readReport() async {
do {
report = try await SettingsReport.read(core)
} catch {
said((error as? CottonCallError)?.message ?? ActionRefused.words(for: error))
}
}
private func shareAfterPreview() {
guard let shown = sharing else { return }
sharing = nil
shown.share()
}
}
// MARK: About
/// ABOUT: the app and its version, then for the curious the account's facts
/// as the core says them (Account with its short id, the last sync, Items on
/// this phone, the last error), and Copy these details.
struct ChatYouAboutPage: View {
let about: SettingsAnswer.About?
let said: (String) -> Void
let back: () -> Void
@Environment(\.chatLook) private var look
/// The app's own name, as the phone shows it under its icon.
private var name: String {
(Bundle.main.object(forInfoDictionaryKey: "CFBundleDisplayName") as? String)
?? (Bundle.main.object(forInfoDictionaryKey: "CFBundleName") as? String) ?? ""
}
private var facts: [SettingsAnswer.Fact] { (about?.facts ?? []).filter { $0.id != "app" } }
var body: some View {
ChatYouPageFrame(title: nil, id: "you-about-page", back: back) {
VStack(alignment: .leading, spacing: 0) { content }
.accessibilityElement(children: .contain)
.accessibilityIdentifier("settings-about")
}
}
@ViewBuilder private var content: some View {
VStack(spacing: 4) {
Text(verbatim: String(name.prefix(1)))
.font(look.font(30, .bold)).foregroundStyle(look.colours.onAccent)
.frame(width: 72, height: 72)
.background(RoundedRectangle(cornerRadius: 22, style: .continuous).fill(look.colours.accent))
.accessibilityHidden(true)
Text(verbatim: name).font(look.font(22, .bold)).foregroundStyle(look.colours.text)
.padding(.top, 6)
.accessibilityAddTraits(.isHeader)
if let version = about?.version {
Text(verbatim: "\(version.label) \(version.said)")
.font(look.font(14)).foregroundStyle(look.colours.dim)
.multilineTextAlignment(.center)
.accessibilityIdentifier("settings-about-version")
}
}
.frame(maxWidth: .infinity)
.padding(.top, 18).padding(.bottom, 6)
if !facts.isEmpty {
WarmHeading(words: ChatWords.line("you.about_curious"))
ForEach(Array(facts.enumerated()), id: \.offset) { _, fact in
SettingsPartRow(label: fact.label, said: fact.said, line: nil, look: .warm(look), id: "settings-about-\(fact.id ?? fact.label)")
}
ChatYouFootButton(words: ChatWords.line("you.about_copy"), id: "you-about-copy", main: false) {
let version = about?.version.map { ["\($0.label): \($0.said)"] } ?? []
UIPasteboard.general.string = (version + (about?.facts ?? []).map { "\($0.label): \($0.said)" }).joined(separator: "\n")
said(ChatWords.line("you.about_copied"))
}
.padding(.top, 14)
}
}
}
#endif