@@ -4,16 +4,14 @@ import {
44 handleDialogClose ,
55 compressBase64Image ,
66} from '../../utils/helpers' ;
7- import { serverFunctions } from '../../utils/serverFunctions' ;
7+
88import useAuth from '../../hooks/useAuth' ;
99import { CircularProgress , Container , Typography , Box } from '@mui/material' ;
1010import { showAlertDialog } from '../../utils/alert' ;
11- import LoadingOverlay from '../../components/loading-overlay' ;
1211
1312const CreateDiagramDialog = ( ) => {
1413 const { authState, authStatus } = useAuth ( ) ;
1514 const [ diagramsUrl , setDiagramsUrl ] = useState ( '' ) ;
16- const [ isInserting , setIsInserting ] = useState ( false ) ;
1715 const [ iframeLoading , setIframeLoading ] = useState ( true ) ;
1816
1917 useEffect ( ( ) => {
@@ -29,13 +27,6 @@ const CreateDiagramDialog = () => {
2927 const handleMessage = async ( e : MessageEvent ) => {
3028 const action = e . data . action ;
3129 if ( action === 'save' ) {
32- if ( isInserting ) {
33- console . log ( 'Already inserting diagram, ignoring duplicate click' ) ;
34- return ;
35- }
36-
37- setIsInserting ( true ) ;
38-
3930 const data = e . data . data ;
4031 const metadata = new URLSearchParams ( {
4132 projectID : data . projectID ,
@@ -47,15 +38,21 @@ const CreateDiagramDialog = () => {
4738 try {
4839 const compressedImage = await compressBase64Image ( data . diagramImage ) ;
4940
50- await serverFunctions . insertBase64ImageWithMetadata (
51- compressedImage ,
52- metadata . toString ( )
53- ) ;
41+ // Pass data to sidebar via BroadcastChannel and close immediately
42+ const channel = new BroadcastChannel ( 'diagram_channel' ) ;
43+ channel . postMessage ( {
44+ type : 'pendingInsertion' ,
45+ payload : {
46+ image : compressedImage ,
47+ metadata : metadata . toString ( ) ,
48+ operation : 'insert' ,
49+ } ,
50+ } ) ;
51+ channel . close ( ) ;
5452 handleDialogClose ( ) ;
5553 } catch ( error ) {
56- console . error ( 'Error inserting image with metadata' , error ) ;
57- showAlertDialog ( 'Error inserting image, please try again' ) ;
58- setIsInserting ( false ) ;
54+ console . error ( 'Error preparing diagram insertion' , error ) ;
55+ showAlertDialog ( 'Error preparing diagram, please try again' ) ;
5956 }
6057 }
6158 } ;
@@ -65,7 +62,7 @@ const CreateDiagramDialog = () => {
6562 return ( ) => {
6663 window . removeEventListener ( 'message' , handleMessage ) ;
6764 } ;
68- } , [ isInserting ] ) ;
65+ } , [ ] ) ;
6966
7067 const handleIframeLoad = ( ) => {
7168 setIframeLoading ( false ) ;
@@ -124,7 +121,6 @@ const CreateDiagramDialog = () => {
124121
125122 return (
126123 < >
127- { isInserting && < LoadingOverlay /> }
128124 { iframeLoading && (
129125 < Box
130126 sx = { {
@@ -151,8 +147,7 @@ const CreateDiagramDialog = () => {
151147 border : 'none' ,
152148 width : '100%' ,
153149 height : '96.5vh' ,
154- opacity : isInserting ? 0.5 : 1 ,
155- pointerEvents : isInserting ? 'none' : 'auto' ,
150+ opacity : 1 ,
156151 } }
157152 onLoad = { handleIframeLoad }
158153 />
0 commit comments