Send theme update event to marketplace app on theme change detected (#2289)

This commit is contained in:
Lukasz Ostrowski 2022-09-13 09:15:48 +02:00 committed by GitHub
parent 7d3a0a776a
commit ff09d04660
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -33,12 +33,21 @@ export const AppFrame: React.FC<Props> = ({
}) => { }) => {
const shop = useShop(); const shop = useShop();
const frameRef = React.useRef<HTMLIFrameElement>(); const frameRef = React.useRef<HTMLIFrameElement>();
const { sendThemeToExtension } = useTheme(); const { themeType } = useTheme();
const classes = useStyles(); const classes = useStyles();
const appOrigin = getOrigin(src); const appOrigin = getOrigin(src);
const { postToExtension } = useAppActions(frameRef, appOrigin, appId); const { postToExtension } = useAppActions(frameRef, appOrigin, appId);
const location = useLocation(); const location = useLocation();
useEffect(() => {
postToExtension({
type: "theme",
payload: {
theme: themeType,
},
});
}, [themeType, postToExtension]);
useEffect(() => { useEffect(() => {
postToExtension({ postToExtension({
type: "redirect", type: "redirect",
@ -58,7 +67,12 @@ export const AppFrame: React.FC<Props> = ({
version: 1, version: 1,
}, },
}); });
sendThemeToExtension(); postToExtension({
type: "theme",
payload: {
theme: themeType,
},
});
if (onLoad) { if (onLoad) {
onLoad(); onLoad();