Browse Source

fix redundant video

imwald
Silberengel 5 months ago
parent
commit
0f1bd83f90
  1. 21
      src/components/Note/VideoNote.tsx

21
src/components/Note/VideoNote.tsx

@ -7,10 +7,29 @@ import MediaPlayer from '../MediaPlayer' @@ -7,10 +7,29 @@ import MediaPlayer from '../MediaPlayer'
export default function VideoNote({ event, className }: { event: Event; className?: string }) {
const videoInfos = useMemo(() => getImetaInfosFromEvent(event), [event])
// Extract URLs from content to avoid duplicate rendering
const contentUrls = useMemo(() => {
const content = event.content || ''
const urlMatches = content.match(/https?:\/\/[^\s]+/g) || []
return urlMatches.map(url => {
try {
return new URL(url).href
} catch {
return url
}
})
}, [event.content])
return (
<div className={className}>
<Content event={event} />
{videoInfos.map((video) => (
{videoInfos
.filter((video) => {
// Only render videos from imeta tags that are not already in the content
const videoUrl = new URL(video.url).href
return !contentUrls.includes(videoUrl)
})
.map((video) => (
<MediaPlayer src={video.url} key={video.url} className="mt-2" />
))}
</div>

Loading…
Cancel
Save