@@ -6,7 +6,7 @@ import invariant from "tiny-invariant";
66
77import { IconButton } from "catcolab-ui-components" ;
88import { createAnalysis } from "../analysis" ;
9- import { type DocRef , type LiveDoc , useApi } from "../api" ;
9+ import { type DocRef , DocumentType , type LiveDoc , useApi } from "../api" ;
1010import { DocumentTypeIcon } from "../components/document_type_icon" ;
1111import { createDiagram } from "../diagram" ;
1212import {
@@ -24,14 +24,22 @@ import { TheoryLibraryContext } from "../theory";
2424export function DocumentMenu ( props : {
2525 liveDoc : LiveDoc ;
2626 docRef : DocRef ;
27- onDocCreated ?: ( ) => void ;
27+ onDocCreated ?: ( docType : DocumentType , refId : string ) => void ;
2828 onDocDeleted ?: ( ) => void ;
2929} ) {
3030 const api = useApi ( ) ;
3131
3232 const navigate = useNavigate ( ) ;
3333 const docType = ( ) => props . liveDoc . doc . type ;
3434
35+ const handleDocCreated = ( docType : DocumentType , refId : string ) => {
36+ if ( props . onDocCreated ) {
37+ props . onDocCreated ( docType , refId ) ;
38+ } else {
39+ navigate ( `/${ docType } /${ refId } ` ) ;
40+ }
41+ } ;
42+
3543 const onNewDiagram = async ( ) => {
3644 let modelRefId : string | undefined ;
3745 switch ( props . liveDoc . doc . type ) {
@@ -47,8 +55,7 @@ export function DocumentMenu(props: {
4755 }
4856
4957 const newRef = await createDiagram ( api , api . makeUnversionedRef ( modelRefId ) ) ;
50- props . onDocCreated ?.( ) ;
51- navigate ( `/diagram/${ newRef } ` ) ;
58+ handleDocCreated ( "diagram" , newRef ) ;
5259 } ;
5360
5461 const onNewAnalysis = async ( ) => {
@@ -57,8 +64,7 @@ export function DocumentMenu(props: {
5764 invariant ( docType !== "analysis" , "Analysis cannot be created on other analysis" ) ;
5865
5966 const newRef = await createAnalysis ( api , docType , api . makeUnversionedRef ( docRefId ) ) ;
60- props . onDocCreated ?.( ) ;
61- navigate ( `/analysis/${ newRef } ` ) ;
67+ handleDocCreated ( "analysis" , newRef ) ;
6268 } ;
6369
6470 const theories = useContext ( TheoryLibraryContext ) ;
0 commit comments