Cotton code
50 lines · 1.8 KB · SwiftRaw
import CottonKitimport CottonValuesimport SwiftUIenum SettingsRing {    /// The dial's Settings card, as the core keys it (`shell.fan`).    static let tool = "settings"    /// The table whose rows are its views.    static let table = ExportFan.settingsTable    /// The screen a view's page is: its row's route; nil where this build    /// has none for it.    static func route(of view: ToolView) -> Route? {        view.address.flatMap(Route.parse)    }    /// What holding a view opens: Settings' Export view, the export fan;    /// nil for every other view.    static func exports(tool: String, view: ToolView) -> DeckEditTarget? {        guard tool == self.tool, ExportFan.opens(table: table, record: view.id) else { return nil }        return DeckEditTarget(table: table, record: view.id, date: nil)    }}/// The Settings card's page: the chosen view's own screen, drawn in place;/// where no fan stands (the Mac), Settings' own list.struct SettingsPage: View {    /// What a route draws, as the route table draws it (`RouteScreen`).    let screen: @MainActor (Route) -> AnyView    @Environment(ToolViews.self) private var views: ToolViews?    var body: some View {        if let views {            if let view = views.current(of: SettingsRing.tool) {                if let route = SettingsRing.route(of: view) {                    screen(route).id(view.id)                } else {                    PaperScreen(title: view.label) {                        QuietState(title: ShellLines.line("lists", "destination.cannot_open"), message: "")                    }                }            } else {                PaperScreen { EmptyView() }  // no loader: the fan's answer lands next frame            }        } else {            TableListRoute(table: SettingsRing.table)        }    }}