// One table's list under one project the route names — a project's own Todos// (`/projects/[slug]/todos`, `/todos/done?project=<id>`). Projects are a filter// (rebuild note 7b95efa4): the list is the table's own list with that project// as the current one, never a second screen.//// A route carries the project's id or its slug, and this resolves either, the// id first, as the crate always has. A project that resolves to nothing// narrows to NOTHING — it says so — and never to the whole table.importCottonValuesimportSwiftUIpublicstructProjectListRoute: View {enumFound: Equatable {case project(String)case nonecase failed }privatelet table: Stringprivatelet project: Stringprivatelet onOpen: ((TableRecord) -> Void)? @Environment(\.records) privatevar store @State privatevar found: Found?/// - Parameter project: the project's id or its slug.publicinit(table: String, project: String, onOpen: ((TableRecord) -> Void)? = nil) {self.table = tableself.project = projectself.onOpen = onOpen }publicvar body: someView {switch found {case .project(let id)?:TableListRoute(table: table, onOpen: onOpen) .environment(\.currentProject, id)case .none?:PaperScreen {QuietState(title: ShellLines.line("record", "project.not_found"), message: ShellLines.line("record", "project.not_found_message")) }case .failed?:PaperScreen {QuietState( title: ShellLines.line("record", "project.unreadable"), message: ShellLines.line("empty", "unchanged"), actionLabel: ShellLines.line("record", "try_again"), action: { found = nil }) }casenil:PaperScreen { EmptyView() } // no loader: the rows are local and land next frame .task(id: project) { found = awaitSelf.resolve(project, in: store) } } }/// The project's id for `reference`: a project with that id, else one/// with that slug.staticfunc resolve(_ reference: String, in store: (any Records)?) async -> Found {guardlet store, !reference.isEmpty else { return .failed }do {guardlet projects = tryawait store.tableDefinitions().first(where: { $0.role == .project }) else { return .none }iflet byID = tryawait store.get(table: projects.id, id: reference) { return .project(byID.id) }iflet slug = projects.scopeBy, let bySlug = tryawait store.first(table: projects.id, column: slug, equals: .text(reference)) {return .project(bySlug.id) }return .none } catch {return .failed } }}