feat: add multi-image icon
This commit is contained in:
@@ -1,9 +1,7 @@
|
|||||||
import { isNsfwEvent } from '@/lib/event'
|
import { extractImageInfosFromEventTags, isNsfwEvent } from '@/lib/event'
|
||||||
import { extractImageInfoFromTag } from '@/lib/tag'
|
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { TImageInfo } from '@/types'
|
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
import { memo, ReactNode } from 'react'
|
import { memo, ReactNode, useMemo } from 'react'
|
||||||
import {
|
import {
|
||||||
embedded,
|
embedded,
|
||||||
embeddedHashtagRenderer,
|
embeddedHashtagRenderer,
|
||||||
@@ -15,13 +13,7 @@ import {
|
|||||||
import { ImageCarousel } from '../ImageCarousel'
|
import { ImageCarousel } from '../ImageCarousel'
|
||||||
|
|
||||||
const PictureContent = memo(({ event, className }: { event: Event; className?: string }) => {
|
const PictureContent = memo(({ event, className }: { event: Event; className?: string }) => {
|
||||||
const images: TImageInfo[] = []
|
const images = useMemo(() => extractImageInfosFromEventTags(event), [event])
|
||||||
event.tags.forEach((tag) => {
|
|
||||||
const imageInfo = extractImageInfoFromTag(tag)
|
|
||||||
if (imageInfo) {
|
|
||||||
images.push(imageInfo)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
const isNsfw = isNsfwEvent(event)
|
const isNsfw = isNsfwEvent(event)
|
||||||
|
|
||||||
const nodes: ReactNode[] = [
|
const nodes: ReactNode[] = [
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
import { extractFirstPictureFromPictureEvent } from '@/lib/event'
|
import { extractImageInfosFromEventTags } from '@/lib/event'
|
||||||
import { toNote } from '@/lib/link'
|
import { toNote } from '@/lib/link'
|
||||||
import { tagNameEquals } from '@/lib/tag'
|
import { tagNameEquals } from '@/lib/tag'
|
||||||
import { cn } from '@/lib/utils'
|
import { cn } from '@/lib/utils'
|
||||||
import { useSecondaryPage } from '@/PageManager'
|
import { useSecondaryPage } from '@/PageManager'
|
||||||
|
import { Images } from 'lucide-react'
|
||||||
import { Event } from 'nostr-tools'
|
import { Event } from 'nostr-tools'
|
||||||
import { useMemo } from 'react'
|
import { useMemo } from 'react'
|
||||||
import {
|
import {
|
||||||
@@ -23,7 +24,7 @@ export default function PictureNoteCard({
|
|||||||
className?: string
|
className?: string
|
||||||
}) {
|
}) {
|
||||||
const { push } = useSecondaryPage()
|
const { push } = useSecondaryPage()
|
||||||
const firstImage = extractFirstPictureFromPictureEvent(event)
|
const images = useMemo(() => extractImageInfosFromEventTags(event), [event])
|
||||||
const title = useMemo(() => {
|
const title = useMemo(() => {
|
||||||
const title = event.tags.find(tagNameEquals('title'))?.[1] ?? event.content
|
const title = event.tags.find(tagNameEquals('title'))?.[1] ?? event.content
|
||||||
return embedded(title, [
|
return embedded(title, [
|
||||||
@@ -32,11 +33,16 @@ export default function PictureNoteCard({
|
|||||||
embeddedHashtagRenderer
|
embeddedHashtagRenderer
|
||||||
])
|
])
|
||||||
}, [event])
|
}, [event])
|
||||||
if (!firstImage) return null
|
if (!images.length) return null
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={cn('cursor-pointer', className)} onClick={() => push(toNote(event))}>
|
<div className={cn('cursor-pointer relative', className)} onClick={() => push(toNote(event))}>
|
||||||
<Image className="rounded-lg w-full aspect-[6/8]" image={firstImage} />
|
<Image className="rounded-lg w-full aspect-[6/8]" image={images[0]} />
|
||||||
|
{images.length > 1 && (
|
||||||
|
<div className="absolute top-2 right-2 bg-background/50 rounded-full p-2">
|
||||||
|
<Images size={16} />
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
<div className="p-2 space-y-1">
|
<div className="p-2 space-y-1">
|
||||||
<div className="line-clamp-2 font-semibold">{title}</div>
|
<div className="line-clamp-2 font-semibold">{title}</div>
|
||||||
<div className="flex items-center gap-2">
|
<div className="flex items-center gap-2">
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { BIG_RELAY_URLS, COMMENT_EVENT_KIND, PICTURE_EVENT_KIND } from '@/constants'
|
import { BIG_RELAY_URLS, COMMENT_EVENT_KIND, PICTURE_EVENT_KIND } from '@/constants'
|
||||||
import client from '@/services/client.service'
|
import client from '@/services/client.service'
|
||||||
import { TRelayList } from '@/types'
|
import { TImageInfo, TRelayList } from '@/types'
|
||||||
import { Event, kinds, nip19 } from 'nostr-tools'
|
import { Event, kinds, nip19 } from 'nostr-tools'
|
||||||
import { extractImageInfoFromTag, isReplyETag, isRootETag, tagNameEquals } from './tag'
|
import { extractImageInfoFromTag, isReplyETag, isRootETag, tagNameEquals } from './tag'
|
||||||
import { isWebsocketUrl, normalizeUrl } from './url'
|
import { isWebsocketUrl, normalizeUrl } from './url'
|
||||||
@@ -254,13 +254,15 @@ export function extractHashtags(content: string) {
|
|||||||
return hashtags
|
return hashtags
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractFirstPictureFromPictureEvent(event: Event) {
|
export function extractImageInfosFromEventTags(event: Event) {
|
||||||
if (!isPictureEvent(event)) return null
|
const images: TImageInfo[] = []
|
||||||
for (const tag of event.tags) {
|
event.tags.forEach((tag) => {
|
||||||
const url = extractImageInfoFromTag(tag)
|
const imageInfo = extractImageInfoFromTag(tag)
|
||||||
if (url) return url
|
if (imageInfo) {
|
||||||
}
|
images.push(imageInfo)
|
||||||
return null
|
}
|
||||||
|
})
|
||||||
|
return images
|
||||||
}
|
}
|
||||||
|
|
||||||
export function extractImagesFromContent(content: string) {
|
export function extractImagesFromContent(content: string) {
|
||||||
|
|||||||
Reference in New Issue
Block a user