diff --git a/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx new file mode 100644 index 0000000000000..3e34575b31c96 --- /dev/null +++ b/frontend/src/lib/components/IframedToolbarBrowser/IframedToolbarBrowser.tsx @@ -0,0 +1,75 @@ +import { LemonBanner, Spinner } from '@posthog/lemon-ui' +import { useActions, useValues } from 'kea' +import { useEffect } from 'react' +import useResizeObserver from 'use-resize-observer' + +import { ToolbarUserIntent } from '~/types' + +import { appEditorUrl } from '../AuthorizedUrlList/authorizedUrlListLogic' +import { iframedToolbarBrowserLogic } from './iframedToolbarBrowserLogic' + +function IframeErrorOverlay(): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + const { iframeBanner } = useValues(logic) + return iframeBanner ? ( +
+ + {iframeBanner.message}. Your site might not allow being embedded in an iframe. You can click "Open in + toolbar" above to visit your site and view the heatmap there. + +
+ ) : null +} + +function LoadingOverlay(): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + const { loading } = useValues(logic) + return loading ? ( +
+ +
+ ) : null +} + +export function IframedToolbarBrowser({ + iframeRef, + userIntent, +}: { + iframeRef?: React.MutableRefObject + userIntent: ToolbarUserIntent +}): JSX.Element | null { + const logic = iframedToolbarBrowserLogic() + + const { browserUrl } = useValues(logic) + const { onIframeLoad, setIframeWidth } = useActions(logic) + + const { width: iframeWidth } = useResizeObserver({ ref: iframeRef }) + useEffect(() => { + setIframeWidth(iframeWidth ?? null) + }, [iframeWidth]) + + return browserUrl ? ( +
+ + +