SPB Git

Repository Public

MoreScreen.swift 7.1 KB 150 lines swift

1// SP Notes iOS2// File: Features/Root/MoreScreen.swift3// Description: The two list screens of the iPhone tabs: « Notes » (the library: every list of notes, the sections, folders and4//              tags) and « Plus » (tasks, inbox, folders, tags, archive, trash, the hosted sections that are available, the5//              command palette, synchronisation and settings). Together with « Aujourd’hui » and « Recherche » they reach every6//              screen of 1.0.7//8// Author: Simon-Pierre Boucher9// Contact: contact@spboucher.ai10import SPNotesCore11import SPNotesDesign12import SwiftUI1314/// One row of « Notes » or « Plus »: where it goes. The lists are data so the reachability of every screen is tested.15struct ShellEntry: Identifiable, Equatable {16    enum Target: Equatable {17        case push(Destination)18        case sheet(String)19        case palette20    }21    var id: String22    var title: String23    var symbol: String24    var target: Target25    var isSecondary = false26}2728@MainActor29enum ShellEntries {30    /// « Notes »: the lists, then the sections.31    static var library: [[ShellEntry]] {32        [33            [34                ShellEntry(id: "entry-all", title: SmartList.all.title, symbol: SmartList.all.symbol, target: .push(.list(.smart(.all)))),35                ShellEntry(id: "entry-favorites", title: SmartList.favorites.title, symbol: SmartList.favorites.symbol, target: .push(.list(.smart(.favorites)))),36                ShellEntry(id: "entry-recent", title: SmartList.recent.title, symbol: SmartList.recent.symbol, target: .push(.list(.smart(.recent)))),37                ShellEntry(id: "entry-pinned", title: SmartList.pinned.title, symbol: SmartList.pinned.symbol, target: .push(.list(.smart(.pinned)))),38            ],39            NoteSection.editable.map { ShellEntry(id: "entry-section-\($0)", title: NoteSection.title($0), symbol: NoteSection.symbol($0), target: .push(.list(.section($0)))) },40            [41                ShellEntry(id: "entry-folders", title: String(localized: "Dossiers"), symbol: "folder", target: .push(.folders)),42                ShellEntry(id: "entry-tags", title: String(localized: "Tags"), symbol: "number", target: .push(.tags)),43            ],44        ]45    }4647    /// « Plus »: the fixed entries, the hosted sections that are available (none while their screens are not registered), the tools.48    static func more(sections: HostedSectionRegistry) -> [[ShellEntry]] {49        var groups: [[ShellEntry]] = [50            [51                ShellEntry(id: "more-tasks", title: String(localized: "Tâches"), symbol: "checklist", target: .push(.tasks)),52                ShellEntry(id: "more-inbox", title: SmartList.inbox.title, symbol: SmartList.inbox.symbol, target: .push(.inbox)),53            ],54            [55                ShellEntry(id: "more-folders", title: String(localized: "Dossiers"), symbol: "folder", target: .push(.folders)),56                ShellEntry(id: "more-tags", title: String(localized: "Étiquettes"), symbol: "number", target: .push(.tags)),57                ShellEntry(id: "more-archived", title: SmartList.archived.title, symbol: SmartList.archived.symbol, target: .push(.list(.smart(.archived))), isSecondary: true),58                ShellEntry(id: "more-trash", title: SmartList.trash.title, symbol: SmartList.trash.symbol, target: .push(.list(.smart(.trash))), isSecondary: true),59            ],60        ]61        let hosted = sections.available.map { ShellEntry(id: "more-hosted-\($0.id)", title: $0.title, symbol: $0.symbol, target: .push(.hosted($0.id))) }62        if !hosted.isEmpty { groups.append(hosted) }63        groups.append([64            ShellEntry(id: "more-palette", title: String(localized: "Palette de commandes"), symbol: "command", target: .palette),65            ShellEntry(id: "more-sync", title: String(localized: "Synchronisation"), symbol: "arrow.triangle.2.circlepath", target: .sheet("sync")),66            ShellEntry(id: "more-settings", title: String(localized: "Réglages"), symbol: "gearshape", target: .sheet("settings")),67        ])68        return groups69    }70}7172struct ShellEntryList: View {73    let groups: [[ShellEntry]]74    var counts: [String: Int] = [:]75    @Environment(ShellState.self) private var shell7677    var body: some View {78        ForEach(Array(groups.enumerated()), id: \.offset) { _, group in79            Section {80                ForEach(group) { entry in row(entry) }81            }82        }83    }8485    @ViewBuilder private func row(_ entry: ShellEntry) -> some View {86        let label = FolderRow(title: entry.title, symbol: entry.symbol, count: counts[entry.id], tint: entry.isSecondary ? .spTextSecondary : .accentColor)87        switch entry.target {88        case .push(let destination):89            NavigationLink(value: destination) { label }.accessibilityIdentifier(entry.id)90        case .sheet(let name):91            Button { shell.sheet = name == "sync" ? .syncDetails : .settings } label: { label }92                .buttonStyle(.plain)93                .accessibilityIdentifier(entry.id)94        case .palette:95            Button { shell.isPaletteOpen = true } label: { label }96                .buttonStyle(.plain)97                .accessibilityIdentifier(entry.id)98        }99    }100}101102/// « Notes »: the library.103struct NotesLibraryScreen: View {104    @Environment(AppModel.self) private var app105    @Environment(ShellState.self) private var shell106    @State private var counts: ListCounts?107108    var body: some View {109        List {110            ShellEntryList(groups: ShellEntries.library, counts: ["entry-all": counts?.all ?? 0, "entry-favorites": counts?.favorites ?? 0, "entry-pinned": counts?.pinned ?? 0])111        }112        .listStyle(.insetGrouped)113        .scrollContentBackground(.hidden)114        .background(Color.spBackground)115        .navigationTitle("Notes")116        .toolbar {117            ToolbarItem(placement: .topBarTrailing) { SyncIndicator() }118            ToolbarItem(placement: .primaryAction) { NewNoteButton(source: nil) }119        }120        .refreshable { await app.syncAndWait() }121        .task(id: app.feed.structure) { if let fresh = try? await app.store.counts() { counts = fresh } }122        .accessibilityIdentifier("library-screen")123    }124}125126/// « Plus ».127struct MoreScreen: View {128    @Environment(AppModel.self) private var app129    @Environment(ShellState.self) private var shell130    @State private var counts: ListCounts?131    @State private var openTasks = 0132133    var body: some View {134        List {135            ShellEntryList(groups: ShellEntries.more(sections: shell.sections),136                           counts: ["more-inbox": counts?.inbox ?? 0, "more-tasks": openTasks, "more-archived": counts?.archived ?? 0, "more-trash": counts?.trash ?? 0])137            if app.session == .expired { Section { SessionExpiredBanner() } }138        }139        .listStyle(.insetGrouped)140        .scrollContentBackground(.hidden)141        .background(Color.spBackground)142        .navigationTitle("Plus")143        .task(id: app.feed.structure &+ app.feed.entities("task")) {144            if let fresh = try? await app.store.counts() { counts = fresh }145            openTasks = ((try? await app.repositories.tasks.list(.open)) ?? []).count146        }147        .accessibilityIdentifier("more-screen")148    }149}150
Files main
Menu

Theme