SPB Git

Repository Public

RootView.swift 8.8 KB 205 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/App/RootView.swift10// Description      : onglets adaptatifs (barre d'onglets sur iPhone, barre11//                    latérale sur iPad) et destinations partagées.12// Module           : ImmoKa13// Repository       : https://git.spboucher.ai/immo-ka-ios-v314// Project Website  : https://www.immo-ka.com15// Created          : 2026-11-2516// Last Modified    : 2026-11-3017//18// =============================================================================19// AUTHOR & PROFESSIONAL AFFILIATION20// =============================================================================21//22// Author           : Simon-Pierre Boucher23// Position         : Professor of Finance24// Institution      : Université du Québec en Outaouais (UQO)25// Department       : Département des sciences administratives26// Organization     : SP Boucher27//28// Website          : https://spboucher.ai29// Git              : https://git.spboucher.ai30//31// =============================================================================32// OFFICIAL CONTACT DIRECTORY33// =============================================================================34//35// General          : info@spboucher.ai36// Professional     : contact@spboucher.ai37// Direct           : simon@spboucher.ai38// Research         : research@spboucher.ai39// Development      : dev@spboucher.ai40// Support          : support@spboucher.ai41// Security/Admin   : admin@spboucher.ai42// Notifications    : notifications@spboucher.ai43//44// Preferred Contact: support@spboucher.ai45//46// =============================================================================47// COPYRIGHT & INTELLECTUAL PROPERTY48// =============================================================================49//50// Copyright (c) 202651// Simon-Pierre Boucher52//53// All rights reserved where applicable.54//55// This file is governed by the applicable project license,56// copyright notices, institutional agreements and relevant law.57//58// Unless expressly authorized by the applicable license or59// rights holder, copying, redistribution, sublicensing,60// publication and commercial exploitation are not permitted.61//62// Existing third-party rights and notices remain unaffected.63//64// =============================================================================65// CONFIDENTIALITY & SECURITY66// =============================================================================67//68// Classification   : Public69// Distribution     : Public repository; use is governed by the project license70// Security Contact : admin@spboucher.ai71//72// Access to this source does not independently grant permission73// to redistribute or disclose confidential materials.74//75// Do not embed credentials, private keys, access tokens,76// certificates or confidential personal information.77//78// =============================================================================79// LICENSE & MAINTENANCE80// =============================================================================81//82// License          : None specified (no license file in this repository)83// Maintainer       : Simon-Pierre Boucher84// Technical Contact: dev@spboucher.ai85//86// =============================================================================87// END OF SP BOUCHER SOURCE HEADER88// =============================================================================8990import SwiftUI9192struct RootView: View {93    @Environment(AppModel.self) private var model94    @Environment(Library.self) private var library95    @Environment(Account.self) private var account9697    var body: some View {98        @Bindable var model = model99        TabView(selection: $model.tab) {100            Tab("Découvrir", systemImage: "house", value: AppTab.discover) {101                stack(.discover) { DiscoverView() }102            }103            Tab("Explorer", systemImage: "map", value: AppTab.explore) {104                stack(.explore) { ExploreView() }105            }106            Tab("Favoris", systemImage: "heart", value: AppTab.favorites) {107                stack(.favorites) { FavoritesView() }108            }109            .badge(library.favoriteIDs.count)110            Tab("Courtiers", systemImage: "person.2", value: AppTab.pros) {111                stack(.pros) { ProsView() }112            }113            Tab("Marché", systemImage: "chart.bar.xaxis", value: AppTab.market) {114                stack(.market) { MarketView() }115            }116        }117        .tabViewStyle(.sidebarAdaptable)118        .overlay(alignment: .bottom) { toast }119        .overlay { DoorOverlay() }120        .sheet(isPresented: $model.accountSheet, onDismiss: {121            model.accountStart = []122            // un message rédigé avant la connexion attend en mémoire : la rédaction revient avec son texte123            guard let draft = account.messaging.takeDraft() else { return }124            if account.user?.canStartConversation == true { model.compose = draft }125            else if account.user != nil { model.showToast("Seul un acheteur peut écrire à un courtier.") }126        }) {127            AccountFlow(initial: model.accountStart)128        }129        .sheet(item: $model.compose) { ComposeSheet(target: $0) }130        .task {131            // pastille des messages : au plus une fois par minute, au premier plan, jamais sans session132            while !Task.isCancelled {133                try? await Task.sleep(for: .seconds(MessagingPolicy.unreadInterval))134                await account.messaging.refreshUnread(active: Foreground.isActive)135            }136        }137        .onChange(of: account.sessionEnded) { _, ended in138            // session fermée par le serveur (expirée, révoquée ailleurs) : on le dit une fois, sans rien bloquer139            if ended { model.showToast("Votre session a pris fin. Vos favoris restent sur cet appareil.") }140        }141        .animation(.snappy, value: model.toast)142    }143144    private func stack<Content: View>(_ tab: AppTab, @ViewBuilder _ content: () -> Content) -> some View {145        NavigationStack(path: model.path(for: tab)) {146            content()147                .navigationDestination(for: Route.self) { route in148                    destination(route)149                }150        }151    }152153    @ViewBuilder154    private func destination(_ route: Route) -> some View {155        switch route {156        case .listing(let uid): ListingView(uid: uid)157        case .agency(let name): AgencyView(name: name)158        case .banniere(let id): BanniereView(id: id)159        case .city(let name): CityView(name: name)160        case .cities: CitiesView()161        case .inspectors: ProDirectoryView(kind: .inspectors)162        case .movers: ProDirectoryView(kind: .movers)163        case .registry: RegistryView()164        case .compare: CompareView()165        case .recent: RecentView()166        case .rates: RatesView()167        case .calculator: CalculatorView()168        case .vraiPrixGuide: VraiPrixGuideView()169        case .about: AboutView()170        case .privacy: LegalView(kind: .privacy)171        case .terms: LegalView(kind: .terms)172        case .settings: SettingsView()173        case .neighborhood(let slug, let city): NeighborhoodView(slug: slug, city: city)174        case .neighborhoods(let city, let name): NeighborhoodsView(city: city, cityName: name)175        case .brokers: BrokerSearchView()176        case .market(let slug, let kind, let name): PlaceMarketView(place: MarketPlace(slug: slug, kind: kind, name: name))177        case .broker(let id, let name): BrokerView(id: id, name: name)178        case .account: AccountView()179        case .messages: MessagesView()180        case .conversation(let id): ThreadView(id: id)181        }182    }183184    @ViewBuilder185    private var toast: some View {186        if let text = model.toast {187            // confirmation : le symbole de la marque, porte entrouverte, accompagne le message188            HStack(spacing: 10) {189                BrandMark(angle: BrandGeometry.ajarAngle, onDark: true).frame(height: 20)190                Text(text)191            }192                .font(.subheadline.weight(.medium))193                .multilineTextAlignment(.leading)194                .padding(.horizontal, 18).padding(.vertical, 12)195                .foregroundStyle(Theme.bg)196                .background(Theme.ink, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))197                .shadow(color: .black.opacity(0.18), radius: 10, y: 4)198                .padding(.horizontal, 20)199                .padding(.bottom, 72)200                .transition(.move(edge: .bottom).combined(with: .opacity))201                .accessibilityAddTraits(.isStaticText)202        }203    }204}205
Files main
Menu

Theme