From 15b038cd789e6ea79ad00047f5c4415b416016a3 Mon Sep 17 00:00:00 2001 From: Keyan <34140557+huumn@users.noreply.github.com> Date: Sat, 7 Sep 2024 12:07:10 -0500 Subject: [PATCH] refactor embeds to be reused (#1368) * refactor embeds to be reused * adjust the meaning of settings for embeds * add wavlake embed (close #1359) * add spotify embed (closes #1360) * fix 'format' appearing in srcSet * add nostr embed * refine nostr embed * Update components/media-or-link.js Co-authored-by: ekzyis * Update pages/settings/index.js Co-authored-by: ekzyis * ek suggestions --------- Co-authored-by: ekzyis --- components/item-full.js | 97 ++-------------- components/item.js | 53 +++++++-- components/media-or-link.js | 226 +++++++++++++++++++++++++++++++++--- components/text.js | 58 +-------- components/text.module.css | 132 +++++++++++++++++++-- lib/item.js | 2 +- lib/url.js | 53 ++++++++- middleware.js | 2 +- pages/settings/index.js | 25 +++- styles/item.module.css | 92 --------------- svgs/video-on-fill.svg | 1 + 11 files changed, 455 insertions(+), 286 deletions(-) create mode 100644 svgs/video-on-fill.svg diff --git a/components/item-full.js b/components/item-full.js index 39640608..8a5d294c 100644 --- a/components/item-full.js +++ b/components/item-full.js @@ -9,10 +9,7 @@ import styles from '@/styles/item.module.css' import itemStyles from './item.module.css' import { useMe } from './me' import Button from 'react-bootstrap/Button' -import { TwitterTweetEmbed } from 'react-twitter-embed' -import YouTube from 'react-youtube' -import useDarkMode from './dark-mode' -import { useEffect, useState } from 'react' +import { useEffect } from 'react' import Poll from './poll' import { commentsViewed } from '@/lib/new-comments' import Related from './related' @@ -22,7 +19,7 @@ import Share from './share' import Toc from './table-of-contents' import Link from 'next/link' import { RootProvider } from './root' -import { IMGPROXY_URL_REGEXP, parseEmbedUrl } from '@/lib/url' +import { decodeProxyUrl, IMGPROXY_URL_REGEXP } from '@/lib/url' import { numWithUnits } from '@/lib/format' import { useQuoteReply } from './use-quote-reply' import { UNKNOWN_LINK_REL } from '@/lib/constants' @@ -50,91 +47,11 @@ function BioItem ({ item, handleClick }) { ) } -function TweetSkeleton () { - return ( -
-
-
-
-
-
-
-
-
-
- ) -} +function ItemEmbed ({ url, imgproxyUrls }) { + const src = IMGPROXY_URL_REGEXP.test(url) ? decodeProxyUrl(url) : url + const srcSet = imgproxyUrls?.[url] -function ItemEmbed ({ item }) { - const [darkMode] = useDarkMode() - const [overflowing, setOverflowing] = useState(false) - const [show, setShow] = useState(false) - - // This Twitter embed could use similar logic to the video embeds below - const twitter = item.url?.match(/^https?:\/\/(?:twitter|x)\.com\/(?:#!\/)?\w+\/status(?:es)?\/(?\d+)/) - if (twitter?.groups?.id) { - return ( -
- } onLoad={() => setOverflowing(true)} /> - {overflowing && !show && - } -
- ) - } - - const { provider, id, meta } = parseEmbedUrl(item.url) - - if (provider === 'youtube') { - return ( -
- -
- ) - } - - if (provider === 'rumble') { - return ( -
-
-