// People's list, and the contacts import over it. // // The list is one list drawn from the view chosen on the ring (`ToolViewRoute`: // All, then each group as a slip, never a stacks row), and a person opens as // the person table's page. What this adds is only what this phone's address // book needs, covering the WHOLE SCREEN over the list (`wholeScreen`, the // cover a note's reading page opens in) — a flow over a store no table holds, // never a page of the list's own: the import (`/people/import`, People's // "Import from contacts"). The address book is a source Cotton imports from, // never a sink it rewrites: People is the clean book. // // The deck's plus, the + fan's Contact and the Imports list name the same // path, so every way in raises the same cover over the same list, and closing // it leaves that list. import CottonKit import SwiftUI struct PeopleListFlow: View { /// The table whose list this is — said by the route that draws it /// (`RouteScreen`), so the route table reads as what it is: `/people` is /// the person table's named list (`Route.namedTableLists`), the list a /// person's page opens beside. let table: String /// The flow a People route asked for. enum Raising { case importing(PeopleImportModel) } /// The flow, when the list was opened for one: covering the screen over /// the list for as long as this entry stands (`Navigator.listArrival` /// never replaces it), and spent — the plain list put in its place — when /// the cover goes. var raising: Raising? = nil @Environment(Navigator.self) private var navigator /// Raised once the list has appeared: a cover bound up before its /// presenter is on screen is a cover SwiftUI may drop. @State private var asked = false /// The cover is coming down. @State private var leaving = false var body: some View { ToolViewRoute(of: "people", table: table) { navigator.push(.peoplePerson(id: $0.id)) } // The whole screen: the picker's own close is its one close, and // nothing beside it can call the import off while it files. .wholeScreen(isPresented: sheetUp, onDismiss: sheetDown) { sheet } .task { if raising != nil { asked = true } } } @ViewBuilder private var sheet: some View { switch raising { case .importing(let model)?: PeopleImportSheet(model: model, close: { leaving = true }) case nil: EmptyView() } } /// Up from the moment the list stands for a flow until it is told to leave. private var sheetUp: Binding { Binding(get: { asked && raising != nil && !leaving }, set: { up in if !up { leaving = true } }) } /// The sheet is down: spend the entry, so the list is the plain one and a /// later act raises a fresh flow. private func sheetDown() { guard leaving else { return } navigator.stack = Self.leavingSheet(over: navigator.stack) } /// The path once a People sheet is down — pure, and one assignment. A /// People list asked to import on top becomes the plain People /// list; any other top is left. static func leavingSheet(over path: [Route]) -> [Route] { var out = path if out.last == .peopleImport { out[out.count - 1] = .people } return out } }