// Home's page as a deck, a READER of the core's answer (`shell.today`; the// shell boundary, 7 Nov 2026): the cards in the order the core dealt them —// this device's own card, today's rows across every database held, the// birthdays and money due, the unread conversations, then a card for each of// Home's bands with something to say — each worn in the face the core named// (`DeckFace.view`), its tap the core's. A row with no record of its own to// wear (an occurrence of a repeating event) wears the `today` face// (`TodayFace`). Each card opens its record in its own database// (`FeedRowOpening`); this device's card opens in place. The words, the order// and the faces are the core's; Home decides none of them.importCottonKitimportCottonValuesimportSwiftUI/// One of Home's bands with something to say now — its notices, what is/// asked of the person, what was done for them — drawn on a card of its own.structHomePartCard {let id: Stringlet face: AnyView}structHomeToday: View { @Environment(\.theme) privatevar theme @Environment(Navigator.self) privatevar navigator: Navigator? @Environment(\.screenRoute) privatevar screenRoute @Environment(DatabasesModel.self) privatevar databases: DatabasesModel? @Environment(DatabaseScene.self) privatevar scene: DatabaseScene? @Environment(ToastCenter.self) privatevar toasts: ToastCenter? @Environment(\.cottonSync) privatevar sync @Environment(\.records) privatevar store @Environment(\.tableDefinitions) privatevar definitions/// Home's page, as the core answered it.let home: HomeModel/// Home's whole page as the deck (the phone, cards on). Off, a section of/// Home's page: the day's heading over its rows.var deckPage = false/// The record Home's `device` part names, read from the board's box.var devicePart = HomeDevicePart()/// The faces of Home's bands, by part (`notices`, `asked`, `done`).var parts: [HomePartCard] = []/// The board's `today` part, for the section's rows and quiet line.var today: BoardEntry? = nil/// This device's card opened in place on Home. @State privatevar deviceOpened = falseprivatevar cards: [TodayAnswer.Card] { home.answer?.cards ?? [] }var body: someView {Group {if deckPage { deck } else { section } } .accessibilityElement(children: .contain) .accessibilityIdentifier("home-today") }/// Today as a section of Home's page: the day's heading over its rows.privatevar section: someView { VStack(alignment: .leading, spacing: 10) {Text(DayHeads.today) .font(theme.type.title(HomeTodayKnobs.headingSize)) .foregroundStyle(theme.colors.ink.color) .accessibilityAddTraits(.isHeader)let rows = (today?.cards ?? []).compactMap { id in cards.first { $0.id == id } }if !rows.isEmpty {ForEach(rows, id: \.id) { card inButton { open(card) } label: {ObjectSlip( seed: card.id, dye: card.dye.flatMap(PaperDye.init(rawValue:)) ?? .cream, title: card.deck.slots["title"]?.text ?? "", meta: card.deck.slots["line"]?.text, struck: false) } .buttonStyle(.plain) .accessibilityIdentifier(Self.identifier(card)) .modifier(UnreadUnderTheFan()) } } else {Text(today?.quiet ?? " ") .font(theme.type.body(HomeTodayKnobs.quietSize)) .foregroundStyle(theme.colors.inkSecondary.color) } } }/// What reads this device's card again: each sync revision, each pull/// landing, each change of phase and each write this device makes.privatestructDeviceReads: Hashable {var device: String?var revision: Intvar pulled: String?var phase: Stringvar local: Int }privatestaticlet labels = DeckAnswer.Labels(by_slot: [:], by_column: [:])privatevar deck: someView {CardDeck( items: cards, emptyLine: home.answer?.empty ?? ShellLines.line("board", "today.empty"),open: open, words: { card in [card.deck.slots["title"]?.text, card.deck.slots["body"]?.text].compactMap { $0 }.joined(separator: " ") }, plus: (ShellLines.line("capture", "composer.make_something"), { navigator?.open(.capture, start: .typing) }),// A hold on the sync card opens it in place, as a tap does. holds: { card inif card.kind == "device" { deviceOpened = true } }, opened: deviceOpened ? cards.first { $0.kind == "device" }?.id : nil ) { card in face(card) } .preference(key: FanPageReadingPreference.self, value: FanPageReading(filled: devicePart.id == nil || home.answer != nil))// This device's card moves with the sync (rows done of total, bytes,// synced at): read alone, on each pass and every few seconds. .task(id: DeviceReads( device: devicePart.id, revision: sync?.revision ?? 0, pulled: sync?.lastPullAt, phase: sync?.loop?.state ?? "", local: sync?.localWrites ?? 0)) {guard devicePart.id != nilelse { return }while !Task.isCancelled {await home.readDevice()try? awaitTask.sleep(for: .seconds(HomeSyncKnobs.every)) } } } @ViewBuilder privatefunc face(_ card: TodayAnswer.Card) -> someView {let drawn = card.deck.drawn(labels: Self.labels)let record = card.deck.record.recordswitch card.kind {case"part":// Home's own rows and buttons: the deck's zones never move over them.iflet part = parts.first(where: { "part/" + $0.id == card.id }) { part.face .deckKeepsTaps() .padding(TodayFaceKnobs.inset) .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .topLeading) .clipped() .onCardPaper(.framed) .modifier(UnreadUnderTheFan()) }default:ifDeckFace.draws(drawn) {DeckFace.view(for: drawn, record: record) { tick(card) } .modifier(HomeOpensInPlace(opened: deviceOpened && card.kind == "device", record: record, card: drawn, definition: card.table.flatMap { definitions[$0] }) { deviceOpened = false }) .environment(\.faceChoiceTable, card.table) .accessibilityElement(children: .contain) .accessibilityIdentifier(Self.identifier(card)) .modifier(UnreadUnderTheFan()) } elseif card.deck.face == "today" {let kind = card.deck.slots["kind"]?.textTodayFace(today: TodayItem(title: card.deck.slots["title"]?.text ?? "", done: false, line: card.deck.slots["line"]?.text), kind: kind) { side inToolObject(name: kind ?? "", picture: ToolObjects.picture(for: card.deck.slots["picture"]?.text ?? "todos"), printing: .contentOnly, side: side) } .accessibilityElement(children: .contain) .accessibilityIdentifier(Self.identifier(card)) .modifier(UnreadUnderTheFan()) } else {Color.clear.onCardPaper(.framed) } } }/// The name a card answers to, kept whichever face draws it.staticfunc identifier(_ card: TodayAnswer.Card) -> String {switch card.kind {case"day": "home-today-\(card.id.dropFirst("day/".count))"case"thread": "home-today-thread-\(card.deck.record.id)"case"part": "home-part-\(card.id.dropFirst("part/".count))"default: "home-later-\(card.deck.record.id)" } }/// A tick on a card's own check: what the core says it writes, then Home/// reads again.privatefunc tick(_ card: TodayAnswer.Card) {guardlet store, let table = card.table, let patch = card.deck.toggle, !patch.isEmpty else { return }Task { _ = try? await store.update(table: table, id: card.deck.record.id, patch: patch)await home.load() } }privatefuncopen(_ card: TodayAnswer.Card) {guardlet navigator else { return }switch card.kind {case"device": deviceOpened = truecase"day":guardlet opens = card.opens else { return }// A row of the shown database opens on its tool's deck, the fan// turned to it; one of another database switches to it first.if opens.database == nil, navigator.fanBrings?(opens.table, opens.page, false) == true { return }// The record's own screen, as its definition routes it; a// repeating event's occurrence opens at the start the core names.let own = BoardRecord.route(table: opens.table, id: opens.id, definition: definitions[opens.table])let route = opens.at.flatMap { Route.parse(Route.join(own.path, [("at", $0)])) } ?? own navigator.rowOpened[screenRoute ?? route] = PathRecord(table: opens.table, record: card.deck.record.record)FeedRowOpening(model: databases, scene: scene, toasts: toasts).open(route, in: card.database?.row, on: navigator)case"thread", "later":guardlet table = card.table else { return } navigator.open(table: table, id: card.deck.record.id, definition: definitions[table])default:return } }}/// A Home card opened in place, where its table's definition is held: only/// the sync card ever opens.privatestructHomeOpensInPlace: ViewModifier {let opened: Boollet record: TableRecordlet card: DeckCardlet definition: TableDefinition?let close: () -> Voidfunc body(content: Content) -> someView {iflet definition { content.opensInPlace(opened, definition: definition, record: record, worn: card.face, close: close) } else { content } }}enumHomeTodayKnobs {staticlet headingSize: CGFloat = 22staticlet quietSize: CGFloat = 16}