Repository Public
1// =============================================================================2// SP BOUCHER | SOFTWARE & RESEARCH3// ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING4// =============================================================================5//6// PROJECT METADATA7// -----------------------------------------------------------------------------8// Project : SP Search iOS9// File : Features/Favorites/FavoritesView.swift10// Description : Saved results, on this device only: open, share, remove.11// Module : Features12// Repository : https://git.spboucher.ai/sp-search-ios13// Project Website : https://search.spboucher.ai14// Created : 2026-12-0115// Last Modified : 2026-12-0116//17// =============================================================================18// AUTHOR & PROFESSIONAL AFFILIATION19// =============================================================================20//21// Author : Simon-Pierre Boucher22// Position : Professor of Finance23// Institution : Université du Québec en Outaouais (UQO)24// Department : Département des sciences administratives25// Organization : SP Boucher26//27// Website : https://spboucher.ai28// Git : https://git.spboucher.ai29//30// =============================================================================31// OFFICIAL CONTACT DIRECTORY32// =============================================================================33//34// General : info@spboucher.ai35// Professional : contact@spboucher.ai36// Direct : simon@spboucher.ai37// Research : research@spboucher.ai38// Development : dev@spboucher.ai39// Support : support@spboucher.ai40// Security/Admin : admin@spboucher.ai41// Notifications : notifications@spboucher.ai42//43// Preferred Contact: support@spboucher.ai44//45// =============================================================================46// COPYRIGHT & INTELLECTUAL PROPERTY47// =============================================================================48//49// Copyright (c) 202650// Simon-Pierre Boucher51//52// All rights reserved where applicable.53//54// This file is governed by the applicable project license,55// copyright notices, institutional agreements and relevant law.56//57// Unless expressly authorized by the applicable license or58// rights holder, copying, redistribution, sublicensing,59// publication and commercial exploitation are not permitted.60//61// Existing third-party rights and notices remain unaffected.62//63// =============================================================================64// CONFIDENTIALITY & SECURITY65// =============================================================================66//67// Classification : Public68// Distribution : Public repository; use is governed by the project license69// Security Contact : admin@spboucher.ai70//71// Access to this source does not independently grant permission72// to redistribute or disclose confidential materials.73//74// Do not embed credentials, private keys, access tokens,75// certificates or confidential personal information.76//77// =============================================================================78// LICENSE & MAINTENANCE79// =============================================================================80//81// License : None specified (no license file in this repository)82// Maintainer : Simon-Pierre Boucher83// Technical Contact: dev@spboucher.ai84//85// =============================================================================86// END OF SP BOUCHER SOURCE HEADER87// =============================================================================8889import SPSearchKit90import SwiftUI9192struct FavoritesView: View {93 @Environment(FavoritesModel.self) private var favorites94 @Environment(\.dismiss) private var dismiss95 @State private var confirmClear = false96 var onOpen: (URL) -> Void9798 var body: some View {99 NavigationStack {100 List {101 if favorites.items.isEmpty {102 Section {103 VStack(alignment: .leading, spacing: 8) {104 Text("Aucun favori").font(.display(.title2)).foregroundStyle(Theme.ink)105 Text("Enregistrez un résultat depuis son aperçu ou par un appui long. Les favoris restent sur cet appareil ; ils sont aussi proposés par la recherche du système (Spotlight).")106 .font(.subheadline).foregroundStyle(Theme.muted)107 }108 .padding(.vertical, 8)109 .listRowBackground(Color.clear)110 }111 } else {112 Section {113 ForEach(favorites.items) { f in114 Button { if let url = f.link { onOpen(url) } } label: { row(f) }115 .buttonStyle(.plain)116 .accessibilityHint("Ouvre la page")117 .swipeActions(edge: .trailing) {118 Button("Retirer", role: .destructive) { favorites.remove(f.url) }119 }120 .contextMenu {121 if let url = f.link {122 ShareLink(item: url, subject: Text(verbatim: f.title)) { Label("Partager…", systemImage: "square.and.arrow.up") }123 }124 Button(role: .destructive) { favorites.remove(f.url) } label: { Label("Retirer des favoris", systemImage: "star.slash") }125 }126 }127 .onDelete { offsets in offsets.map { favorites.items[$0].url }.forEach(favorites.remove) }128 } footer: {129 Text("Conservés sur cet appareil seulement. Le texte affiché est celui du jour de l’enregistrement.")130 }131 }132 }133 .scrollContentBackground(.hidden)134 .background(Theme.paper)135 .navigationTitle("Favoris")136 .navigationBarTitleDisplayMode(.inline)137 .toolbar {138 ToolbarItem(placement: .cancellationAction) { Button("Fermer") { dismiss() } }139 ToolbarItem(placement: .destructiveAction) {140 Button("Tout retirer", role: .destructive) { confirmClear = true }.disabled(favorites.items.isEmpty)141 }142 }143 .alert("Retirer tous les favoris ?", isPresented: $confirmClear) {144 Button("Tout retirer", role: .destructive) { favorites.clear() }145 Button("Annuler", role: .cancel) {}146 } message: {147 Text("Ils sont supprimés de cet appareil. L’action est définitive.")148 }149 }150 .tint(Theme.accent)151 }152153 private func row(_ f: Favorite) -> some View {154 HStack(alignment: .top, spacing: 12) {155 FaviconView(path: f.faviconPath, name: f.siteName ?? f.domain, size: 30).padding(.top, 2)156 VStack(alignment: .leading, spacing: 3) {157 Text(verbatim: f.title).font(.display(.body, weight: .semibold)).foregroundStyle(Theme.ink).lineLimit(2)158 Text(verbatim: f.displayURL ?? f.domain).font(.data(.caption2)).foregroundStyle(Theme.muted).lineLimit(1).truncationMode(.tail)159 Text("Enregistré \(Format.relative(f.savedAt))").font(.caption).foregroundStyle(Theme.muted)160 }161 .frame(maxWidth: .infinity, alignment: .leading)162 }163 .padding(.vertical, 4)164 .contentShape(Rectangle())165 }166}167