SPB Git

Repository Public

SettingsView.swift 14.7 KB 248 lines swift

1//2//  Fabri-Ka iOS v23//  File: FabriKa/Features/More/SettingsView.swift4//  Description: réglages (apparence, animations, données de l'appareil) et pages fixes — à propos, méthode et5//               sources (règle « public » et ce qu'elle écarte, état de la collecte), confidentialité.6//7//  Author: Simon-Pierre Boucher8//  Contact: contact@spboucher.ai9//1011import SwiftUI1213struct SettingsView: View {14    @Environment(AppModel.self) private var model15    @Environment(Library.self) private var library16    @Environment(MotionCenter.self) private var motion17    @Environment(\.accessibilityReduceMotion) private var reduceMotion18    @State private var confirmErase = false1920    var body: some View {21        @Bindable var model = model22        @Bindable var motion = motion23        ScrollView {24            VStack(alignment: .leading, spacing: 0) {25                title("Apparence")26                Picker("Apparence", selection: $model.appearance) {27                    ForEach(Appearance.allCases) { Text($0.label).tag($0) }28                }29                .pickerStyle(.segmented)30                .accessibilityIdentifier("appearance-picker")3132                title("Animations")33                Picker("Animations", selection: $motion.preference) {34                    ForEach(MotionCenter.Preference.allCases) { Text($0.label).tag($0) }35                }36                .pickerStyle(.segmented)37                .accessibilityIdentifier("motion-picker")38                Text(reduceMotion39                    ? "« Réduire les animations » est activé dans les réglages de l'iPhone : aucune enseigne ne tombe, aucune photo ne voyage."40                    : "À l'ouverture d'une fiche, la photo voyage et l'enseigne de la boutique se pose : en entier aux deux premières fiches, plus brièvement ensuite. « Discrètes » raccourcit le geste ; « Aucune » montre la fiche d'emblée.")41                    .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true).padding(.top, 10)4243                title("Sur cet appareil")44                FactRow("Produits favoris", Fmt.count(library.favorites.count))45                FactRow("Boutiques suivies", Fmt.count(library.stores.count))46                FactRow("Fiches vues récemment", Fmt.count(library.recents.count))47                FactRow("Recherches récentes", Fmt.count(library.searches.count), divider: false)48                Button("Effacer mes données de l'appareil") { confirmErase = true }49                    .buttonStyle(SecondaryButtonStyle()).frame(maxWidth: 380).padding(.top, 12)50                    .accessibilityIdentifier("erase-data")51                Text("Aucun compte, aucune connexion : rien de ceci n'existe ailleurs que sur cet appareil.")52                    .font(.footnote).foregroundStyle(Theme.ink3).fixedSize(horizontal: false, vertical: true).padding(.top, 10)5354                title("Fabri-Ka")55                NavRow(icon: "ic-boutique", title: "À propos") { model.open(.about) }56                NavRow(icon: "ic-liste", title: "Méthode et sources") { model.open(.method) }57                NavRow(icon: "ic-en-stock", title: "Confidentialité") { model.open(.privacy) }58                NavRow(icon: "ic-inscrire", title: "Inscrire une boutique", divider: false) { model.open(.register) }5960                Text("Version \(Bundle.main.infoDictionary?["CFBundleShortVersionString"] as? String ?? "2.0.0") (\(Bundle.main.infoDictionary?["CFBundleVersion"] as? String ?? "1"))")61                    .font(.footnote).num().foregroundStyle(Theme.ink3).padding(.top, 28)62            }63            .pageColumn()64            .padding(.bottom, 40)65        }66        .linen()67        .navigationTitle("Réglages")68        .confirmationDialog("Effacer vos favoris, vos boutiques suivies, vos fiches récentes et vos recherches ?", isPresented: $confirmErase, titleVisibility: .visible) {69            Button("Tout effacer", role: .destructive) {70                library.eraseAll()71                ResponseCache.clear()72                model.showToast("Données de l'appareil effacées")73            }74            Button("Annuler", role: .cancel) {}75        }76    }7778    private func title(_ s: String) -> some View {79        Text(s).font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 30).padding(.bottom, 10)80            .accessibilityAddTraits(.isHeader)81    }82}8384/// Paragraphe de page fixe.85private struct Prose: View {86    let text: String87    var body: some View {88        Text(text).font(.body).foregroundStyle(Theme.ink2).lineSpacing(3).fixedSize(horizontal: false, vertical: true)89    }90}9192struct AboutView: View {93    @Environment(AppModel.self) private var model94    @State private var info = ServiceInfo.cached95    @State private var mail: IdentifiedURL?96    @Environment(\.openURL) private var openURL9798    var body: some View {99        ScrollView {100            VStack(alignment: .leading, spacing: 16) {101                Wordmark(size: 30).padding(.top, 12)102                Text("Ce que font les boutiques du Québec, et où les trouver.")103                    .font(.editorial(24)).foregroundStyle(Theme.ink).fixedSize(horizontal: false, vertical: true)104                Prose(text: "Fabri-Ka recense les boutiques en ligne du Québec et ce qu'elles vendent. On n'achète rien ici : chaque produit mène à sa boutique. C'est un outil de découverte : trouver un artisan, un producteur, une boutique, par produit, par catégorie, par région.")105                if let info, let p = info.products, let s = info.stores {106                    VStack(spacing: 0) {107                        FactRow("Produits publiés", Fmt.count(p))108                        FactRow("Boutiques", Fmt.count(s))109                        FactRow("Dernier relevé", Fmt.date(info.lastCollectAt ?? info.generatedAt), divider: false)110                    }111                }112                Text("Ce que « boutique du Québec » veut dire").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 10)113                Prose(text: "Fabri-Ka sait qu'une boutique est établie au Québec et répertoriée par un organisme québécois. Il ne sait pas, produit par produit, où l'objet a été fabriqué. L'origine se dit donc par le lieu de la boutique, jamais par une garantie. Quand une boutique revend aussi des produits d'ailleurs, c'est écrit.")114                Text("Sans compte").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 10)115                Prose(text: "L'app ne demande ni compte ni connexion. Vos favoris, vos boutiques suivies et vos réglages restent sur l'appareil.")116                VStack(spacing: 0) {117                    NavRow(icon: "ic-liste", title: "Méthode et sources") { model.open(.method) }118                    NavRow(icon: "ic-en-stock", title: "Confidentialité") { model.open(.privacy) }119                    NavRow(icon: "ic-inscrire", title: "Inscrire une boutique") { model.open(.register) }120                    NavRow(icon: "ic-lien-boutique", title: "Écrire à Fabri-Ka", detail: "contact@spboucher.ai", divider: false) {121                        if let u = URL(string: "mailto:contact@spboucher.ai") { openURL(u) }122                    }123                }124                .padding(.top, 8)125            }126            .pageColumn()127            .padding(.bottom, 40)128        }129        .linen()130        .navigationTitle("À propos")131        .navigationBarTitleDisplayMode(.inline)132        .task { if let v = try? await APIClient.shared.version() { info = v } }133    }134}135136struct MethodView: View {137    @State private var rules: Loadable<PublicRules> = .loading138    @State private var sources: Sources?139140    var body: some View {141        ScrollView {142            VStack(alignment: .leading, spacing: 14) {143                Prose(text: "Les catalogues publics des boutiques sont lus par leur plateforme (Shopify, WooCommerce, Wix, Square, Squarespace…), plusieurs fois par jour. Une seule règle décide de ce qui est publié ; elle est appliquée partout, et la voici telle que le service la publie.")144                    .padding(.top, 8)145                switch rules {146                case .loading: LoadingSign(label: "Chargement de la méthode")147                case .failed(let e): ErrorState(error: e) { Task { await load() } }148                case .loaded(let r, let stale):149                    if stale { StaleBanner() }150                    Text("Ce qui est publié").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 10)151                    VStack(alignment: .leading, spacing: 10) {152                        ForEach(Array(r.rules.enumerated()), id: \.offset) { i, rule in153                            HStack(alignment: .firstTextBaseline, spacing: 10) {154                                Text("\(i + 1)").font(.footnote.weight(.semibold)).num().foregroundStyle(Theme.ink3).frame(width: 18, alignment: .trailing)155                                Text(rule).font(.subheadline).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)156                            }157                        }158                    }159                    Text("En chiffres").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 14)160                    VStack(spacing: 0) {161                        if let v = r.active { FactRow("Produits actifs relevés", Fmt.count(v)) }162                        if let v = r.publicProducts { FactRow("Produits publiés", Fmt.count(v)) }163                        if let v = r.excludedProducts { FactRow("Produits écartés", Fmt.count(v)) }164                        if let v = r.registry { FactRow("Boutiques au registre", Fmt.count(v)) }165                        if let v = r.publicStores { FactRow("Boutiques publiées", Fmt.count(v)) }166                        if let v = r.directoryOnly { FactRow("Fiches annuaire, sans catalogue suivi", Fmt.count(v)) }167                        if let v = r.withoutPosition { FactRow("Boutiques sans position connue", Fmt.count(v), divider: false) }168                    }169                    if !r.excluded.isEmpty {170                        Text("Pourquoi un produit n'est pas publié").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 14)171                        VStack(spacing: 0) {172                            ForEach(r.excluded.filter { $0.n > 0 }.prefix(12)) { e in173                                FactRow(e.label.prefix(1).uppercased() + e.label.dropFirst(), Fmt.count(e.n))174                            }175                        }176                    }177                    if let m = r.meaning {178                        Text("Ce que « québécois » veut dire").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 14)179                        Prose(text: m)180                    }181                }182                if let s = sources {183                    Text("État de la collecte").font(.editorial(20)).foregroundStyle(Theme.ink).padding(.top, 14)184                    VStack(spacing: 0) {185                        if let v = s.followed { FactRow("Boutiques suivies par la collecte", Fmt.count(v)) }186                        if let v = s.failing { FactRow("En échec en ce moment", Fmt.count(v)) }187                        if let v = s.cadenceHours { FactRow("Cadence", "toutes les \(Int(v)) h") }188                        if let v = s.syncs24h { FactRow("Passes depuis 24 h", Fmt.count(v)) }189                        if let a = s.added24h, let r = s.removed24h { FactRow("Produits apparus, retirés (24 h)", "\(Fmt.count(a)), \(Fmt.count(r))") }190                        FactRow("Dernière écriture", Fmt.ago(s.lastCollectAt) ?? "—", divider: false)191                    }192                    if !s.platforms.isEmpty {193                        Text("Par plateforme").eyebrowStyle().padding(.top, 12)194                        VStack(spacing: 0) {195                            ForEach(s.platforms.filter { $0.publicStores > 0 }.prefix(8)) { p in196                                FactRow(p.name, Fmt.stores(p.publicStores) + " · " + Fmt.products(p.publicProducts))197                            }198                        }199                    }200                    if !s.listedBy.isEmpty {201                        Text("Répertoires consultés").eyebrowStyle().padding(.top, 12)202                        Text(s.listedBy.joined(separator: ", ") + ".").font(.footnote).foregroundStyle(Theme.ink2).fixedSize(horizontal: false, vertical: true)203                    }204                }205            }206            .pageColumn()207            .padding(.bottom, 40)208        }209        .linen()210        .navigationTitle("Méthode et sources")211        .navigationBarTitleDisplayMode(.inline)212        .task { await load() }213    }214215    private func load() async {216        if let s = await Loadable.from({ try await APIClient.shared.publicRules() }) { rules = s }217        sources = try? await APIClient.shared.sources().value218    }219}220221struct PrivacyView: View {222    var body: some View {223        ScrollView {224            VStack(alignment: .leading, spacing: 14) {225                Text("L'app ne sait pas qui vous êtes.").font(.editorial(24)).foregroundStyle(Theme.ink).padding(.top, 8)226                    .fixedSize(horizontal: false, vertical: true)227                block("Aucun compte", "Fabri-Ka n'a ni compte, ni connexion, ni témoin. L'app n'envoie aucun identifiant, ne suit rien et ne contient aucun outil de mesure ni de publicité.")228                block("Ce qui reste sur l'appareil", "Vos favoris, vos boutiques suivies, les fiches vues récemment, vos recherches récentes et vos réglages sont gardés sur cet appareil, dans le dossier de l'app. « Effacer mes données », dans les réglages, les supprime.")229                block("Ce que l'app demande au service", "Pour afficher le répertoire, l'app interroge le service de Fabri-Ka : recherches, fiches, photos. Les photos passent toujours par Fabri-Ka : votre appareil ne contacte le site d'une boutique que lorsque vous touchez « Voir chez la boutique » ou « Voir son site ». Le service ne tient aucun journal des requêtes ni des adresses IP.")230                block("Inscription d'une boutique", "Si vous inscrivez une boutique, les renseignements du formulaire (nom, spécialité, description, ville et code postal, site, courriel, téléphone, réseaux sociaux) sont conservés pour traiter la demande, avec une empreinte irréversible de l'adresse IP qui ne sert qu'à limiter les abus. L'adresse IP elle-même n'est conservée nulle part.")231                block("Nous joindre", "contact@spboucher.ai")232            }233            .pageColumn()234            .padding(.bottom, 40)235        }236        .linen()237        .navigationTitle("Confidentialité")238        .navigationBarTitleDisplayMode(.inline)239    }240241    private func block(_ title: String, _ text: String) -> some View {242        VStack(alignment: .leading, spacing: 6) {243            Text(title).font(.editorial(19)).foregroundStyle(Theme.ink).padding(.top, 10).accessibilityAddTraits(.isHeader)244            Prose(text: text)245        }246    }247}248
Files main
Menu

Theme