SPB Git

Repository Public

NoteFeatureSheet.swift 3.3 KB 74 lines swift

1// SP Notes iOS2// File: Features/Sections/NoteFeatureSheet.swift3// Description: The screens of SPNotesFeatures that are about ONE note, opened from the note's menu: Ask scoped to the page4//              (with the model picker of the shared screen), the semantic zoom (synopsis — AI, on request — / outline / full5//              text) and the page timeline with its time machine. Offered only when the server is known to have the feature.6//7// Author: Simon-Pierre Boucher8// Contact: contact@spboucher.ai9import SPNotesCore10import SPNotesDesign11import SPNotesFeatures12import SwiftUI1314struct NoteFeatureSheet: View {15    enum Kind: Equatable { case ask, outline, timeline }1617    /// Whether the server (as last read; nil = never asked) offers what the sheet needs. Pure, tested.18    static func offers(_ kind: Kind, _ features: ServerMeta?) -> Bool {19        guard let features else { return false }20        switch kind {21        case .ask: return features.has(ServerFeature.nodesV3)22        case .outline: return features.has(ServerFeature.zoom)23        case .timeline: return features.has(ServerFeature.events)24        }25    }2627    let kind: Kind28    let noteId: String29    let title: String30    let document: NoteDocument31    @Environment(AppModel.self) private var app32    @Environment(\.dismiss) private var dismiss33    @State private var router: SheetRouter?3435    var body: some View {36        NavigationStack {37            Group {38                if let router {39                    switch kind {40                    case .ask:41                        AskScreen(repositories: app.repositories, router: router, context: AskContext(pageId: noteId, pageTitle: AppModel.displayTitle(title)))42                    case .outline:43                        PageOutlineView(model: SemanticZoomModel(repositories: app.repositories, router: router, pageId: noteId)) {44                            NativeDocumentView(document: document, identifier: "outline-full")45                        }46                    case .timeline:47                        TimelineScreen(repositories: app.repositories, router: router, scope: .page(noteId))48                    }49                } else {50                    ProgressView()51                }52            }53            .background(NVColor.bg)54            .navigationBarTitleDisplayMode(.inline)55            .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Fermer") { dismiss() }.accessibilityIdentifier("note-feature-close") } }56        }57        .onAppear { if router == nil { router = SheetRouter(app: app, dismiss: { dismiss() }) } }58        .accessibilityIdentifier("note-feature-sheet")59    }6061    /// Navigation asked by a screen shown in a sheet: the sheet closes, the app's routes do the rest.62    @MainActor63    final class SheetRouter: FeatureRouter {64        let app: AppModel65        let dismiss: () -> Void66        init(app: AppModel, dismiss: @escaping () -> Void) { self.app = app; self.dismiss = dismiss }67        func openPage(id: String, blockId: String?) { dismiss(); app.pendingRoute = .note(id, blockId: blockId) }68        func openDatabase(id: String) { dismiss(); app.pendingRoute = .note(id) }69        func openCanvas(pageId: String) { dismiss(); app.pendingRoute = .note(pageId) }70        func openURL(_ url: URL) { UIApplication.shared.open(url) }71        func presentError(_ error: Error) { app.banner = error.localizedDescription }72    }73}74
Files main
Menu

Theme