diff --git a/app/page.tsx b/app/page.tsx index e93eca3..50ae681 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -3,6 +3,7 @@ import { Search } from "@/components/Search"; import { TrendingAccounts } from "@/components/TrendingAccounts"; import { TrendingImages } from "@/components/TrendingImages"; +import { TrendingImagesNew } from "@/components/TrendingImagesNew"; import { useEffect } from "react"; @@ -17,7 +18,8 @@ export default function Home() { {/* */} - + {/* */} + > ); } diff --git a/components/TrendingImageNew.tsx b/components/TrendingImageNew.tsx new file mode 100644 index 0000000..e515a3b --- /dev/null +++ b/components/TrendingImageNew.tsx @@ -0,0 +1,77 @@ +import React from 'react'; +import { useProfile } from "nostr-react"; +import { nip19 } from "nostr-tools"; +import { + Card, + CardHeader, + CardTitle, + SmallCardContent, +} from "@/components/ui/card" +import Link from 'next/link'; +import { Avatar } from './ui/avatar'; +import { AvatarImage } from '@radix-ui/react-avatar'; + +interface TrendingImageNewProps { + event: { + id: string; + pubkey: string; + content: string; + created_at: string; + tags: Array; + } +} + +const TrendingImageNew: React.FC = ({ event }) => { + const { data: userData } = useProfile({ + pubkey: event.pubkey, + }); + + const npubShortened = (() => { + let encoded = nip19.npubEncode(event.pubkey); + let parts = encoded.split('npub'); + return 'npub' + parts[1].slice(0, 4) + ':' + parts[1].slice(-3); + })(); + + const title = userData?.username || userData?.display_name || userData?.name || userData?.npub || npubShortened; + const text = event.content.replaceAll('\n', ' '); + + // Get image URL from imeta tags + const imageUrl = event.tags.find(tag => tag[0] === 'imeta' && tag[1]?.startsWith('url ')) + ?.slice(1)[0]?.replace('url ', ''); + + const hrefProfile = `/profile/${nip19.npubEncode(event.pubkey)}`; + const hrefNote = `/note/${nip19.noteEncode(event.id)}`; + const profileImageSrc = userData?.picture || "https://robohash.org/" + event.pubkey; + + return ( + + + + + + + + + {title} + + + + + + + + {imageUrl && ( + + + + + + )} + + + + + ); +} + +export default TrendingImageNew; \ No newline at end of file diff --git a/components/TrendingImagesNew.tsx b/components/TrendingImagesNew.tsx new file mode 100644 index 0000000..e0dec93 --- /dev/null +++ b/components/TrendingImagesNew.tsx @@ -0,0 +1,35 @@ +import React, { useState, useEffect } from 'react'; +import TrendingImage from '@/components/TrendingImageNew'; +import { Spinner } from '@/components/spinner'; + +export function TrendingImagesNew() { + const [events, setEvents] = useState([]); + + useEffect(() => { + // TODO: Fetch trending images from luminas own relay via http call + fetch('https://relay.lumina.rocks/api/trending/kind20') + .then(res => res.json()) + .then(data => setEvents(data.trending)) + .catch(error => { + console.error('Error calling trending images:', error); + }); + }, []); + + return ( + + Currently Trending + + {events && events.length > 0 ? ( + events.map((event, index) => ( + + )) + ) : ( + + + Curating Trending Images for you.. 💜 + + )} + + + ); +} \ No newline at end of file