diff --git a/components/carousel.js b/components/carousel.js index 666c895b..1b5ed6dd 100644 --- a/components/carousel.js +++ b/components/carousel.js @@ -120,7 +120,11 @@ export function CarouselProvider ({ children }) { media.current.set(src, { src, originalSrc, rel }) }, [media.current]) - const value = useMemo(() => ({ showCarousel, addMedia }), [showCarousel, addMedia]) + const removeMedia = useCallback((src) => { + media.current.delete(src) + }, [media.current]) + + const value = useMemo(() => ({ showCarousel, addMedia, removeMedia }), [showCarousel, addMedia, removeMedia]) return {children} } diff --git a/components/embed.js b/components/embed.js new file mode 100644 index 00000000..fa24a660 --- /dev/null +++ b/components/embed.js @@ -0,0 +1,204 @@ +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, 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) + + // https://github.com/vercel/next.js/issues/39451 + iframeRef.current.src = `https://njump.me/${id}?embed=yes` + + return () => { + window?.removeEventListener('message', setHeightFromIframe) + } + }, [iframeRef.current]) + + return ( +
+