SPB Git

Repository Public

NoteScreenHost.swift 3.8 KB 81 lines swift

1// SP Notes iOS2// File: Features/Root/NoteScreenHost.swift3// Description: The note screen as the shell hosts it (stack, detail column, note window): passes the block to reveal, advertises4//              the note for Handoff (`NSUserActivity` with the web address of the page), and the window that shows one note.5//6// Author: Simon-Pierre Boucher7// Contact: contact@spboucher.ai8import SPNotesCore9import SwiftUI1011struct NoteScreenHost: View {12    let noteId: String13    var isNew = false14    @Environment(AppModel.self) private var app15    @Environment(ShellState.self) private var shell16    @State private var title = ""1718    var body: some View {19        NoteEditorScreen(noteId: noteId, isNew: isNew, reveal: shell.reveal(for: noteId))20            // Outgoing Handoff: the note being read continues on another device (or in a browser, by its web address).21            .userActivity(NoteActivity.type, element: noteId) { id, activity in22                NoteActivity.fill(activity, noteId: id, title: title, blockId: nil)23            }24            .task(id: app.feed.page(noteId) &+ app.feed.lists) {25                if let summary = try? await app.store.summary(id: noteId) { title = summary.title }26            }27            // the tab bar leaves the note alone (the formatting bar and the keyboard take its place)28            .toolbar(shell.isCompact ? .hidden : .automatic, for: .tabBar)29    }30}3132/// A window that shows one note (iPad): its own navigation stack (a mention pushes the other note), its own toolbar.33struct NoteWindowScreen: View {34    @Binding var target: NoteWindowTarget?35    @Environment(AppModel.self) private var app36    @Environment(ShellState.self) private var shell37    @Environment(\.dismissWindow) private var dismissWindow38    @Environment(\.accessibilityReduceMotion) private var reduceMotion39    @State private var prepared = false4041    var body: some View {42        @Bindable var shell = shell43        NavigationStack(path: $shell.path) {44            Group {45                if let target {46                    NoteScreenHost(noteId: target.noteId)47                        .toolbar {48                            ToolbarItem(placement: .topBarLeading) {49                                Button { dismissWindow() } label: { Label("Fermer la fenêtre", systemImage: "xmark") }50                                    .accessibilityIdentifier("note-window-close")51                            }52                        }53                } else {54                    EmptyStateView(symbol: "note.text", title: "Aucune note", message: "Cette fenêtre n’a plus de note à montrer.", actionTitle: "Fermer la fenêtre") { dismissWindow() }55                }56            }57            .navigationDestination(for: Destination.self) { destination in58                if case .note(let id, let isNew) = destination { NoteScreenHost(noteId: id, isNew: isNew) }59            }60        }61        .overlay(alignment: .bottom) { ToastView(bottomPadding: 14) }62        .nvAnimation(.base, value: shell.toast?.id)63        .dropDestination(for: NoteTransfer.self) { items, _ in64            // a note dropped on the window is shown in it65            guard let id = items.flatMap(\.ids).first(where: { $0 != target?.noteId }) else { return false }66            shell.open(note: id)67            return true68        }69        .onAppear {70            guard !prepared else { return }71            prepared = true72            // a stack of its own: the window behaves like a narrow shell whose root is the note73            shell.tab = .notes74            shell.paths = [.notes: []]75            shell.rootNote = target?.noteId76            if let target, let blockId = target.blockId { shell.open(note: target.noteId, blockId: blockId) }77        }78        .background(Color.clear.accessibilityElement().accessibilityIdentifier("note-window"))79    }80}81
Files main
Menu

Theme