Skip to content

Commit

Permalink
Refactor event data handling in ChatInput and ImageCaptureButton comp…
Browse files Browse the repository at this point in the history
…onents to destructure action and payload, improving code readability and maintainability
  • Loading branch information
Royal-lobster committed Nov 26, 2023
1 parent 2ffe621 commit 3219a68
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
5 changes: 3 additions & 2 deletions src/components/Sidebar/chat/ChatInput.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ export function SidebarInput({
if (isWebpageContextOn) {
const pageContent = new Promise((resolve) => {
window.addEventListener('message', function (event) {
if (event.data.action === 'get-page-content') {
resolve(event.data.pageContent)
const { action, payload } = event.data
if (action === 'get-page-content') {
resolve(payload)
}
})

Expand Down
5 changes: 3 additions & 2 deletions src/components/Sidebar/chat/ImageCaptureButton.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@ const ImageCaptureButton = ({
const image = await new Promise((resolve) => {
window.parent.postMessage({ action: 'get-screenshot-image' }, '*')
window.addEventListener('message', function (event) {
if (event.data.action === 'get-screenshot-image') {
resolve(event.data.image)
const { action, payload } = event.data
if (action === 'get-screenshot-image') {
resolve(payload)
}
})
})
Expand Down
4 changes: 2 additions & 2 deletions src/pages/content/sidebar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ window.addEventListener('message', async (event) => {
iframe.contentWindow?.postMessage(
{
action: 'get-page-content',
pageContent,
payload: pageContent,
},
'*',
)
Expand All @@ -64,7 +64,7 @@ window.addEventListener('message', async (event) => {
iframe.contentWindow?.postMessage(
{
action: 'get-screenshot-image',
image,
payload: image,
},
'*',
)
Expand Down

0 comments on commit 3219a68

Please sign in to comment.