Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : Lou-Ka iOS9// File : LouKa/Features/Managers/CitiesView.swift10// Description : villes (index et fiche ville) et annuaire des déménageurs.11// Module : LouKa12// Repository : https://git.spboucher.ai/lou-ka-ios-v313// Project Website : https://www.lou-ka.com14// Created : 2026-11-2515// Last Modified : 2026-11-2816//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : None specified (no license file in this repository)82// Maintainer : Simon-Pierre Boucher83// Technical Contact: dev@spboucher.ai84//85// =============================================================================86// END OF SP BOUCHER SOURCE HEADER87// =============================================================================8889import SwiftUI9091struct CitiesView: View {92 @State private var villes: [VilleRow]?93 @State private var error: Error?94 @State private var query = ""95 @State private var byName = false9697 private var filtered: [VilleRow] {98 let q = Fmt.slug(query)99 var v = (villes ?? []).filter { q.isEmpty || Fmt.slug($0.city).contains(q) }100 if byName { v.sort { $0.city.localizedCaseInsensitiveCompare($1.city) == .orderedAscending } }101 return v102 }103104 var body: some View {105 List {106 if let villes {107 Section {108 ForEach(filtered) { v in109 NavigationLink(value: Route.city(slug: v.slug, name: v.city)) {110 HStack {111 VStack(alignment: .leading, spacing: 2) {112 Text(v.city).font(.body.weight(.medium)).foregroundStyle(Theme.ink)113 Text(Fmt.plural(v.n, "logement", "logements")).font(.caption).num().foregroundStyle(Theme.ink3)114 }115 Spacer()116 if let p = v.avgPrice {117 VStack(alignment: .trailing, spacing: 1) {118 Text(Fmt.money(p)).font(.subheadline.weight(.semibold)).num().foregroundStyle(Theme.ink)119 Text("en moyenne").font(.caption2).foregroundStyle(Theme.ink3)120 }121 }122 }123 }124 .listRowBackground(Theme.surface)125 }126 } header: {127 Text("\(Fmt.plural(filtered.count, "ville", "villes")) sur \(Fmt.int(villes.count))")128 }129 } else if let error {130 ErrorStateView(error: error) { Task { await load() } }.listRowBackground(Color.clear)131 } else {132 ForEach(0..<10, id: \.self) { _ in Skeleton(height: 34).listRowBackground(Theme.surface) }133 }134 }135 .scrollContentBackground(.hidden)136 .background(Theme.bg)137 .navigationTitle("Villes")138 .searchable(text: $query, prompt: "Chercher une ville")139 .toolbar {140 ToolbarItem(placement: .topBarTrailing) {141 SlidingSegmented(selection: $byName, options: [(false, "Offre"), (true, "A-Z")], label: "Tri des villes")142 }143 }144 .task { if villes == nil { await load() } }145 }146147 private func load() async {148 error = nil149 do { villes = try await APIClient.shared.villes().villes } catch is CancellationError {} catch { self.error = error }150 }151}152153struct CityView: View {154 let slug: String155 let name: String156 @Environment(AppModel.self) private var app157 @State private var detail: VilleDetail?158 @State private var error: Error?159 @State private var type: VilleDetail.UnitType?160161 var body: some View {162 ScrollView {163 LazyVStack(alignment: .leading, spacing: 20) {164 if let d = detail {165 VStack(alignment: .leading, spacing: 6) {166 Text("Logements à louer").eyebrowStyle()167 Text(d.city.isEmpty ? name : d.city).font(.editorial(29)).tracking(-0.2).foregroundStyle(Theme.ink)168 }169 HStack(spacing: 10) {170 StatTile(value: Fmt.int(d.n), label: d.n > 1 ? "logements" : "logement")171 StatTile(value: Fmt.money(d.med), label: "loyer médian")172 StatTile(value: Fmt.money(d.avg), label: "loyer moyen")173 }174 .cardStyle(padding: 16)175 Button {176 var f = SearchFilters(); f.city = d.city.isEmpty ? name : d.city; f.unitType = type?.unitType177 app.explore(f)178 } label: { Label("Voir sur la carte", systemImage: "map").frame(maxWidth: .infinity) }179 .buttonStyle(PrimaryButtonStyle())180 if d.types.count > 1 {181 ScrollView(.horizontal, showsIndicators: false) {182 HStack(spacing: 8) {183 Chip(label: "Tout", active: type == nil) { type = nil }184 ForEach(d.types) { t in185 Chip(label: "\(t.unitType) · \(t.n)", active: type?.slug == t.slug) { type = type?.slug == t.slug ? nil : t }186 }187 }188 }189 .scrollClipDisabled()190 }191 LazyVGrid(columns: [GridItem(.adaptive(minimum: 300), spacing: 14)], spacing: 14) {192 ForEach(Array(d.listings.enumerated()), id: \.element.id) { i, l in ListingLink(listing: l).staggered(i) }193 }194 if d.listings.isEmpty {195 EmptyStateView(door: .closed, title: "Aucun logement affiché", message: "L'offre change plusieurs fois par jour.")196 }197 if !d.neighbors.isEmpty {198 SectionHeader(title: "Villes voisines")199 FlowLayout(spacing: 8) {200 ForEach(d.neighbors.prefix(12)) { v in201 NavigationLink(value: Route.city(slug: v.slug, name: v.city)) {202 Text("\(v.city) · \(Fmt.int(v.n))").font(.footnote.weight(.medium)).num().foregroundStyle(Theme.ink)203 .padding(.horizontal, 12).padding(.vertical, 8).background(Theme.surface2, in: RoundedRectangle(cornerRadius: Theme.radiusTag, style: .continuous))204 }205 .buttonStyle(.plain)206 }207 }208 }209 } else if let error {210 if case APIError.notFound = error {211 EmptyStateView(door: .closed, title: "Ville introuvable", message: "Aucun logement à louer n'y est affiché pour l'instant.")212 } else {213 ErrorStateView(error: error) { Task { await load() } }214 }215 } else {216 Skeleton(height: 40).frame(width: 200)217 Skeleton(height: 90, radius: 20)218 ForEach(0..<2, id: \.self) { _ in ListingCardSkeleton() }219 }220 }221 .padding(20)222 .frame(maxWidth: 1000)223 .frame(maxWidth: .infinity)224 }225 .background(Theme.bg)226 .navigationTitle(name)227 .navigationBarTitleDisplayMode(.inline)228 .task(id: type?.slug) { await load() }229 .refreshable { await load() }230 }231232 private func load() async {233 error = nil234 do { detail = try await APIClient.shared.ville(slug: slug, type: type?.slug) } catch is CancellationError {} catch { if detail == nil { self.error = error } }235 }236}237238struct MoversView: View {239 @State private var movers: [Mover]?240 @State private var error: Error?241 @State private var query = ""242 @State private var region: String?243 @State private var external: ExternalLink?244245 private var regions: [String] { Array(Set((movers ?? []).map(\.region).filter { !$0.isEmpty })).sorted() }246 private var filtered: [Mover] {247 let q = Fmt.slug(query)248 return (movers ?? []).filter { m in249 (region == nil || m.region == region) && (q.isEmpty || Fmt.slug(m.name).contains(q) || Fmt.slug(m.city).contains(q))250 }251 .sorted { ($0.rating ?? 0, $0.reviews ?? 0) > ($1.rating ?? 0, $1.reviews ?? 0) }252 }253254 var body: some View {255 ScrollView {256 LazyVStack(alignment: .leading, spacing: 12) {257 if movers != nil {258 ScrollView(.horizontal, showsIndicators: false) {259 HStack(spacing: 8) {260 Chip(label: "Toutes les régions", active: region == nil) { region = nil }261 ForEach(regions, id: \.self) { r in Chip(label: r, active: region == r) { region = region == r ? nil : r } }262 }263 }264 .scrollClipDisabled()265 Text(Fmt.plural(filtered.count, "entreprise", "entreprises")).eyebrowStyle().padding(.top, 4)266 ForEach(filtered) { m in267 VStack(alignment: .leading, spacing: 8) {268 HStack(alignment: .top) {269 VStack(alignment: .leading, spacing: 2) {270 Text(m.name).font(.headline).foregroundStyle(Theme.ink)271 Text([m.city, m.region].filter { !$0.isEmpty }.joined(separator: " · ")).font(.caption).foregroundStyle(Theme.ink3)272 }273 Spacer()274 if let r = m.rating {275 HStack(spacing: 3) {276 Image(systemName: "star.fill").font(.system(size: 11)).foregroundStyle(Theme.high)277 Text(String(format: "%.1f", r).replacingOccurrences(of: ".", with: ",")).font(.subheadline.weight(.semibold)).num()278 if let n = m.reviews { Text("(\(n))").font(.caption).foregroundStyle(Theme.ink3) }279 }280 }281 }282 HStack(spacing: 10) {283 if !m.phone.isEmpty, let tel = URL(string: "tel:\(m.phone.filter { $0.isNumber || $0 == "+" })") {284 Link(destination: tel) { Label(m.phone, systemImage: "phone") }.buttonStyle(SoftButtonStyle())285 }286 if let link = ExternalLink(m.website) {287 Button { external = link } label: { Label("Site", systemImage: "safari") }.buttonStyle(SoftButtonStyle())288 }289 }290 }291 .cardStyle(padding: 14)292 }293 } else if let error {294 ErrorStateView(error: error) { Task { await load() } }295 } else {296 ForEach(0..<6, id: \.self) { _ in Skeleton(height: 100, radius: 20) }297 }298 }299 .padding(.horizontal, 20).padding(.bottom, 30)300 .frame(maxWidth: 760)301 .frame(maxWidth: .infinity)302 }303 .background(Theme.bg)304 .navigationTitle("Déménageurs")305 .searchable(text: $query, prompt: "Nom ou ville")306 .task { if movers == nil { await load() } }307 .safariSheet($external)308 }309310 private func load() async {311 error = nil312 do { movers = try await APIClient.shared.movers().movers } catch is CancellationError {} catch { self.error = error }313 }314}315