SPB Git

Repository Public License

Router.swift 1.9 KB 72 lines swift

1// ORIX Scan2// File: App/Sources/Core/Router.swift3// Description: Navigation state shared by the iPhone tab layout and the iPad sidebar layout.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import Foundation8import ORIXKit9import SwiftUI1011enum Route: Hashable {12    case document(UUID)13    case library(LibraryScope)14    case workflow(UUID)15    case settings16}1718enum AppSection: Hashable {19    case home, actions, settings20    case library(LibraryScope)21}2223enum AppTab: Hashable { case home, library, actions }2425@Observable26final class Router {27    // iPhone: one stack per tab.28    var tab: AppTab = .home29    var homePath: [Route] = []30    var libraryPath: [Route] = []31    var actionsPath: [Route] = []32    // iPad: sidebar selection plus one detail stack.33    var section: AppSection? = .home34    var detailPath: [Route] = []35    var isRegular = false3637    /// Shows a document from wherever the user is.38    func open(_ id: UUID) { push(.document(id)) }3940    func push(_ route: Route) {41        if isRegular { detailPath.append(route); return }42        switch tab {43        case .home: homePath.append(route)44        case .library: libraryPath.append(route)45        case .actions: actionsPath.append(route)46        }47    }4849    /// Leaves any screen that shows the given document (after it was deleted).50    func close(_ id: UUID) {51        let keep: (Route) -> Bool = { $0 != .document(id) }52        homePath = homePath.filter(keep)53        libraryPath = libraryPath.filter(keep)54        actionsPath = actionsPath.filter(keep)55        detailPath = detailPath.filter(keep)56    }5758    func showLibrary(_ scope: LibraryScope = .all) {59        if isRegular {60            section = .library(scope)61            detailPath = []62        } else {63            tab = .library64            libraryPath = scope == .all ? [] : [.library(scope)]65        }66    }6768    func showActions() {69        if isRegular { section = .actions; detailPath = [] } else { tab = .actions }70    }71}72
Files main
Menu

Theme