import { memo, useEffect, useRef, useState } from 'react' import classNames from 'classnames' import useDarkMode from './dark-mode' import styles from './text.module.css' import { Button } from 'react-bootstrap' import { TwitterTweetEmbed } from 'react-twitter-embed' import YouTube from 'react-youtube' function TweetSkeleton ({ className }) { return (
) } export const NostrEmbed = memo(function NostrEmbed ({ src, className, topLevel, darkMode, id }) { const [show, setShow] = useState(false) const iframeRef = useRef(null) useEffect(() => { if (!iframeRef.current) return const setHeightFromIframe = (e) => { if (e.origin !== 'https://njump.me' || !e?.data?.height || e.source !== iframeRef.current.contentWindow) return iframeRef.current.height = `${e.data.height}px` } window?.addEventListener('message', setHeightFromIframe) const handleIframeLoad = () => { iframeRef.current.contentWindow.postMessage({ setDarkMode: darkMode }, '*') } if (iframeRef.current.complete) { handleIframeLoad() } else { iframeRef.current.addEventListener('load', handleIframeLoad) } // https://github.com/vercel/next.js/issues/39451 iframeRef.current.src = `https://njump.me/${id}?embed=yes` return () => { window?.removeEventListener('message', setHeightFromIframe) iframeRef.current?.removeEventListener('load', handleIframeLoad) } }, [iframeRef.current, darkMode]) return (