SPB Git

Repository Public

RecentScreen.swift 3.1 KB 69 lines swift

1// SP Drive iOS2// File: Features/Recent/RecentScreen.swift3// Description: Recently modified files, and the favourites list: flat lists of items with the same actions as the explorer.4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7import SwiftUI89/// A flat list of items (no folder context): recents, favourites, search results.10struct ItemList: View {11    @Environment(AppModel.self) private var model12    let items: [DriveItem]13    let actions: ItemActions14    var showLocation = true1516    var body: some View {17        ForEach(items) { item in18            Group {19                if item.isFolder {20                    NavigationLink(value: FolderRoute(id: item.id)) { ItemRowView(item: item, showLocation: showLocation, onMore: { actions.sheet = .actions(item) }) }21                } else {22                    Button { actions.open(item, model: model) } label: { ItemRowView(item: item, showLocation: showLocation, onMore: { actions.sheet = .actions(item) }) }.buttonStyle(.plain)23                }24            }25            .contextMenu { ItemMenu(item: item, actions: actions) }26            .swipeActions(edge: .trailing, allowsFullSwipe: false) {27                Button(role: .destructive) { actions.confirmingTrash = [item] } label: { Label("Supprimer", systemImage: "trash") }28            }29            .swipeActions(edge: .leading) {30                Button { actions.toggleStar([item], model: model) } label: { Label(item.starred ? "Retirer" : "Favori", systemImage: item.starred ? "star.slash" : "star.fill") }.tint(.yellow)31            }32        }33    }34}3536struct RecentScreen: View {37    @Environment(AppModel.self) private var model38    @State private var actions = ItemActions()3940    var body: some View {41        let _ = model.itemsVersion42        let items = model.store.recent(limit: 100)43        Group {44            if items.isEmpty { EmptyState(symbol: "clock", title: String(localized: "Rien de récent"), message: String(localized: "Les fichiers ajoutés ou modifiés dernièrement apparaîtront ici."), action: (String(localized: "Ajouter un fichier"), { model.pendingRoute = .upload })) }45            else { List { ItemList(items: items, actions: actions) }.listStyle(.plain) }46        }47        .navigationTitle("Récents")48        .refreshable { await model.refresh() }49        .itemActions(actions)50    }51}5253struct FavoritesScreen: View {54    @Environment(AppModel.self) private var model55    @State private var actions = ItemActions()5657    var body: some View {58        let _ = model.itemsVersion59        let items = model.store.starred()60        Group {61            if items.isEmpty { EmptyState(symbol: "star", title: String(localized: "Aucun favori"), message: String(localized: "Balaye un élément vers la droite, ou utilise son menu, pour l’ajouter aux favoris."), action: (String(localized: "Parcourir Mon Drive"), { if let root = model.rootID { model.pendingRoute = .folder(root) } })) }62            else { List { ItemList(items: items, actions: actions) }.listStyle(.plain) }63        }64        .navigationTitle("Favoris")65        .refreshable { await model.refresh() }66        .itemActions(actions)67    }68}69
Files main
Menu

Theme