// `/bring-in` — Settings › Bring in: the share sheet's door, opened from inside// the app. The files chosen in Files are staged into the app group exactly as// the share extension stages a share, and handed to the SAME drain// (`ShareIntake.intake`), so a photo, a clip, a recording and any other file// land as they would have through the share sheet: the row is written with its// bytes in the store, and the app opens what was made.importCottonKitimportCottonValuesimportSwiftUIstructBringInRoute: View {let shares: ShareIntake @Environment(\.theme) privatevar theme @Environment(ToastCenter.self) privatevar toasts @State privatevar picking = false @State privatevar adding = false/// The words the screen says, one place.enumWords {staticvar title: String { ShellLines.line("databases", "bring_in.title") }staticvar lead: String { ShellLines.line("databases", "bring_in.lead") }staticvar choose: String { ShellLines.line("databases", "bring_in.choose") }staticvar adding: String { ShellLines.line("databases", "bring_in.adding") }staticvar unreadable: String { ShellLines.line("databases", "bring_in.unreadable") } }var body: someView {PaperScreen(title: Words.title) { VStack(alignment: .leading, spacing: RecordListSurfaceKnobs.paperGap) {Text(adding ? Words.adding : Words.lead) .paperBody(15, ink: .pencil) .frame(maxWidth: .infinity, alignment: .leading)PaperTypedButton(Words.choose) { picking = true } .accessibilityIdentifier("bring-in-choose") } .disabled(adding) } .fileImporter(isPresented: $picking, allowedContentTypes: [.item], allowsMultipleSelection: true) { result inguardcase .success(let urls) = result else { return }Task { await bring(urls) } } }/// Stage each chosen file and hand them all to the drain, which files each/// one and opens what it made.privatefunc bring(_ urls: [URL]) async { adding = truedefer { adding = false }let staged = stageForIntake(urls, at: CottonDate.format(Date()))if staged.count < urls.count { toasts.show(Words.unreadable, tone: .error) }await shares.intake(staged) }}