|
|
|
@ -16,7 +16,7 @@ import { cleanUrl } from '@/lib/url' |
|
|
|
import mediaUpload from '@/services/media-upload.service' |
|
|
|
import mediaUpload from '@/services/media-upload.service' |
|
|
|
import { TImetaInfo } from '@/types' |
|
|
|
import { TImetaInfo } from '@/types' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { Event } from 'nostr-tools' |
|
|
|
import { memo } from 'react' |
|
|
|
import { useMemo } from 'react' |
|
|
|
import { |
|
|
|
import { |
|
|
|
EmbeddedHashtag, |
|
|
|
EmbeddedHashtag, |
|
|
|
EmbeddedLNInvoice, |
|
|
|
EmbeddedLNInvoice, |
|
|
|
@ -31,8 +31,7 @@ import MediaPlayer from '../MediaPlayer' |
|
|
|
import WebPreview from '../WebPreview' |
|
|
|
import WebPreview from '../WebPreview' |
|
|
|
import YoutubeEmbeddedPlayer from '../YoutubeEmbeddedPlayer' |
|
|
|
import YoutubeEmbeddedPlayer from '../YoutubeEmbeddedPlayer' |
|
|
|
|
|
|
|
|
|
|
|
const Content = memo( |
|
|
|
export default function Content({ |
|
|
|
({ |
|
|
|
|
|
|
|
event, |
|
|
|
event, |
|
|
|
content, |
|
|
|
content, |
|
|
|
className, |
|
|
|
className, |
|
|
|
@ -42,10 +41,11 @@ const Content = memo( |
|
|
|
content?: string |
|
|
|
content?: string |
|
|
|
className?: string |
|
|
|
className?: string |
|
|
|
mustLoadMedia?: boolean |
|
|
|
mustLoadMedia?: boolean |
|
|
|
}) => { |
|
|
|
}) { |
|
|
|
const translatedEvent = useTranslatedEvent(event?.id) |
|
|
|
const translatedEvent = useTranslatedEvent(event?.id) |
|
|
|
|
|
|
|
const { nodes, allImages, lastNormalUrl, emojiInfos } = useMemo(() => { |
|
|
|
const _content = translatedEvent?.content ?? event?.content ?? content |
|
|
|
const _content = translatedEvent?.content ?? event?.content ?? content |
|
|
|
if (!_content) return null |
|
|
|
if (!_content) return {} |
|
|
|
|
|
|
|
|
|
|
|
const nodes = parseContent(_content, [ |
|
|
|
const nodes = parseContent(_content, [ |
|
|
|
EmbeddedUrlParser, |
|
|
|
EmbeddedUrlParser, |
|
|
|
@ -104,7 +104,6 @@ const Content = memo( |
|
|
|
}) |
|
|
|
}) |
|
|
|
.filter(Boolean) |
|
|
|
.filter(Boolean) |
|
|
|
.flat() as TImetaInfo[] |
|
|
|
.flat() as TImetaInfo[] |
|
|
|
let imageIndex = 0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const emojiInfos = getEmojiInfosFromEmojiTags(event?.tags) |
|
|
|
const emojiInfos = getEmojiInfosFromEmojiTags(event?.tags) |
|
|
|
|
|
|
|
|
|
|
|
@ -112,6 +111,14 @@ const Content = memo( |
|
|
|
const lastNormalUrl = |
|
|
|
const lastNormalUrl = |
|
|
|
typeof lastNormalUrlNode?.data === 'string' ? lastNormalUrlNode.data : undefined |
|
|
|
typeof lastNormalUrlNode?.data === 'string' ? lastNormalUrlNode.data : undefined |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return { nodes, allImages, emojiInfos, lastNormalUrl } |
|
|
|
|
|
|
|
}, [event]) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!nodes || nodes.length === 0) { |
|
|
|
|
|
|
|
return null |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let imageIndex = 0 |
|
|
|
return ( |
|
|
|
return ( |
|
|
|
<div className={cn('text-wrap break-words whitespace-pre-wrap', className)}> |
|
|
|
<div className={cn('text-wrap break-words whitespace-pre-wrap', className)}> |
|
|
|
{nodes.map((node, index) => { |
|
|
|
{nodes.map((node, index) => { |
|
|
|
@ -179,6 +186,3 @@ const Content = memo( |
|
|
|
</div> |
|
|
|
</div> |
|
|
|
) |
|
|
|
) |
|
|
|
} |
|
|
|
} |
|
|
|
) |
|
|
|
|
|
|
|
Content.displayName = 'Content' |
|
|
|
|
|
|
|
export default Content |
|
|
|
|
|
|
|
|