From 9524aea0fab61f5bc5936c403e3b3159a46459e8 Mon Sep 17 00:00:00 2001 From: mroxso <24775431+mroxso@users.noreply.github.com> Date: Sun, 28 Jan 2024 21:10:01 +0100 Subject: [PATCH] add tag feed --- lumina/app/tag/[tag]/page.tsx | 44 +++++++++++++++++++++++++++++++++++ lumina/components/TagFeed.tsx | 44 +++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 lumina/app/tag/[tag]/page.tsx create mode 100644 lumina/components/TagFeed.tsx diff --git a/lumina/app/tag/[tag]/page.tsx b/lumina/app/tag/[tag]/page.tsx new file mode 100644 index 0000000..6a5512e --- /dev/null +++ b/lumina/app/tag/[tag]/page.tsx @@ -0,0 +1,44 @@ +'use client'; + +import Head from "next/head"; +import { NostrProvider } from "nostr-react"; +import ProfileInfoCard from "@/components/ProfileInfoCard"; +import ProfileFeed from "@/components/ProfileFeed"; +import { useParams } from 'next/navigation' +import { nip19 } from "nostr-tools"; +import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs" +import { SectionIcon, GridIcon } from '@radix-ui/react-icons' +import TagFeed from "@/components/TagFeed"; + +const relayUrls = [ + "wss://relay.damus.io", + "wss://relay.nostr.band", +]; + +export default function Home() { + + const params = useParams() + let tag = params.tag + // check if pubkey contains "npub" + // if so, then we need to convert it to a pubkey + // if (pubkey.includes("npub")) { + // // convert npub to pubkey + // pubkey = nip19.decode(pubkey.toString()).data.toString() + // } + + return ( + <> + + + LUMINA.rocks - {tag} + + + + +
+ +
+
+ + ); +} diff --git a/lumina/components/TagFeed.tsx b/lumina/components/TagFeed.tsx new file mode 100644 index 0000000..2a2ebb2 --- /dev/null +++ b/lumina/components/TagFeed.tsx @@ -0,0 +1,44 @@ +import { useRef } from "react"; +import { useNostrEvents, dateToUnix } from "nostr-react"; +import NoteCard from './NoteCard'; + +interface TagFeedProps { + tag: string; +} + +const TagFeed: React.FC = ({tag}) => { + const now = useRef(new Date()); // Make sure current time isn't re-rendered + + const { events } = useNostrEvents({ + filter: { + // since: dateToUnix(now.current), // all new events from now + // since: 0, + // limit: 100, + kinds: [1], + "#t": [tag], + }, + }); + + // const filteredEvents = events.filter((event) => event.content.includes(".jpg")); + // filter events with regex that checks for png, jpg, or gif + let filteredEvents = events.filter((event) => event.content.match(/https?:\/\/.*\.(?:png|jpg|gif)/g)?.[0]); + + // now filter all events with a tag[0] == t and tag[1] == nsfw + filteredEvents = filteredEvents.filter((event) => event.tags.map((tag) => tag[0] == "t" && tag[1] == "nsfw")); + // filter out all replies + // filteredEvents = filteredEvents.filter((event) => !event.tags.some((tag) => { return tag[0] == 'e' })); + + return ( + <> +

Tag Feed for {tag}

+ {filteredEvents.map((event) => ( + //

{event.pubkey} posted: {event.content}

+
+ +
+ ))} + + ); +} + +export default TagFeed; \ No newline at end of file