1- import { Editor } from "obsidian" ;
1+ import { Editor , MarkdownView , Notice } from "obsidian" ;
22import type DiscourseGraphPlugin from "~/index" ;
33import { NodeTypeModal } from "~/components/NodeTypeModal" ;
44import ModifyNodeModal from "~/components/ModifyNodeModal" ;
@@ -7,7 +7,7 @@ import { createDiscourseNode } from "./createNode";
77import { VIEW_TYPE_MARKDOWN , VIEW_TYPE_TLDRAW_DG_PREVIEW } from "~/constants" ;
88import { createCanvas } from "~/components/canvas/utils/tldraw" ;
99import { createOrUpdateDiscourseEmbedding } from "./syncDgNodesToSupabase" ;
10- import { Notice } from "obsidian " ;
10+ import { publishNode } from "./publishNode " ;
1111
1212export const registerCommands = ( plugin : DiscourseGraphPlugin ) => {
1313 plugin . addCommand ( {
@@ -156,4 +156,43 @@ export const registerCommands = (plugin: DiscourseGraphPlugin) => {
156156 return true ;
157157 } ,
158158 } ) ;
159+ plugin . addCommand ( {
160+ id : "publish-discourse-node" ,
161+ name : "Publish current node to lab space" ,
162+ checkCallback : ( checking : boolean ) => {
163+ if ( ! plugin . settings . syncModeEnabled ) {
164+ new Notice ( "Sync mode is not enabled" , 3000 ) ;
165+ return false ;
166+ }
167+ const activeView = plugin . app . workspace . getActiveViewOfType ( MarkdownView ) ;
168+ if ( ! activeView || ! activeView . file ) {
169+ return false ;
170+ }
171+ const file = activeView . file ;
172+ const cache = plugin . app . metadataCache . getFileCache ( file ) ;
173+ const frontmatter = cache ?. frontmatter || { } ;
174+ if ( ! frontmatter . nodeTypeId ) {
175+ return false ;
176+ }
177+ if ( ! checking ) {
178+ if ( ! frontmatter . nodeInstanceId ) {
179+ new Notice ( "Please sync the node first" ) ;
180+ return true ;
181+ }
182+ // TODO (in follow-up PRs):
183+ // Maybe sync the node now if unsynced
184+ // Ensure that the node schema is synced to the database, and shared
185+ // sync the assets to the database
186+ publishNode ( { plugin, file, frontmatter } )
187+ . then ( ( ) => {
188+ new Notice ( "Published" ) ;
189+ } )
190+ . catch ( ( error : Error ) => {
191+ new Notice ( error . message ) ;
192+ console . error ( error ) ;
193+ } ) ;
194+ }
195+ return true ;
196+ } ,
197+ } ) ;
159198} ;
0 commit comments