Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/App/RootView.swift10// Description : onglets adaptatifs (barre d'onglets sur iPhone, barre11// latérale sur iPad) et destinations partagées.12// Module : LouKa13// Repository : https://git.spboucher.ai/lou-ka-ios-v314// Project Website : https://www.lou-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 account96 @Environment(\.scenePhase) private var scenePhase9798 var body: some View {99 @Bindable var model = model100 TabView(selection: $model.tab) {101 Tab("Découvrir", systemImage: "door.left.hand.open", value: AppTab.discover) {102 stack(.discover) { DiscoverView() }103 }104 Tab("Explorer", systemImage: "map", value: AppTab.explore) {105 stack(.explore) { ExploreView() }106 }107 Tab("Favoris", systemImage: "heart", value: AppTab.favorites) {108 stack(.favorites) { FavoritesView() }109 }110 .badge(library.favoriteIDs.count)111 Tab("Gestionnaires", systemImage: "building.2", value: AppTab.managers) {112 stack(.managers) { ManagersView() }113 }114 Tab("Marché", systemImage: "chart.bar.xaxis", value: AppTab.market) {115 stack(.market) { MarketView() }116 }117 }118 .tabViewStyle(.sidebarAdaptable)119 .overlay(alignment: .bottom) { toast }120 .overlay { DoorOverlay() }121 .sheet(isPresented: $model.accountSheet, onDismiss: {122 model.accountStart = []123 // un message rédigé avant la connexion attend en mémoire : la rédaction revient avec son texte124 guard let draft = account.messaging.takeDraft() else { return }125 if account.user?.canStartConversation == true { model.compose = draft }126 else if account.user != nil { model.showToast("Seul un chercheur de logement peut écrire à un gestionnaire.") }127 }) {128 AccountFlow(initial: model.accountStart)129 }130 .sheet(item: $model.compose) { ComposeSheet(target: $0) }131 .task {132 // pastille des messages : au plus une fois par minute, au premier plan, jamais sans session133 while !Task.isCancelled {134 try? await Task.sleep(for: .seconds(MessagingPolicy.unreadInterval))135 await account.messaging.refreshUnread(active: Foreground.isActive)136 }137 }138 .onChange(of: account.sessionEnded) { _, ended in139 // session fermée par le serveur (expirée, révoquée ailleurs) : on le dit une fois, sans rien bloquer140 if ended { model.showToast("Votre session a pris fin. Vos favoris restent sur cet appareil.") }141 }142 .animation(.snappy, value: model.toast)143 }144145 private func stack<Content: View>(_ tab: AppTab, @ViewBuilder _ content: () -> Content) -> some View {146 NavigationStack(path: model.path(for: tab)) {147 content()148 .navigationDestination(for: Route.self) { route in149 destination(route)150 }151 }152 }153154 @ViewBuilder155 private func destination(_ route: Route) -> some View {156 switch route {157 case .listing(let uid): ListingView(uid: uid)158 case .manager(let id): ManagerView(id: id)159 case .city(let slug, let name): CityView(slug: slug, name: name)160 case .managers: ManagersView()161 case .cities: CitiesView()162 case .movers: MoversView()163 case .compare: CompareView()164 case .neighborhoods(let city): NeighborhoodsView(city: city)165 case .neighborhood(let slug, let city, let name): NeighborhoodView(slug: slug, city: city, name: name)166 case .building(let id): BuildingView(id: id)167 case .marketPlace(let slug, let kind, let name): MarketView(place: Place(kind: kind, name: name, slug: slug))168 case .fairValueGuide: FairValueGuideView()169 case .scoresGuide: ScoresGuideView()170 case .about: AboutView()171 case .privacy: LegalView(kind: .privacy)172 case .terms: LegalView(kind: .terms)173 case .settings: SettingsView()174 case .account: AccountView()175 case .messages: MessagesView()176 case .conversation(let id): ThreadView(id: id)177 }178 }179180 @ViewBuilder181 private var toast: some View {182 if let text = model.toast {183 // confirmation : une petite porte entrouverte accompagne le message184 HStack(spacing: 10) {185 DoorMark(angle: DoorGeometry.ajarAngle, panelColor: Theme.bg).frame(height: 20)186 Text(text)187 }188 .font(.subheadline.weight(.medium))189 .multilineTextAlignment(.leading)190 .padding(.horizontal, 18).padding(.vertical, 12)191 .foregroundStyle(Theme.bg)192 .background(Theme.ink, in: RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))193 .shadow(color: .black.opacity(0.18), radius: 10, y: 4)194 .padding(.horizontal, 20)195 .padding(.bottom, 72)196 .transition(.move(edge: .bottom).combined(with: .opacity))197 .accessibilityAddTraits(.isStaticText)198 }199 }200}201