// `/notes/note/[id]`: a note's page — or, for an id that is a project's// journal page (a project's journal section and Activity name one by its id// alone), that page in the journal table, headed by its day. One read of the// note says which and is the page's first frame: a note is drawn from it at// once, and an id the note table does not hold opens in the journal table.// `new`, what the add fan pushes, is a blank note page that creates the note// on its first value.importCottonKitimportCottonValuesimportSwiftUIstructNoteRoute: View {let id: String @Environment(\.records) privatevar store @Environment(\.tableDefinitions) privatevar definitions/// What the one read found. @State privatevar found: Found?enumFound: Equatable {/// The note, drawn from this read.case note(TableRecord)/// The note table holds no such id: a journal page's.case notANote/// The read failed: the note's own page reads again and says so.case unread }var body: someView {if id == "new", let note = definitions["note"] {RecordOpening(definition: note, opens: .blank([:])) } else {switch found {case .note(let record)?:TablePageRoute(table: "note", record: record)caselet other?:TablePageRoute(table: Self.table(of: other), id: id)casenil:PaperScreen { EmptyView() } // no loader: the row is local and lands next frame .task(id: id) { found = awaitSelf.read(id, in: store) } } } }/// The note with this id; `notANote` when the note table holds none.staticfunc read(_ id: String, in store: (any Records)?) async -> Found {guardlet store else { return .unread }do {guardlet record = tryawait store.get(table: "note", id: id) else { return .notANote }return .note(record) } catch {return .unread } }/// The table the id's page opens in.staticfunc table(of found: Found) -> String { found == .notANote ? "journal" : "note" }}