SPB Git

Repository Public

HomeView.swift 9.1 KB 203 lines swift

1// =============================================================================2//                  SP BOUCHER | SOFTWARE & RESEARCH3//             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project          : SP Search iOS9// File             : Features/Search/HomeView.swift10// Description      : Home under the search field: recent searches or examples,11//                    and the engine's own state from /v2/status.12// Module           : Features13// Repository       : https://git.spboucher.ai/sp-search-ios14// Project Website  : https://search.spboucher.ai15// Created          : 2026-12-0116// Last Modified    : 2026-12-0117//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 SPSearchKit91import SwiftUI9293struct HomeView: View {94    @Environment(SearchModel.self) private var model95    var onPick: (String) -> Void96    var onShowHistory: () -> Void9798    /// Each shows one form of the query syntax.99    static let examples = ["université laval", "\"changement climatique\"", "histoire du Québec", "rust site:wikipedia.org", "intitle:météo lang:fr", "pain au levain -machine"]100101    private var recents: [HistoryEntry] { model.historyEnabled ? Array(model.history.prefix(4)) : [] }102103    var body: some View {104        ScrollView {105            VStack(alignment: .leading, spacing: 30) {106                if recents.isEmpty {107                    VStack(alignment: .leading, spacing: 12) {108                        Eyebrow("Essayer")109                        FlowLayout(spacing: 8) {110                            ForEach(Self.examples, id: \.self) { q in111                                Button { onPick(q) } label: { Text(verbatim: q) }112                                    .buttonStyle(ChipStyle(mono: true))113                                    .accessibilityHint("Lance cette recherche")114                            }115                        }116                    }117                } else {118                    VStack(alignment: .leading, spacing: 4) {119                        HStack(alignment: .firstTextBaseline) {120                            Eyebrow("Recherches récentes")121                            Spacer()122                            Button("Tout voir", action: onShowHistory).font(.footnote.weight(.medium))123                        }124                        .padding(.bottom, 6)125                        ForEach(recents) { entry in126                            Button { onPick(entry.query) } label: {127                                HStack(spacing: 12) {128                                    Image(systemName: "clock").font(.footnote).foregroundStyle(Theme.muted).frame(minWidth: 20).accessibilityHidden(true)129                                    Text(verbatim: entry.query).font(.body).foregroundStyle(Theme.ink).lineLimit(2).multilineTextAlignment(.leading)130                                    Spacer(minLength: 8)131                                    Image(systemName: "arrow.up.left").font(.footnote).foregroundStyle(Theme.ruleStrong).accessibilityHidden(true)132                                }133                                .padding(.vertical, 11)134                                .contentShape(Rectangle())135                            }136                            .buttonStyle(.plain)137                            .accessibilityHint("Relance cette recherche")138                            Rule()139                        }140                    }141                }142                EngineStatusLine(state: model.status)143            }144            .padding(.horizontal, 20).padding(.top, 22).padding(.bottom, 32)145            .frame(maxWidth: 680, alignment: .leading)146            .frame(maxWidth: .infinity)147        }148        .scrollDismissesKeyboard(.interactively)149    }150}151152/// A discreet line fed by `/v2/status`: state of the engine, size and age of the index. When the status cannot be153/// read the line says so; it never shows invented figures.154struct EngineStatusLine: View {155    let state: SearchModel.StatusState156157    var body: some View {158        VStack(alignment: .leading, spacing: 8) {159            switch state {160            case .unknown:161                Text(verbatim: "— — —").font(.data(.caption)).foregroundStyle(Theme.muted).redacted(reason: .placeholder)162                    .accessibilityLabel("Chargement de l’état de l’index")163            case .failed:164                Text("L’état de l’index est indisponible pour le moment.").font(.footnote).foregroundStyle(Theme.muted)165            case .loaded(let s):166                HStack(alignment: .firstTextBaseline, spacing: 8) {167                    if s.level != .unknown {168                        Circle().fill(Self.tone(s.level)).frame(width: 7, height: 7).alignmentGuide(.firstTextBaseline) { $0[.bottom] - 1 }169                            .accessibilityHidden(true)170                    }171                    Text(verbatim: Self.summary(s))172                        .font(.data(.caption)).foregroundStyle(Theme.muted)173                        .fixedSize(horizontal: false, vertical: true)174                }175                .accessibilityElement(children: .combine)176            }177            Text("Une fraction du Web public, pas tout Internet. Sans pistage, sans publicité, sans compte.")178                .font(.footnote)179                .foregroundStyle(Theme.muted)180                .fixedSize(horizontal: false, vertical: true)181        }182    }183184    static func tone(_ level: EngineStatus.Level) -> Color {185        switch level {186        case .ok: Theme.ok187        case .degraded: Theme.warn188        case .down: Theme.danger189        case .off, .unknown: Theme.ruleStrong190        }191    }192193    /// "En service · 17 491 959 documents · 665 369 domaines · index mis à jour il y a 2 minutes"194    static func summary(_ s: EngineStatus, now: Date = Date()) -> String {195        var parts: [String] = []196        if s.level != .unknown { parts.append(Format.engineLevel(s.level)) }197        if s.documents > 0 { parts.append(String(localized: "\(Format.count(s.documents)) documents")) }198        if s.domains > 0 { parts.append(String(localized: "\(Format.count(s.domains)) domaines")) }199        if let d = s.updatedAt { parts.append(String(localized: "index mis à jour \(Format.relative(d, now: now))")) }200        return parts.joined(separator: " · ")201    }202}203
Files main
Menu

Theme