SPB Git

spb/vrai-prix-ios Public

App iOS native de Vrai-Prix — estimation immobilière transparente pour le Québec (SwiftUI, MapKit, Swift Charts)

Swift 100%
2.1 KB · 59 lines swift
Raw Blame History
1// Auteur : Simon-Pierre Boucher — contact@spboucher.ai2// Charge l'estimation complète d'une unité puis affiche EstimateView.3import SwiftUI45struct EstimateLoaderView: View {6    let searchResult: SearchResult7    @State private var data: UnitEstimate?8    @State private var errorMessage: String?910    var body: some View {11        Group {12            if let data {13                EstimateView(data: data)14            } else if let errorMessage {15                VStack(spacing: 14) {16                    Text("!").font(.vpDisplay(40)).foregroundStyle(Color.vpLime)17                    Text(errorMessage)18                        .font(.vpBody(15))19                        .foregroundStyle(Color.vpInk2)20                        .multilineTextAlignment(.center)21                    Button("Réessayer") {22                        self.errorMessage = nil23                        Task { await load() }24                    }25                    .buttonStyle(VPGhostButtonStyle())26                    .frame(width: 180)27                }28                .padding(24)29                .frame(maxWidth: .infinity, maxHeight: .infinity)30                .background(Color.vpPaper)31            } else {32                VStack(spacing: 14) {33                    ProgressView()34                        .controlSize(.large)35                    Text("Calcul de l'estimation…")36                        .font(.vpMono(11))37                        .tracking(1.2)38                        .foregroundStyle(Color.vpInk2)39                    Text("Comparables + modèle hédonique")40                        .font(.vpBody(13))41                        .foregroundStyle(Color.vpInk3)42                }43                .frame(maxWidth: .infinity, maxHeight: .infinity)44                .background(Color.vpPaper)45                .task { await load() }46            }47        }48        .navigationBarTitleDisplayMode(.inline)49    }5051    private func load() async {52        do {53            data = try await VraiPrixAPI.shared.estimate(id: searchResult.id)54        } catch {55            errorMessage = error.localizedDescription56        }57    }58}59