SPB Git

Repository Public

BrokerView.swift 9.5 KB 201 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/Features/Pros/BrokerView.swift10// Description      : page d'un courtier de l'annuaire — nom, agence, pastille «11//                    Courtier vérifié », fiche publiée par le courtier12//                    (contenu, bouton d'écriture), puis ses propriétés à13//                    vendre. L'identifiant est celui de `/api/v3/brokers/{id}`,14//                    le même que `broker_id` des comptes de courtier.15// Module           : ImmoKa16// Repository       : https://git.spboucher.ai/immo-ka-ios-v317// Project Website  : https://www.immo-ka.com18// Created          : 2026-11-3019// Last Modified    : 2026-12-0120//21// =============================================================================22// AUTHOR & PROFESSIONAL AFFILIATION23// =============================================================================24//25// Author           : Simon-Pierre Boucher26// Position         : Professor of Finance27// Institution      : Université du Québec en Outaouais (UQO)28// Department       : Département des sciences administratives29// Organization     : SP Boucher30//31// Website          : https://spboucher.ai32// Git              : https://git.spboucher.ai33//34// =============================================================================35// OFFICIAL CONTACT DIRECTORY36// =============================================================================37//38// General          : info@spboucher.ai39// Professional     : contact@spboucher.ai40// Direct           : simon@spboucher.ai41// Research         : research@spboucher.ai42// Development      : dev@spboucher.ai43// Support          : support@spboucher.ai44// Security/Admin   : admin@spboucher.ai45// Notifications    : notifications@spboucher.ai46//47// Preferred Contact: support@spboucher.ai48//49// =============================================================================50// COPYRIGHT & INTELLECTUAL PROPERTY51// =============================================================================52//53// Copyright (c) 202654// Simon-Pierre Boucher55//56// All rights reserved where applicable.57//58// This file is governed by the applicable project license,59// copyright notices, institutional agreements and relevant law.60//61// Unless expressly authorized by the applicable license or62// rights holder, copying, redistribution, sublicensing,63// publication and commercial exploitation are not permitted.64//65// Existing third-party rights and notices remain unaffected.66//67// =============================================================================68// CONFIDENTIALITY & SECURITY69// =============================================================================70//71// Classification   : Public72// Distribution     : Public repository; use is governed by the project license73// Security Contact : admin@spboucher.ai74//75// Access to this source does not independently grant permission76// to redistribute or disclose confidential materials.77//78// Do not embed credentials, private keys, access tokens,79// certificates or confidential personal information.80//81// =============================================================================82// LICENSE & MAINTENANCE83// =============================================================================84//85// License          : None specified (no license file in this repository)86// Maintainer       : Simon-Pierre Boucher87// Technical Contact: dev@spboucher.ai88//89// =============================================================================90// END OF SP BOUCHER SOURCE HEADER91// =============================================================================9293import SwiftUI9495struct BrokerView: View {96    let id: String97    /// nom connu de l'appelant (recherche, fiche d'une propriété) ; complété par l'annuaire98    var name: String = ""99    @Environment(Account.self) private var account100    @State private var detail: BrokerDetail?101    @State private var error: Error?102    /// Fiche publique du courtier (pastille, contenu publié) ; une vue comptée par ouverture de la page.103    @State private var fiche: BrokerFiche?104    @State private var ficheAsked = false105    @State private var external: ExternalLink?106    /// nombre de propriétés montrées (huit, puis toutes)107    @State private var shown = 8108109    private var displayName: String { detail?.name.isEmpty == false ? (detail?.name ?? name) : (name.isEmpty ? "Courtier" : name) }110111    var body: some View {112        ScrollView {113            LazyVStack(alignment: .leading, spacing: 22) {114                head115                if let fiche, fiche.verified || fiche.content != nil {116                    BrokerFicheView(fiche: fiche, name: displayName, external: $external)117                }118                if let d = detail {119                    listings(d)120                } else if let error {121                    ErrorStateView(error: error) { Task { await load() } }122                } else {123                    Skeleton(height: 120, radius: Theme.radius)124                }125                Text("Les courtiers sont ceux que nomment les sources. La pastille « Courtier vérifié » indique que l'équipe d'Immo-Ka a validé le compte de ce courtier ; le contenu de sa fiche est le sien.")126                    .font(.caption).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true)127            }128            .padding(20)129            .frame(maxWidth: 760, alignment: .leading)130            .frame(maxWidth: .infinity)131        }132        .background(Theme.bg)133        .navigationTitle(displayName)134        .navigationBarTitleDisplayMode(.inline)135        .task { if detail == nil { await load() } }136        .task {137            guard !ficheAsked else { return }138            ficheAsked = true139            fiche = await account.messaging.brokerFiche(brokerID: id, countView: true)140        }141        .safariSheet($external)142        .accessibilityIdentifier("broker.page")143    }144145    private func load() async {146        do { detail = try await APIClient.shared.broker(id); error = nil } catch is CancellationError {} catch { self.error = error }147    }148149    private var head: some View {150        HStack(alignment: .top, spacing: 14) {151            BrokerLogo(image: fiche?.content?.logo, name: displayName, size: 60)152            VStack(alignment: .leading, spacing: 5) {153                Text(verbatim: displayName).font(.editorial(24)).tracking(-0.2).foregroundStyle(Theme.ink)154                if fiche?.verified == true { VerifiedBadge() }155                if let a = detail?.agencyName, !a.isEmpty { Text(verbatim: a).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink2) }156                if let r = detail?.regions, !r.isEmpty { Text(verbatim: r.prefix(3).joined(separator: ", ")).font(.subheadline).foregroundStyle(Theme.ink3) }157            }158        }159        .accessibilityElement(children: .contain)160    }161162    @ViewBuilder163    private func listings(_ d: BrokerDetail) -> some View {164        VStack(alignment: .leading, spacing: 12) {165            SectionHeader(title: "Ses propriétés à vendre", subtitle: d.units > 0 ? Fmt.plural(d.units, "propriété distincte", "propriétés distinctes") : nil)166            if d.listings.isEmpty {167                Text("Aucune propriété à vendre n'est rattachée à ce courtier en ce moment.").font(.subheadline).foregroundStyle(Theme.ink2)168            } else {169                VStack(spacing: 0) {170                    ForEach(d.listings.prefix(shown)) { l in171                        NavigationLink(value: Route.listing(l.uid)) {172                            HStack(alignment: .firstTextBaseline, spacing: 12) {173                                VStack(alignment: .leading, spacing: 2) {174                                    Text(verbatim: l.title.isEmpty ? "Propriété à vendre" : l.title).font(.subheadline.weight(.medium)).foregroundStyle(Theme.ink).lineLimit(1)175                                    if !l.city.isEmpty { Text(verbatim: l.city).font(.footnote).foregroundStyle(Theme.ink3).lineLimit(1) }176                                }177                                Spacer(minLength: 8)178                                Text(l.price.flatMap { Listing.priceIsPlausible($0) ? Fmt.money($0) : nil } ?? "Prix sur demande").font(.subheadline).num().foregroundStyle(Theme.ink2)179                                Image(systemName: "chevron.right").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink3).accessibilityHidden(true)180                            }181                            .padding(.vertical, 11)182                            .contentShape(Rectangle())183                        }184                        .buttonStyle(.plain)185                        Divider().overlay(Theme.line)186                    }187                }188                // toute la liste vient de l'annuaire : le filtre `broker=` de la recherche compare le nom publié par189                // la source et n'en retrouverait qu'une partie190                if d.listings.count > shown {191                    Button { withAnimation(.snappy) { shown = d.listings.count } } label: {192                        Label("Afficher les \(Fmt.int(d.listings.count - shown)) autres", systemImage: "chevron.down").frame(maxWidth: .infinity)193                    }194                    .buttonStyle(SoftButtonStyle())195                    .accessibilityIdentifier("broker.listings.more")196                }197            }198        }199    }200}201
Files main
Menu

Theme