feat: 💨

This commit is contained in:
codytseng
2025-01-14 12:44:22 +08:00
parent a3c6cf0c21
commit 3f031da748
3 changed files with 12 additions and 14 deletions

View File

@@ -8,14 +8,10 @@ export default function Image({
image: { url, blurHash }, image: { url, blurHash },
alt, alt,
className = '', className = '',
classNames = {},
...props ...props
}: HTMLAttributes<HTMLDivElement> & { }: HTMLAttributes<HTMLDivElement> & {
image: TImageInfo image: TImageInfo
alt?: string alt?: string
classNames?: {
wrapper?: string
}
}) { }) {
const [isLoading, setIsLoading] = useState(true) const [isLoading, setIsLoading] = useState(true)
const [displayBlurHash, setDisplayBlurHash] = useState(true) const [displayBlurHash, setDisplayBlurHash] = useState(true)
@@ -24,8 +20,8 @@ export default function Image({
useEffect(() => { useEffect(() => {
if (blurHash) { if (blurHash) {
const { numX, numY } = decodeBlurHashSize(blurHash) const { numX, numY } = decodeBlurHashSize(blurHash)
const width = numX * 5 const width = numX * 3
const height = numY * 5 const height = numY * 3
const pixels = decode(blurHash, width, height) const pixels = decode(blurHash, width, height)
const canvas = document.createElement('canvas') const canvas = document.createElement('canvas')
canvas.width = width canvas.width = width
@@ -41,7 +37,7 @@ export default function Image({
}, [blurHash]) }, [blurHash])
return ( return (
<div className={cn('relative', classNames.wrapper ?? '')} {...props}> <div className={cn('relative', className)} {...props}>
{isLoading && <Skeleton className={cn('absolute inset-0', className)} />} {isLoading && <Skeleton className={cn('absolute inset-0', className)} />}
<img <img
src={url} src={url}

View File

@@ -35,12 +35,14 @@ export default function PictureNoteCard({
if (!firstImage) return null if (!firstImage) return null
return ( return (
<div className={cn('space-y-1 cursor-pointer', className)} onClick={() => push(toNote(event))}> <div className={cn('cursor-pointer', 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={firstImage} />
<div className="line-clamp-2 px-2 font-semibold">{title}</div> <div className="p-2 space-y-1">
<div className="flex items-center gap-2 px-2"> <div className="line-clamp-2 font-semibold">{title}</div>
<UserAvatar userId={event.pubkey} size="xSmall" /> <div className="flex items-center gap-2">
<Username userId={event.pubkey} className="text-sm text-muted-foreground truncate" /> <UserAvatar userId={event.pubkey} size="xSmall" />
<Username userId={event.pubkey} className="text-sm text-muted-foreground truncate" />
</div>
</div> </div>
</div> </div>
) )

View File

@@ -48,11 +48,11 @@ class ClientService extends EventTarget {
private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 }) private profileEventCache = new LRUCache<string, Promise<NEvent | undefined>>({ max: 10000 })
private profileEventDataloader = new DataLoader<string, NEvent | undefined>( private profileEventDataloader = new DataLoader<string, NEvent | undefined>(
(ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))), (ids) => Promise.all(ids.map((id) => this._fetchProfileEvent(id))),
{ cacheMap: this.profileEventCache } { cacheMap: this.profileEventCache, maxBatchSize: 10 }
) )
private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>( private fetchProfileEventFromDefaultRelaysDataloader = new DataLoader<string, NEvent | undefined>(
this.profileEventBatchLoadFn.bind(this), this.profileEventBatchLoadFn.bind(this),
{ cache: false } { cache: false, maxBatchSize: 10 }
) )
private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>( private relayListEventDataLoader = new DataLoader<string, NEvent | undefined>(
this.relayListEventBatchLoadFn.bind(this), this.relayListEventBatchLoadFn.bind(this),