importCottonKitimportCottonValuesimportSwiftUI/// A table whose records are made from a file: its list, whose act picks one —/// and, when a share staged a file for it, that file handed to the table's/// `create` as the path in `column`, on arrival.////// What `create` answers decides what stands here: a record naming a chat/// (`thread_id`) is replaced by that chat, as the owner ruled for a shared/// export ("take me into the chat"); any other is the record's own page,/// which asks what the import could not decide or says why it stopped.structTableFileImportRoute: View {let table: Stringlet column: Stringlet take: @MainActor () -> StagedShare? @Environment(\.tableDefinitions) privatevar definitions @Environment(\.records) privatevar store @Environment(Navigator.self) privatevar navigator: Navigator? @State privatevar arrival: Arrival?privateenumArrival {case listcase reading(String)case record(TableRecord)case refused(String) }var body: someView {Group {switch arrival {case .list?:TableListRoute(table: table)case .record(let record)?:iflet definition = definitions[table] {RecordOpening(definition: definition, opens: .record(record.id, record)) }case .reading(let name)?:PaperScreen { QuietState(title: ShellLines.line("record", "import.reading", ["name": name]), message: ShellLines.line("record", "import.reading_message")) }case .refused(let sentence)?:PaperScreen { QuietState(title: ShellLines.line("record", "import.not_added"), message: sentence) }casenil:PaperScreen { EmptyView() } // no loader: the rows are local and land next frame } } .task {guard arrival == nilelse { return }guardlet file = take() else { arrival = .listreturn }guardlet store else { arrival = .refused(ShellLines.line("record", "import.kept_here"))return } arrival = .reading(file.name.isEmpty ? ShellLines.line("record", "import.the_export") : file.name)do {let made = tryawait store.create(table: table, data: [column: .text(file.path), "name": .text(file.name)])guardlet record = made.after else { arrival = .listreturn }ifcase .text(let thread)? = record.values["thread_id"], let navigator { navigator.replace(with: .messagesThread(thread: thread)) } else { arrival = .record(record) } } catchlet refused asActionRefused { arrival = .refused(refused.sentence) } catch { arrival = .refused(ShellLines.line("record", "import.kept_here")) } } }}