Cotton code
67 lines · 3.3 KB · SwiftRaw
// Routing and filters over the shared list/page; ingestion, sync and mailbox// writes stay in Rust. EmailRecords adapts the current boundary until the// generic engine-backed Records seam can serve the same envelope columns.import CottonKitimport SwiftUIstruct EmailArchiveSurface: View {    /// What the Email tool shows: its ONE list of mail, newest first, with its    /// groups drawn as stacks above it (owner, 11 Oct 2026: the seven-way    /// folder menu felt infinite). The people who write and the blocked ones    /// are the list's link tiles (email_thread.json's `links` and `link_tiles`), and a    /// sender's page lists their mail — nothing here draws a way to them.    let id: String?    /// The message a Find hit matched: the conversation opens on it rather    /// than at the newest (mailsearch). The page fetches it when it is older    /// than the first page, and only when it is in this conversation.    var at: String? = nil    @Environment(\.cottonCore) private var core    @State private var archive: EmailRecords?    @Environment(\.tableDefinitions) private var definitions    @Environment(Navigator.self) private var navigator    @Environment(ToolViews.self) private var views: ToolViews?    var body: some View {        Group {            if archive != nil { content }            else if core == nil {                QuietState(title: ShellLines.line("email", "archive.unread_title"), message: ShellLines.line("email", "archive.unread_body"))            } else { SkeletonPage(rows: 3) }        }            .environment(\.records, archive)            .task {                if archive == nil, let core { archive = EmailRecords(core: core, definitions: definitions.all) }            }    }    @ViewBuilder private var content: some View {        if let definition = definitions["email_thread"] {            if let id {                // A mail conversation opens on its own (`ConversationRoute`),                // at the message a search found.                ConversationRoute(table: definition.id, id: id, anchor: at)            } else {                // ONE list: the view the ring over the fan chose (Today, Records,                // People, Junk, All — email_thread.json's `tool.views`), read                // exactly as it says; no stacks, the ring moves between them.                let view = views?.current(of: "email")                if DeckSwitch.draws(definition, view: view?.read, plain: true) {                    // No scrolling lists: the mail is its deck, the ring's                    // views rolling one into the next.                    DeckSurface(definition: definition, filter: view?.read.filter ?? [:], view: view?.read, rollover: { forward in                        guard let views,                              let next = views.neighbour(of: "email", step: forward ? 1 : -1)                        else { return nil }                        views.choose(next.id, of: "email")                        return next.label                    })                } else {                    RecordListSurface(definition: definition, where: view?.read.filter ?? [:], view: view?.read) { record in                        navigator.push(.emailId(id: record.id))                    }                    .id(view?.id)                }            }        }    }}