diff --git a/CalenTask/Features/Settings/SettingsPage.swift b/CalenTask/Features/Settings/SettingsPage.swift index df20345..720483d 100644 --- a/CalenTask/Features/Settings/SettingsPage.swift +++ b/CalenTask/Features/Settings/SettingsPage.swift @@ -11,12 +11,12 @@ import Observation /// Nuovo modulo: `case` in `AppModule` (+ le sue `AppFeature`) e le sue /// opzioni in `ModuleOptions.swift`. Nient'altro da toccare qui. enum SettingsPage: Hashable, Identifiable { - case general, appearance, notifications, sync, developer, account + case general, appearance, notifications, sync, trash, developer, account case modules case module(AppModule) /// Le pagine generali nella barra laterale (l'account ha la sua testata). - static let generalPages: [SettingsPage] = [.general, .appearance, .notifications, .sync, .developer] + static let generalPages: [SettingsPage] = [.general, .appearance, .notifications, .sync, .trash, .developer] var id: String { switch self { @@ -24,6 +24,7 @@ enum SettingsPage: Hashable, Identifiable { case .appearance: "appearance" case .notifications: "notifications" case .sync: "sync" + case .trash: "trash" case .developer: "developer" case .account: "account" case .modules: "modules" @@ -37,6 +38,7 @@ enum SettingsPage: Hashable, Identifiable { case .appearance: "Aspetto" case .notifications: "Notifiche" case .sync: "Sincronizzazione" + case .trash: "Cestino" case .developer: "Sviluppatore" case .account: "Account e spazi" case .modules: "Panoramica moduli" @@ -50,6 +52,7 @@ enum SettingsPage: Hashable, Identifiable { case .appearance: "Tema e contenuto della barra laterale." case .notifications: "Permesso di sistema e riepilogo del mattino." case .sync: "iCloud tra i tuoi dispositivi e calendari di sistema." + case .trash: "Attività eliminate: ripristinale o svuota. Dopo 30 giorni spariscono da sole." case .developer: "Aggiornamenti da GitHub, pre-release e diagnostica." case .account: "Il tuo profilo e gli spazi di lavoro." case .modules: "Accendi solo ciò che ti serve: spegnere un modulo nasconde i suoi strumenti ma conserva dati e preferenze." @@ -63,6 +66,7 @@ enum SettingsPage: Hashable, Identifiable { case .appearance: "paintbrush" case .notifications: "bell.badge" case .sync: "arrow.triangle.2.circlepath.icloud" + case .trash: "trash" case .developer: "hammer" case .account: "person.crop.circle" case .modules: "square.grid.2x2" @@ -76,6 +80,7 @@ enum SettingsPage: Hashable, Identifiable { case .appearance: Color(hex: "#5B5BD6") case .notifications: Color(hex: "#E54666") case .sync: Color(hex: "#0091FF") + case .trash: Color(hex: "#8B8D98") case .developer: Color(hex: "#F76B15") case .account: Color(hex: "#30A46C") case .modules: Color(hex: "#8E4EC6") diff --git a/CalenTask/Features/Settings/SettingsView.swift b/CalenTask/Features/Settings/SettingsView.swift index 5756625..431b4b5 100644 --- a/CalenTask/Features/Settings/SettingsView.swift +++ b/CalenTask/Features/Settings/SettingsView.swift @@ -174,6 +174,7 @@ struct SettingsPageView: View { case .appearance: AppearanceSettingsView() case .notifications: NotificationsSettingsView() case .sync: SyncSettingsView() + case .trash: TrashSettingsView() case .developer: DeveloperSettingsView() case .account: AccountSettingsView() case .modules: ModulesOverviewView() diff --git a/CalenTask/Features/Settings/TrashSettingsView.swift b/CalenTask/Features/Settings/TrashSettingsView.swift new file mode 100644 index 0000000..7649989 --- /dev/null +++ b/CalenTask/Features/Settings/TrashSettingsView.swift @@ -0,0 +1,63 @@ +import Foundation +import SwiftData +import SwiftUI + +/// Impostazioni › Cestino (#22): le attività eliminate si possono ripristinare +/// (con le sotto-attività) o cancellare per sempre; dopo 30 giorni le elimina +/// `TrashService.purgeExpired`. +struct TrashSettingsView: View { + @Environment(\.modelContext) private var modelContext + @Query(filter: #Predicate { $0.deletedAt != nil }) + private var trashed: [TodoTask] + @State private var confirmEmpty = false + + /// Radici dei sottoalberi eliminati, le più recenti prima. + private var deleted: [TodoTask] { + trashed.filter { $0.parentTask?.deletedAt == nil } + .sorted { ($0.deletedAt ?? .distantPast) > ($1.deletedAt ?? .distantPast) } + } + + var body: some View { + Form { + Section { SettingsPageHeader(page: .trash) } + + if deleted.isEmpty { + Section { + Label("Il cestino è vuoto.", systemImage: "trash") + .foregroundStyle(.secondary) + } + } else { + Section { + ForEach(deleted) { task in + HStack { + VStack(alignment: .leading, spacing: 2) { + Text(task.title.isEmpty ? "Senza titolo" : task.title) + if let when = task.deletedAt { + Text("Eliminata \(when.formatted(.relative(presentation: .named)))") + .font(.caption) + .foregroundStyle(.secondary) + } + } + Spacer() + Button("Ripristina") { TrashService.restore(task) } + .buttonStyle(.borderless) + } + } + } + Section { + Button("Svuota cestino", role: .destructive) { confirmEmpty = true } + } + } + } + .formStyle(.grouped) + .navigationTitle("Cestino") + .confirmationDialog( + "Eliminare per sempre \(deleted.count) attività?", + isPresented: $confirmEmpty, titleVisibility: .visible + ) { + Button("Elimina per sempre", role: .destructive) { + TrashService.emptyTrash(in: modelContext) + } + } + } +}