import { useCallback } from "react"; import { useSelector } from "react-redux"; import { TwitterTweetEmbed } from "react-twitter-embed"; import { FileExtensionRegex, YoutubeUrlRegex, TweetUrlRegex, TidalRegex, SoundCloudRegex, MixCloudRegex, SpotifyRegex, TwitchRegex, AppleMusicRegex, } from "Const"; import { RootState } from "State/Store"; import SoundCloudEmbed from "Element/SoundCloudEmded"; import MixCloudEmbed from "Element/MixCloudEmbed"; import SpotifyEmbed from "Element/SpotifyEmbed"; import TidalEmbed from "Element/TidalEmbed"; import { ProxyImg } from "Element/ProxyImg"; import { HexKey } from "Nostr"; import TwitchEmbed from "./TwitchEmbed"; import AppleMusicEmbed from "./AppleMusicEmbed"; export default function HyperText({ link, creator }: { link: string; creator: HexKey }) { const pref = useSelector((s: RootState) => s.login.preferences); const follows = useSelector((s: RootState) => s.login.follows); const publicKey = useSelector((s: RootState) => s.login.publicKey); const render = useCallback(() => { const a = link; try { const hideNonFollows = pref.autoLoadMedia === "follows-only" && !follows.includes(creator); const isMine = creator === publicKey; if (pref.autoLoadMedia === "none" || (!isMine && hideNonFollows)) { return ( e.stopPropagation()} target="_blank" rel="noreferrer" className="ext"> {a} ); } const url = new URL(a); const youtubeId = YoutubeUrlRegex.test(a) && RegExp.$1; const tweetId = TweetUrlRegex.test(a) && RegExp.$2; const tidalId = TidalRegex.test(a) && RegExp.$1; const soundcloundId = SoundCloudRegex.test(a) && RegExp.$1; const mixcloudId = MixCloudRegex.test(a) && RegExp.$1; const isSpotifyLink = SpotifyRegex.test(a); const isTwitchLink = TwitchRegex.test(a); const isAppleMusicLink = AppleMusicRegex.test(a); const extension = FileExtensionRegex.test(url.pathname.toLowerCase()) && RegExp.$1; if (extension && !isAppleMusicLink) { switch (extension) { case "gif": case "jpg": case "jpeg": case "png": case "bmp": case "webp": { return ; } case "wav": case "mp3": case "ogg": { return