Files
lumina/components/ProfileQuickViewFeed.tsx
mroxso 5b3246c077 Feature: Display Improvements (#40)
* refactor: improve event rendering logic and add no posts found message

* fix errors
2025-02-09 18:26:10 +01:00

76 lines
2.3 KiB
TypeScript

import { useRef, useState } from "react";
import { useNostrEvents } from "nostr-react";
import { Skeleton } from "@/components/ui/skeleton";
import { Button } from "@/components/ui/button";
import QuickViewKind20NoteCard from "./QuickViewKind20NoteCard";
import { getImageUrl } from "@/utils/utils";
interface ProfileQuickViewFeedProps {
pubkey: string;
}
const ProfileQuickViewFeed: React.FC<ProfileQuickViewFeedProps> = ({ pubkey }) => {
const now = useRef(new Date()); // Make sure current time isn't re-rendered
const [limit, setLimit] = useState(20);
const { isLoading, events } = useNostrEvents({
filter: {
authors: [pubkey],
limit: limit,
kinds: [20],
},
});
const loadMore = () => {
setLimit(limit => limit + 50);
}
return (
<>
<div className="grid grid-cols-3 gap-2">
{events.length === 0 && isLoading ? (
<>
<div>
<Skeleton className="h-[125px] rounded-xl" />
</div>
<div>
<Skeleton className="h-[125px] rounded-xl" />
</div>
<div>
<Skeleton className="h-[125px] rounded-xl" />
</div>
</>
) : events.some(event => getImageUrl(event.tags)) ? (
<>
{events.map((event) => {
const imageUrl = getImageUrl(event.tags);
return imageUrl ? (
<QuickViewKind20NoteCard
key={event.id}
pubkey={event.pubkey}
text={event.content}
image={imageUrl}
event={event}
tags={event.tags}
eventId={event.id}
linkToNote={true}
/>
) : null;
})}
</>
) : (
<div className="col-span-3 flex flex-col items-center justify-center py-10 text-gray-500">
<p className="text-lg">No posts found :(</p>
</div>
)}
</div>
{!isLoading && events.some(event => getImageUrl(event.tags)) ? (
<div className="flex justify-center p-4">
<Button className="w-full" onClick={loadMore}>Load More</Button>
</div>
) : null}
</>
);
}
export default ProfileQuickViewFeed;