Skip to content

Commit

Permalink
Send post message to active preview openend in new tab (#2408)
Browse files Browse the repository at this point in the history
  • Loading branch information
agalin920 authored Dec 27, 2023
1 parent 96642e2 commit c4e1385
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions src/apps/active-preview/Preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,28 @@ export function Preview(props) {
setAnchorEl(null);
};

const handleOpenInNewTab = () => {
const newTab = window.open(
`${CONFIG.URL_MANAGER_PROTOCOL}${instance.ZUID}${CONFIG.URL_MANAGER}/active-preview`,
"_blank"
);

if (newTab) {
newTab.addEventListener("load", () => {
newTab.postMessage(
{
source: "zesty",
route,
settings,
version,
dirty,
},
window.location.origin
);
});
}
};

if (!domain) {
return (
<Box
Expand Down Expand Up @@ -341,12 +363,7 @@ export function Preview(props) {
mr: 0.5,
}}
size="small"
onClick={() =>
window.open(
`${CONFIG.URL_MANAGER_PROTOCOL}${instance.ZUID}${CONFIG.URL_MANAGER}/active-preview`,
"_blank"
)
}
onClick={handleOpenInNewTab}
>
<OpenInNewRounded />
</IconButton>
Expand Down

0 comments on commit c4e1385

Please sign in to comment.