Sources/OrgstarMobile/RoamGraphScreen.swift
33 lines · 1079 bytes
1 symbol in this file
1#if os(iOS)
2import OrgApp
3import OrgCore
4import OrgIndex
5import SwiftUI
6
7/// The workspace's nodes and links, as the Mac's Graph window draws them; a tap on a node
8/// opens it.
9struct RoamGraphScreen: View {
10 let workspace: WorkspaceModel
11 let session: DocumentSession
12 let path: String
13 let caret: Int
14 let open: (HeadingLocation) -> Void
15 @Environment(\.dismiss) private var dismiss
16
17 private var current: String? {
18 session.document(of: path).flatMap { RoamGraph.current(tree: $0.tree, at: caret, path: path, denote: OrgPreferences.usesDenote()) }
19 }
20
21 var body: some View {
22 NavigationStack {
23 RoamGraphView(load: { workspace.roamGraph(overlay: workspace.overlay(session.openDocuments)) }, current: current, version: 0) { location in
24 dismiss()
25 open(location)
26 }
27 .navigationTitle("Graph")
28 .navigationBarTitleDisplayMode(.inline)
29 .toolbar { ToolbarItem(placement: .cancellationAction) { Button("Done") { dismiss() } } }
30 }
31 }
32}
33#endif