SPB Git

Repository Public

ExploreView.swift 29.0 KB 589 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : Immo-Ka iOS9// File             : ImmoKa/Features/Explore/ExploreView.swift10// Description      : Explorer — carte plein écran, tiroir de résultats à crans11//                    (iPhone) ou panneau latéral (iPad), filtres.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-2817//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 ExploreView: View {93    @Environment(AppModel.self) private var app94    @Environment(Library.self) private var library95    @Environment(\.horizontalSizeClass) private var hSize96    @Environment(DoorCenter.self) private var door97    @Environment(\.accessibilityReduceMotion) private var reduceMotion98    @State private var model = ExploreModel()99    @State private var location = LocationProvider()100    @State private var detent: DrawerDetent = .peek101    @State private var showFilters = false102    @State private var showPlaces = false103    @State private var showLegend = false104    @Environment(\.colorScheme) private var scheme105106    private static let kinds = ["Maison", "Condo", "Duplex", "Triplex", "Chalet", "Terrain"]107108    var body: some View {109        GeometryReader { geo in110            let wide = hSize == .regular && geo.size.width > 780111            ZStack(alignment: .topLeading) {112                map(bottomInset: wide ? 0 : DrawerDetent.peek.height(in: geo.size.height))113                    .ignoresSafeArea(edges: wide ? [.bottom] : [.top, .bottom])114                    .padding(.leading, wide ? 400 : 0)115116                if wide {117                    VStack(spacing: 0) {118                        topBar.dynamicTypeSize(...DynamicTypeSize.xxLarge).padding(.horizontal, 14).padding(.top, 10).padding(.bottom, 8)119                        ResultsList(model: model, layout: .row)120                    }121                    .frame(width: 400)122                    .background(Theme.bg)123                    .overlay(alignment: .trailing) { Rectangle().fill(Theme.line).frame(width: 1) }124                    mapControls.padding(.leading, 400).frame(maxWidth: .infinity, alignment: .trailing)125                    counter.padding(.leading, 400).frame(maxWidth: .infinity)126                    preview.dynamicTypeSize(...DynamicTypeSize.xxLarge).frame(maxWidth: 420).padding(.leading, 400 + 16).padding(.bottom, 24)127                        .frame(maxHeight: .infinity, alignment: .bottom)128                } else {129                    // les commandes posées sur la carte ont une place comptée : leur texte grandit jusqu'à un plafond130                    VStack(spacing: 8) {131                        topBar132                        counter133                    }134                    .dynamicTypeSize(...DynamicTypeSize.xxLarge)135                    .padding(.horizontal, 12).padding(.top, 6)136                    mapControls.padding(.top, 118).frame(maxWidth: .infinity, alignment: .trailing)137                    preview138                        .dynamicTypeSize(...DynamicTypeSize.xxLarge)139                        .padding(.horizontal, 12)140                        .padding(.bottom, DrawerDetent.peek.height(in: geo.size.height) + 10)141                        .frame(maxHeight: .infinity, alignment: .bottom)142                        .opacity(detent == .peek ? 1 : 0)143                    SnapDrawer(detent: $detent, height: geo.size.height) {144                        ResultsHeader(model: model).dynamicTypeSize(...DynamicTypeSize.xxLarge)145                    } content: {146                        ResultsList(model: model, layout: .grid, showsHeader: false)147                            .opacity(detent == .peek ? 0 : 1)148                            .accessibilityHidden(detent == .peek)149                    }150                }151            }152        }153        .background(Theme.bg)154        .toolbar(.hidden, for: .navigationBar)155        .sheet(isPresented: $showFilters) { FiltersSheet(model: model) }156        .sheet(isPresented: $showPlaces) { PlaceSearchSheet(model: model) }157        .task {158            model.start()159            #if DEBUG160            // -IKSheet places|filters : ouvre une feuille au lancement (captures d'écran)161            switch UserDefaults.standard.string(forKey: "IKSheet") {162            case "places": showPlaces = true163            case "filters": showFilters = true164            default: break165            }166            #endif167        }168        .onChange(of: app.pendingSearch, initial: true) { _, pending in169            guard let pending else { return }170            model.apply(pending.filters, sort: pending.sort, title: pending.title)171            app.pendingSearch = nil172            detent = .peek173        }174        .animation(.snappy(duration: 0.28), value: model.selectedUID)175    }176177    private func map(bottomInset: CGFloat) -> some View {178        ListingsMapView(items: model.items, selectedUID: model.selectedUID, seen: library.seenIDs,179                        command: model.command, showsUser: location.authorized, bottomInset: bottomInset,180                        onRegion: { b, size in model.regionChanged(b, size: size) },181                        onSelect: { uid in model.selectedUID = uid },182                        onOpen: { uid, frame in183                            // deuxième toucher sur la maison sélectionnée : la porte s'ouvre depuis le marqueur184                            door.open(uid: uid, image: model.selected?.images.first, from: frame, origin: .mapPill, reduceMotion: reduceMotion) { app.open(.listing(uid)) }185                        })186            // voile à la marque : chaux chaude en thème clair, nuit en thème sombre (MapKit ne permet pas de recolorer le fond)187            .overlay {188                (scheme == .dark ? Theme.nightBase.opacity(0.22) : Color(hex: 0xC9B58E).opacity(0.14))189                    .blendMode(scheme == .dark ? .normal : .multiply)190                    .allowsHitTesting(false)191            }192            .accessibilityLabel("Carte des propriétés à vendre")193    }194195    /// Nom de la bannière, de l'agence ou de la source dont on liste les propriétés.196    private var placeName: String? {197        if model.filters.agency == nil, model.filters.source == nil { return nil }198        return model.placeTitle ?? model.filters.agency ?? model.filters.source.map { $0.contains(",") ? "Plusieurs sources" : app.sourceName($0) }199    }200201    // MARK: Barre du haut202203    /// Ce que dit le champ de recherche : le lieu, le courtier, la phrase libre, sinon l'invitation.204    private var searchLabel: String {205        let f = model.filters206        if let s = f.sector { return f.city.map { "\(s), \($0)" } ?? s }207        if let c = f.city { return c }208        if let p = placeName { return p }209        if let b = f.broker { return b }210        if let r = f.region { return r }211        if let n = f.nl { return n }212        if let t = f.text { return t }213        return model.usesV3 ? "Ville, quartier ou phrase libre" : "Ville, adresse, agence"214    }215216    private var topBar: some View {217        VStack(spacing: 8) {218            HStack(spacing: 8) {219                Button { showPlaces = true } label: {220                    HStack(spacing: 10) {221                        Image(systemName: "magnifyingglass").font(.system(size: 15, weight: .semibold)).foregroundStyle(Theme.ink3)222                        Text(searchLabel)223                            .font(.subheadline.weight(model.filters.hasPlace ? .semibold : .regular))224                            .foregroundStyle(model.filters.hasPlace ? Theme.ink : Theme.ink3)225                            .lineLimit(1)226                        Spacer(minLength: 0)227                        if model.filters.hasPlace {228                            Button {229                                model.placeTitle = nil230                                var f = model.filters; f.city = nil; f.sector = nil; f.text = nil; f.nl = nil; f.source = nil; f.agency = nil; f.region = nil; f.broker = nil; model.filters = f231                            } label: {232                                Image(systemName: "xmark.circle.fill").foregroundStyle(Theme.ink3)233                            }234                            .accessibilityLabel("Effacer le lieu")235                        }236                    }237                    .padding(.horizontal, 14)238                    .frame(height: 46)239                    .solidControl(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))240                }241                .buttonStyle(.plain)242                .accessibilityLabel("Chercher un lieu")243                .accessibilityIdentifier("explore.search")244245                Button { showFilters = true } label: {246                    Image(systemName: "slider.horizontal.3")247                        .font(.system(size: 16, weight: .semibold))248                        .foregroundStyle(model.filters.activeCount > 0 ? Theme.brand : Theme.ink)249                        .frame(width: 46, height: 46)250                        .background(Theme.surface, in: Circle())251                        .overlay(Circle().strokeBorder(model.filters.activeCount > 0 ? Theme.brand : Theme.line2, lineWidth: 1))252                        .shadow(color: .black.opacity(0.12), radius: 6, y: 2)253                        .overlay(alignment: .topTrailing) {254                            if model.filters.activeCount > 0 {255                                Text("\(model.filters.activeCount)").font(.caption2.weight(.bold)).foregroundStyle(Theme.brandInk)256                                    .frame(width: 18, height: 18).background(Theme.brand, in: Circle()).offset(x: 3, y: -3)257                            }258                        }259                }260                .buttonStyle(.plain)261                .accessibilityLabel("Filtres\(model.filters.activeCount > 0 ? ", \(model.filters.activeCount) actifs" : "")")262                .accessibilityIdentifier("explore.filters")263            }264            ScrollView(.horizontal, showsIndicators: false) {265                HStack(spacing: 7) {266                    QuickChip(label: "Sous le prix attendu", icon: "arrow.down.to.line", active: model.filters.deal == .sous, tint: Theme.good) {267                        model.filters.deal = model.filters.deal == .sous ? nil : .sous268                    }269                    ForEach(Self.kinds, id: \.self) { s in270                        QuickChip(label: s, active: model.filters.propertyType == s) {271                            model.filters.propertyType = model.filters.propertyType == s ? nil : s272                        }273                    }274                    QuickChip(label: "3 ch. et plus", icon: "bed.double", active: model.filters.bedroomsMin == 3) {275                        model.filters.bedroomsMin = model.filters.bedroomsMin == 3 ? nil : 3276                    }277                }278                .padding(.horizontal, 1)279            }280            .scrollClipDisabled()281            if !model.interpreted.isEmpty {282                // phrase libre : ce que le service a compris, sous la barre283                ScrollView(.horizontal, showsIndicators: false) {284                    HStack(spacing: 6) {285                        Text("Compris :").font(.caption.weight(.semibold)).foregroundStyle(Theme.ink2)286                        ForEach(model.interpreted) { u in287                            Text(u.label).font(.caption.weight(.medium)).strikethrough(u.ignored)288                                .foregroundStyle(u.ignored ? Theme.ink3 : Theme.ink)289                        }290                    }291                    .padding(.horizontal, 12).padding(.vertical, 7)292                    .solidControl(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))293                }294                .scrollClipDisabled()295                .accessibilityIdentifier("explore.interpreted")296            }297        }298    }299300    private var counter: some View {301        HStack(spacing: 7) {302            if model.loadingPoints { ProgressView().controlSize(.mini).tint(Theme.brand) }303            Text(model.pointsError != nil ? "Connexion impossible"304                 : model.total.map { Fmt.plural($0, "propriété", "propriétés") } ?? "Chargement des propriétés…")305                .font(.footnote.weight(.semibold)).num()306        }307        .foregroundStyle(Theme.ink)308        .padding(.horizontal, 14).padding(.vertical, 8)309        .solidControl(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))310        .padding(.top, hSize == .regular ? 12 : 0)311        .accessibilityIdentifier("explore.counter")312        .onTapGesture { if model.pointsError != nil { model.retry() } }313    }314315    // commandes fines, groupées : zoom, autour de moi, légende repliable316    private var mapControls: some View {317        HStack(alignment: .top, spacing: 8) {318            if showLegend {319                legend.transition(.asymmetric(insertion: .move(edge: .trailing).combined(with: .opacity), removal: .opacity))320            }321            VStack(spacing: 8) {322                VStack(spacing: 0) {323                    controlButton("plus", "Zoom avant") { model.command = MapCommand(kind: .zoom(factor: 0.5)) }324                    Rectangle().fill(Theme.line).frame(width: 40, height: 1)325                    controlButton("minus", "Zoom arrière") { model.command = MapCommand(kind: .zoom(factor: 2)) }326                }327                .solidControl(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))328                VStack(spacing: 0) {329                    controlButton(location.authorized ? "location.fill" : "location", "Autour de moi") {330                        location.locate { c in model.center(on: c) }331                        if location.denied { app.showToast("Autorisez la localisation dans Réglages pour utiliser « Autour de moi »") }332                    }333                    Rectangle().fill(Theme.line).frame(width: 40, height: 1)334                    controlButton(showLegend ? "xmark" : "list.bullet.rectangle", showLegend ? "Fermer la légende" : "Légende") {335                        withAnimation(reduceMotion ? nil : .spring(response: 0.34, dampingFraction: 0.82)) { showLegend.toggle() }336                    }337                }338                .solidControl(RoundedRectangle(cornerRadius: Theme.radiusSmall, style: .continuous))339            }340        }341        .padding(.trailing, 12)342        .padding(.top, hSize == .regular ? 12 : 0)343    }344345    private func controlButton(_ icon: String, _ label: String, action: @escaping () -> Void) -> some View {346        Button {347            Haptics.tap()348            action()349        } label: {350            Image(systemName: icon).font(.system(size: 15, weight: .medium)).foregroundStyle(Theme.ink)351                .frame(width: 44, height: 42).contentShape(Rectangle())352        }353        .buttonStyle(.plain)354        .accessibilityLabel(label)355    }356357    /// Légende de la carte : ce que disent les étiquettes et les plaques.358    private var legend: some View {359        VStack(alignment: .leading, spacing: 9) {360            Text("Légende").font(.editorial(15)).foregroundStyle(Theme.ink)361            legendRow(fill: Theme.surface, stroke: Theme.good, text: Theme.good, sample: "385 k", label: "Sous le prix attendu")362            legendRow(fill: Theme.surface, stroke: Theme.line2, text: Theme.ink, sample: "525 k", label: "Dans l'intervalle, au-dessus ou sans position")363            legendRow(fill: Theme.surface, stroke: Theme.line2, text: Theme.high, sample: "1,2 M", label: "Élevé")364            legendRow(fill: Theme.surface2, stroke: Theme.line, text: Theme.ink3, sample: "410 k", label: "Déjà vue")365            HStack(spacing: 9) {366                VStack(spacing: 0) {367                    Rectangle().fill(Theme.accent).frame(height: 2.5)368                    Text("312").font(.editorial(12)).foregroundStyle(Theme.bg).padding(.horizontal, 6).padding(.vertical, 2)369                }370                .background(Theme.house, in: RoundedRectangle(cornerRadius: 3, style: .continuous))371                .fixedSize()372                .frame(width: 44)373                Text("Plusieurs propriétés : touchez pour zoomer").font(.caption2).foregroundStyle(Theme.ink2)374            }375            HStack(spacing: 9) {376                HStack(spacing: 3) {377                    BrandMark(angle: 62, mono: nil, showsThreshold: false).frame(width: 13, height: 13).environment(\.colorScheme, scheme == .dark ? .light : .dark)378                    Text("489 k").font(.system(size: 10, weight: .bold)).monospacedDigit().foregroundStyle(Theme.bg)379                }380                .padding(.horizontal, 4).padding(.vertical, 3)381                .background(Theme.ink, in: RoundedRectangle(cornerRadius: 4, style: .continuous))382                .frame(width: 44)383                Text("Sélection : touchez de nouveau pour entrer").font(.caption2).foregroundStyle(Theme.ink2)384            }385        }386        .padding(12)387        .frame(width: 236, alignment: .leading)388        .solidControl(RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))389        .accessibilityElement(children: .combine)390    }391392    private func legendRow(fill: Color, stroke: Color, text: Color, sample: String, label: String) -> some View {393        HStack(spacing: 9) {394            Text(sample).font(.system(size: 11, weight: .bold)).monospacedDigit().foregroundStyle(text)395                .padding(.horizontal, 6).padding(.vertical, 3)396                .background(fill, in: RoundedRectangle(cornerRadius: 5, style: .continuous))397                .overlay(RoundedRectangle(cornerRadius: 5, style: .continuous).strokeBorder(stroke, lineWidth: 1))398                .frame(width: 44)399            Text(label).font(.caption2).foregroundStyle(Theme.ink2)400        }401    }402403    @ViewBuilder404    private var preview: some View {405        if let uid = model.selectedUID {406            Group {407                if let l = model.selected {408                    ListingLink(listing: l, layout: .row, origin: .mapPill)409                } else {410                    HStack(spacing: 12) { BrandLoader(size: 30); Text("Chargement…").font(.subheadline).foregroundStyle(Theme.ink3) }411                        .frame(maxWidth: .infinity).frame(height: 118)412                        .background(Theme.surface, in: RoundedRectangle(cornerRadius: Theme.radius, style: .continuous))413                }414            }415            .shadow(color: .black.opacity(0.18), radius: 14, y: 6)416            .overlay(alignment: .topTrailing) {417                GlassIconButton(system: "xmark", tint: Theme.ink, size: 30, label: "Fermer l'aperçu") { model.selectedUID = nil }418                    .offset(x: 6, y: -8)419            }420            .id(uid)421            .transition(.move(edge: .bottom).combined(with: .opacity))422        }423    }424}425426private struct QuickChip: View {427    let label: String428    var icon: String?429    let active: Bool430    var tint: Color = Theme.brand431    let action: () -> Void432    var body: some View {433        Button {434            Haptics.select()435            action()436        } label: {437            HStack(spacing: 5) {438                if let icon { Image(systemName: icon).font(.system(size: 11, weight: .semibold)) }439                Text(label).font(.footnote.weight(.semibold))440            }441            .padding(.horizontal, 12)442            .frame(height: 34)443            .foregroundStyle(active ? Theme.brandInk : Theme.ink)444            .background(active ? tint : Theme.surface, in: RoundedRectangle(cornerRadius: 8, style: .continuous))445            .overlay(RoundedRectangle(cornerRadius: 8, style: .continuous).strokeBorder(active ? Color.clear : Theme.line2, lineWidth: 1))446            .shadow(color: .black.opacity(0.08), radius: 4, y: 1)447        }448        .buttonStyle(.plain)449        .accessibilityAddTraits(active ? .isSelected : [])450    }451}452453// MARK: - Tiroir à crans454455enum DrawerDetent: CaseIterable {456    case peek, half, full457    func height(in total: CGFloat) -> CGFloat {458        switch self {459        case .peek: 96460        case .half: total * 0.48461        case .full: total - 150462        }463    }464}465466/// Tiroir de résultats : l'en-tête se tire pour changer de cran, le contenu défile.467struct SnapDrawer<Header: View, Content: View>: View {468    @Binding var detent: DrawerDetent469    let height: CGFloat470    @ViewBuilder var header: () -> Header471    @ViewBuilder var content: () -> Content472    @GestureState private var drag: CGFloat = 0473474    var body: some View {475        let h = max(80, detent.height(in: height) - drag)476        VStack(spacing: 0) {477            VStack(spacing: 8) {478                Capsule().fill(Theme.ink3.opacity(0.5)).frame(width: 38, height: 5).padding(.top, 8)479                header()480            }481            .frame(maxWidth: .infinity)482            .contentShape(Rectangle())483            .gesture(484                DragGesture(minimumDistance: 6)485                    .updating($drag) { v, s, _ in s = v.translation.height }486                    .onEnded { v in487                        let projected = detent.height(in: height) - v.predictedEndTranslation.height488                        let best = DrawerDetent.allCases.min { abs($0.height(in: height) - projected) < abs($1.height(in: height) - projected) } ?? .peek489                        if best != detent { Haptics.tap() }490                        detent = best491                    }492            )493            .onTapGesture { detent = detent == .peek ? .half : .peek }494            .accessibilityAddTraits(.isButton)495            .accessibilityHint("Agrandit ou réduit la liste des résultats")496            content().frame(maxHeight: .infinity)497        }498        .frame(height: h, alignment: .top)499        .frame(maxWidth: .infinity)500        .background(Theme.bg, in: UnevenRoundedRectangle(topLeadingRadius: Theme.radiusPanel, topTrailingRadius: Theme.radiusPanel, style: .continuous))501        .overlay(UnevenRoundedRectangle(topLeadingRadius: Theme.radiusPanel, topTrailingRadius: Theme.radiusPanel, style: .continuous).strokeBorder(Theme.line2, lineWidth: 1))502        .shadow(color: .black.opacity(0.14), radius: 14, y: -4)503        .frame(maxHeight: .infinity, alignment: .bottom)504        .animation(.interactiveSpring(response: 0.38, dampingFraction: 0.86), value: detent)505    }506}507508// MARK: - Liste des résultats509510struct ResultsHeader: View {511    @Bindable var model: ExploreModel512    @Environment(Library.self) private var library513    @Environment(AppModel.self) private var app514515    var body: some View {516        HStack(alignment: .center) {517            VStack(alignment: .leading, spacing: 2) {518                Text(model.filters.city ?? model.placeTitle ?? model.filters.agency ?? (model.filters.text.map { "« \($0) »" } ?? "Dans cette zone"))519                    .font(.headline).foregroundStyle(Theme.ink).lineLimit(1)520                Text(model.inView.map { Fmt.plural($0, "propriété visible", "propriétés visibles") }521                     ?? ((model.listError ?? model.pointsError) != nil ? "Liste indisponible" : "Recherche…"))522                    .font(.footnote).num().foregroundStyle(Theme.ink3)523            }524            Spacer()525            Button {526                library.saveSearch(model.filters, sort: model.sort, total: model.total)527                Haptics.success()528                app.showToast("Recherche enregistrée dans vos favoris")529            } label: {530                Image(systemName: "bookmark").font(.system(size: 15, weight: .semibold)).foregroundStyle(Theme.ink2)531                    .frame(width: 40, height: 40)532            }533            .accessibilityLabel("Enregistrer cette recherche")534            Menu {535                Picker("Trier", selection: $model.sort) {536                    ForEach(SearchSort.allCases) { s in Text(s.label).tag(s) }537                }538            } label: {539                HStack(spacing: 5) {540                    Image(systemName: "arrow.up.arrow.down").font(.system(size: 11, weight: .semibold))541                    Text(model.sort.label).font(.footnote.weight(.semibold))542                }543                .foregroundStyle(Theme.ink)544                .padding(.horizontal, 12).frame(height: 36)545                .background(Theme.surface2, in: RoundedRectangle(cornerRadius: 8, style: .continuous))546            }547            .accessibilityLabel("Trier : \(model.sort.label)")548        }549        .padding(.horizontal, 16)550        .padding(.bottom, 10)551    }552}553554struct ResultsList: View {555    @Bindable var model: ExploreModel556    var layout: ListingCard.Layout557    var showsHeader = true558559    var body: some View {560        ScrollView {561            LazyVStack(spacing: 12) {562                if showsHeader { ResultsHeader(model: model).padding(.horizontal, -16).padding(.top, 4) }563                if let error = model.listError ?? model.pointsError, model.listings.isEmpty {564                    ErrorStateView(error: error) { model.retry() }565                } else if model.listings.isEmpty, model.loadingList || model.inView == nil {566                    ForEach(0..<4, id: \.self) { _ in ListingCardSkeleton() }567                } else if model.listings.isEmpty {568                    EmptyStateView(door: .closed, title: "Aucune propriété dans cette zone",569                                   message: "Dézoomez la carte ou assouplissez un filtre : de nouvelles inscriptions arrivent chaque jour.",570                                   actionTitle: model.filters.isEmpty ? nil : "Effacer les filtres") { model.filters = SearchFilters() }571                } else {572                    ForEach(Array(model.listings.enumerated()), id: \.element.id) { i, l in573                        ListingLink(listing: l, layout: layout).staggered(i).onAppear { model.loadMoreIfNeeded(l) }574                    }575                    if model.loadingList { BrandLoader(size: 28).padding() }576                    else if model.unpositioned > 0 {577                        Text("\(Fmt.plural(model.unpositioned, "autre propriété correspond", "autres propriétés correspondent")) à vos filtres sans adresse précise, donc hors carte.")578                            .font(.footnote).foregroundStyle(Theme.ink3).multilineTextAlignment(.center).padding()579                    }580                }581            }582            .padding(.horizontal, 16)583            .padding(.bottom, 24)584        }585        .scrollDismissesKeyboard(.immediately)586        .accessibilityIdentifier("explore.results")587    }588}589
Files main
Menu

Theme