Repository Public
1// Author: Simon-Pierre Boucher — contact@spboucher.ai2// File: Features/Offline/StorageView.swift3// Description: Storage dashboard: space on MacLustr, what is on this Mac (local copies, pinned, cache), counts, the largest files, and the two distinct actions — free local space (the files stay on SP Drive) versus delete from the Drive.4import SPDriveCore5import SPDriveNext6import SwiftUI78struct StorageView: View {9 @Environment(AppModel.self) private var model10 @Environment(Navigator.self) private var nav11 @State private var counts = MetadataStore.Counts(files: 0, folders: 0, bytes: 0, trashed: 0)12 @State private var local = MetadataStore.LocalUsage(files: 0, bytes: 0, pinnedBytes: 0)13 @State private var cache: Int64 = 014 @State private var largest: [DriveItem] = []15 @State private var confirmFree = false1617 var body: some View {18 ScrollView {19 VStack(alignment: .leading, spacing: 18) {20 if model.has(.storage), model.online { StorageCenter(model: model, nav: nav) }21 else if let q = model.quota, q.limit > 0 {22 card("Sur MacLustr", symbol: "server.rack") {23 QuotaBar(used: q.used, limit: q.limit)24 HStack { stat("Utilisé", Fmt.bytes(q.used)); stat("Disponible", Fmt.bytes(q.free)); stat("Total", Fmt.bytes(q.limit)) }25 Text("L’espace utilisé compte chaque contenu une fois, versions et corbeille comprises.").font(.caption).foregroundStyle(.secondary)26 }27 } else { card("Sur MacLustr", symbol: "server.rack") { Text("Espace indisponible hors ligne.").foregroundStyle(.secondary) } }28 card("Bibliothèque", symbol: "folder") {29 HStack { stat("Fichiers", "\(counts.files)"); stat("Dossiers", "\(counts.folders)"); stat("Taille", Fmt.bytes(counts.bytes)); stat("Corbeille", "\(counts.trashed)") }30 HStack { stat("Transferts en attente", "\(model.status.transfers.running + model.status.transfers.queued + model.status.transfers.paused)"); stat("Opérations en attente", "\(model.status.pendingOperations)"); stat("En attente dans le Finder", "\(model.pendingInFinder)") }31 }32 card("Sur ce Mac", symbol: "laptopcomputer") {33 HStack { stat("Copies locales", "\(local.files)"); stat("Taille locale", Fmt.bytes(local.bytes)); stat("Dont épinglées", Fmt.bytes(local.pinnedBytes)); stat("Cache", Fmt.bytes(cache)) }34 if !model.finderReady { Label("L’emplacement SP Drive du Finder n’est pas actif : aucune copie locale n’est gérée. Activez-le dans Paramètres › Général.", systemImage: "info.circle").font(.callout).foregroundStyle(.secondary) }35 HStack {36 Button("Libérer l’espace des copies non épinglées…") { confirmFree = true }.disabled(local.bytes - local.pinnedBytes <= 0)37 Button("Vider le cache d’aperçus") { model.clearCache(); refresh() }.disabled(cache == 0)38 Button("Gérer les éléments hors ligne") { nav.section = .offline }39 }40 Text("« Libérer l’espace » retire seulement la copie de ce Mac : les fichiers restent sur SP Drive et se retéléchargent à l’ouverture. Les éléments épinglés et les modifications pas encore envoyées ne sont jamais retirés.").font(.caption).foregroundStyle(.secondary)41 }42 if !(model.has(.storage) && model.online) { card("Fichiers les plus volumineux", symbol: "chart.bar") {43 if largest.isEmpty { Text("Aucun fichier.").foregroundStyle(.secondary) }44 ForEach(largest) { f in45 HStack {46 ItemThumbnail(model: model, item: f, side: 18)47 Text(f.name).lineLimit(1).truncationMode(.middle)48 ItemBadges(model: model, item: f)49 Spacer()50 Text(Fmt.bytes(f.size)).monospacedDigit().foregroundStyle(.secondary)51 Button("Afficher") { nav.open(folder: f.parentID == model.rootID ? nil : f.parentID); nav.selection = [f.id] }.controlSize(.small)52 }53 }54 } }55 }56 .padding(20).frame(maxWidth: 820, alignment: .leading)57 }58 .background(SPDTheme.surface)59 .navigationTitle("Stockage")60 .task(id: model.revision) { refresh(); await model.refreshAccount() }61 .confirmationDialog("Libérer l’espace local ?", isPresented: $confirmFree) {62 Button("Libérer \(Fmt.bytes(local.bytes - local.pinnedBytes))") {63 Task { let r = await model.freeUpAllUnpinned(); model.banner = Banner(text: "\(r.freed) copie(s) locale(s) retirée(s)\(r.kept > 0 ? ", \(r.kept) conservée(s)" : ""). Rien n’a été supprimé de SP Drive.", isError: false); refresh() }64 }65 Button("Annuler", role: .cancel) {}66 } message: { Text("Les copies locales non épinglées seront retirées de ce Mac. Les fichiers restent sur SP Drive.") }67 }68 private func refresh() {69 counts = (try? model.store?.counts()) ?? counts70 local = (try? model.store?.localUsage()) ?? local71 largest = (try? model.store?.largestFiles(limit: 12)) ?? []72 cache = model.cacheBytes()73 }74 private func card<C: View>(_ title: String, symbol: String, @ViewBuilder _ content: () -> C) -> some View {75 VStack(alignment: .leading, spacing: 10) { Label(title, systemImage: symbol).font(SPDTheme.Typo.headline); content() }76 .frame(maxWidth: .infinity, alignment: .leading).spdCard()77 }78 private func stat(_ label: String, _ value: String) -> some View {79 VStack(alignment: .leading, spacing: 1) { Text(value).font(SPDTheme.Typo.figure); Text(label).font(SPDTheme.Typo.caption).foregroundStyle(SPDTheme.textSecondary) }80 .frame(maxWidth: .infinity, alignment: .leading).accessibilityElement(children: .combine)81 }82}83