Cotton code
48 lines · 2.0 KB · SwiftRaw
import SwiftUI/// `/tools` and `/database` (design note 26203e21): a board pushed over Home —/// the Tools screen's (`tools`: every tool, put-away ones too, and About) or/// the database page's (`database`: its name, its facts, a section for every/// tool holding records, its tools). Built through `HomeBoard` over Home's one/// read, and named as the window's shown database is.struct BoardRoute: View {    /// The board id: "tools" or "database".    let board: String    let home: HomeModel    /// The name a window that has not resolved its database yet falls back on.    let fallbackName: String?    @Environment(DatabaseScene.self) private var scene: DatabaseScene?    @Environment(DatabasesModel.self) private var databases: DatabasesModel?    var body: some View {        let shown = databases.flatMap { scene?.shown(in: $0) }        HomeBoard(            home: home,            databaseName: shown?.name ?? fallbackName,            personal: shown?.kind != .shared,            board: board)    }}/// The shown database's own record page — what tray › "Name and picture" opens —/// for a route that names no database: a project's brand (`/projects/[slug]//// brand`), which is its database's (`DatabaseBrand`). The generic page of the/// table playing the database role, as "Name and picture" opens it. Nothing is/// drawn until the window has resolved which database it shows.struct ShownDatabasePage: View {    @Environment(DatabaseScene.self) private var scene: DatabaseScene?    @Environment(DatabasesModel.self) private var databases: DatabasesModel?    @Environment(\.tableDefinitions) private var definitions    var body: some View {        if let id = databases.flatMap({ scene?.shown(in: $0) })?.databaseId,            let table = definitions.playing(.database)?.id        {            TablePageRoute(table: table, id: id)                .settingsKeptFlows(table: table, record: id)        } else {            Color.clear        }    }}