Skip to content

Commit 395e623

Browse files
committed
Await for chrome runtime response added in append note
1 parent d371077 commit 395e623

File tree

2 files changed

+30
-28
lines changed

2 files changed

+30
-28
lines changed

apps/extension/src/Hooks/useSaveChanges.ts

+30-27
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
useAuthStore,
1414
useContentStore,
1515
useDataStore,
16+
useFloatingStore,
1617
useHighlightStore,
1718
useRecentsStore
1819
} from '@mexit/core'
@@ -48,6 +49,7 @@ export function useSaveChanges() {
4849
const setActiveItem = useSputlitStore((s) => s.setActiveItem)
4950
const ilinks = useDataStore((s) => s.ilinks)
5051
const sharedNodes = useDataStore((s) => s.sharedNodes)
52+
const setFloatingElement = useFloatingStore((store) => store.setFloatingElement)
5153

5254
const setContent = useContentStore((s) => s.setContent)
5355
const appendContent = useContentStore((s) => s.appendContent)
@@ -262,35 +264,36 @@ export function useSaveChanges() {
262264
setActiveItem()
263265
// mog('Request and things', { request, node, nodeContent, content })
264266
// 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)
267268

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')
292288
}
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+
}
294297
}
295298

296299
return {

libs/shared/src/Components/AIPreview/index.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,6 @@ const AIPreviewContainer: React.FC<AIPreviewProps> = (props) => {
9292
} else {
9393
const deserializedContent = getContent(content)
9494
props.onInsert?.(deserializedContent, id)
95-
setFloatingElement(undefined)
9695
}
9796
}
9897

0 commit comments

Comments
 (0)