Skip to content

Commit

Permalink
Use useHandleWindowMessage
Browse files Browse the repository at this point in the history
  • Loading branch information
vhande committed Nov 4, 2024
1 parent bf813eb commit 4cb48e9
Showing 1 changed file with 7 additions and 14 deletions.
21 changes: 7 additions & 14 deletions src/pages/search/index.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ import { useEffect, useState } from 'react';
import { TabContent } from 'react-bootstrap';
import { useTranslation } from 'react-i18next';

import {
useHandleWindowMessage,
WindowMessageTypes,
} from '@/hooks/useHandleWindowMessage';
import { useIsClient } from '@/hooks/useIsClient';
import { useLegacyPath } from '@/hooks/useLegacyPath';
import { Page } from '@/ui/Page';
Expand Down Expand Up @@ -36,20 +40,9 @@ const Search = () => {
{ shallow: true },
);

useEffect(() => {
const handleMessage = (event) => {
if (event.origin !== publicRuntimeConfig.legacyAppUrl) {
return;
}

if (event.data.height) {
setIframeHeight(event.data.height);
}
};
window.addEventListener('message', handleMessage);

return () => window.removeEventListener('message', handleMessage);
}, []);
useHandleWindowMessage({
[WindowMessageTypes.PAGE_HEIGHT]: (event) => setIframeHeight(event?.height),
});

return (
<Page>
Expand Down

0 comments on commit 4cb48e9

Please sign in to comment.