@@ -13,6 +13,7 @@ import {
13
13
useAuthStore ,
14
14
useContentStore ,
15
15
useDataStore ,
16
+ useFloatingStore ,
16
17
useHighlightStore ,
17
18
useRecentsStore
18
19
} from '@mexit/core'
@@ -48,6 +49,7 @@ export function useSaveChanges() {
48
49
const setActiveItem = useSputlitStore ( ( s ) => s . setActiveItem )
49
50
const ilinks = useDataStore ( ( s ) => s . ilinks )
50
51
const sharedNodes = useDataStore ( ( s ) => s . sharedNodes )
52
+ const setFloatingElement = useFloatingStore ( ( store ) => store . setFloatingElement )
51
53
52
54
const setContent = useContentStore ( ( s ) => s . setContent )
53
55
const appendContent = useContentStore ( ( s ) => s . appendContent )
@@ -262,35 +264,36 @@ export function useSaveChanges() {
262
264
setActiveItem ( )
263
265
// mog('Request and things', { request, node, nodeContent, content })
264
266
// TODO: Merge this with the savit request call. DRY
265
- chrome . runtime . sendMessage ( request , ( response ) => {
266
- const { message, error } = response
267
+ const response = await chrome . runtime . sendMessage ( request )
267
268
268
- if ( error && notification ) {
269
- toast . error ( 'An Error Occured. Please try again.' )
270
- } else {
271
- // mog('Response and things', { response })
272
- const bulkCreateRequest = request . subType === 'BULK_CREATE_NODES'
273
- const nodeid = ! bulkCreateRequest ? message . id : message . node . id
274
- const content = message . content ?? request . body . content
275
- appendContent ( node . nodeid , content )
276
- const title = ! bulkCreateRequest ? message . title : message . node . title
277
- updateBlocks ( {
278
- id : node . nodeid ,
279
- contents : content ,
280
- title
281
- } )
282
-
283
- if ( notification ) {
284
- toast . success ( 'Saved to Cloud' )
285
- }
286
-
287
- if ( saveAndExit ) {
288
- setVisualState ( VisualState . animatingOut )
289
- // So that sputlit opens with preview true when it opens the next time
290
- setPreviewMode ( true )
291
- }
269
+ const { message, error } = response
270
+
271
+ if ( error && notification ) {
272
+ toast . error ( 'An Error Occured. Please try again.' )
273
+ } else {
274
+ // mog('Response and things', { response })
275
+ const bulkCreateRequest = request . subType === 'BULK_CREATE_NODES'
276
+ const nodeid = ! bulkCreateRequest ? message . id : message . node . id
277
+ const content = message . content ?? request . body . content
278
+ appendContent ( node . nodeid , content )
279
+ const title = ! bulkCreateRequest ? message . title : message . node . title
280
+ updateBlocks ( {
281
+ id : node . nodeid ,
282
+ contents : content ,
283
+ title
284
+ } )
285
+
286
+ if ( notification ) {
287
+ toast . success ( 'Saved to Cloud' )
292
288
}
293
- } )
289
+
290
+ if ( saveAndExit ) {
291
+ setVisualState ( VisualState . animatingOut )
292
+ // So that sputlit opens with preview true when it opens the next time
293
+ setPreviewMode ( true )
294
+ setFloatingElement ( undefined )
295
+ }
296
+ }
294
297
}
295
298
296
299
return {
0 commit comments