From f37d35bf6c96fec97fc213c557a392d6e52e6105 Mon Sep 17 00:00:00 2001 From: Derek Ross Date: Wed, 10 Dec 2025 15:05:56 -0500 Subject: [PATCH] feat: add community page --- src/AppRouter.tsx | 2 + src/components/NoteContent.tsx | 317 ++++++++++--- src/components/ProjectSidebar.tsx | 13 +- src/hooks/useCommunity.ts | 217 +++++++++ src/pages/Community.tsx | 723 ++++++++++++++++++++++++++++++ 5 files changed, 1217 insertions(+), 55 deletions(-) create mode 100644 src/hooks/useCommunity.ts create mode 100644 src/pages/Community.tsx diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index dd0f5e75..93fc3e32 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -5,6 +5,7 @@ import { URLFragmentHandler } from "./components/URLFragmentHandler"; import Index from "./pages/Index"; import Clone from "./pages/Clone"; +import Community from "./pages/Community"; import Settings from "./pages/Settings"; import Preferences from "./pages/Preferences"; import NostrSettings from "./pages/NostrSettings"; @@ -36,6 +37,7 @@ export function AppRouter() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/src/components/NoteContent.tsx b/src/components/NoteContent.tsx index a7a7c30f..6cb6e533 100644 --- a/src/components/NoteContent.tsx +++ b/src/components/NoteContent.tsx @@ -2,76 +2,130 @@ import { useMemo } from 'react'; import { type NostrEvent } from '@nostrify/nostrify'; import { Link } from 'react-router-dom'; import { nip19 } from 'nostr-tools'; +import { useNostr } from '@nostrify/react'; +import { useQuery } from '@tanstack/react-query'; import { useAuthor } from '@/hooks/useAuthor'; import { genUserName } from '@/lib/genUserName'; import { cn } from '@/lib/utils'; +import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar'; interface NoteContentProps { event: NostrEvent; className?: string; + /** When true, renders mentions and hashtags as styled text instead of clickable links */ + disableLinks?: boolean; + /** When true, hides embedded note/event previews entirely */ + hideEmbeds?: boolean; } /** Parses content of text note events so that URLs and hashtags are linkified. */ export function NoteContent({ - event, - className, -}: NoteContentProps) { + event, + className, + disableLinks = false, + hideEmbeds = false, +}: NoteContentProps) { // Process the content to render mentions, links, etc. const content = useMemo(() => { const text = event.content; - + // Regex to find URLs, Nostr references, and hashtags const regex = /(https?:\/\/[^\s]+)|nostr:(npub1|note1|nprofile1|nevent1)([023456789acdefghjklmnpqrstuvwxyz]+)|(#\w+)/g; - + const parts: React.ReactNode[] = []; let lastIndex = 0; let match: RegExpExecArray | null; let keyCounter = 0; - + while ((match = regex.exec(text)) !== null) { const [fullMatch, url, nostrPrefix, nostrData, hashtag] = match; const index = match.index; - + // Add text before this match if (index > lastIndex) { parts.push(text.substring(lastIndex, index)); } - + if (url) { - // Handle URLs - parts.push( - - {url} - - ); + // Handle URLs - always render as links (but prevent click propagation when disableLinks) + if (disableLinks) { + parts.push( + + {url} + + ); + } else { + parts.push( + + {url} + + ); + } } else if (nostrPrefix && nostrData) { // Handle Nostr references try { const nostrId = `${nostrPrefix}${nostrData}`; const decoded = nip19.decode(nostrId); - + if (decoded.type === 'npub') { const pubkey = decoded.data; parts.push( - + ); - } else { - // For other types, just show as a link + } else if (decoded.type === 'nprofile') { + const pubkey = decoded.data.pubkey; parts.push( - - {fullMatch} - + ); + } else if (decoded.type === 'nevent') { + if (hideEmbeds) { + // Skip embedded events entirely when hideEmbeds is true + } else if (disableLinks) { + parts.push( + + ); + } else { + parts.push( + + ); + } + } else if (decoded.type === 'note') { + if (hideEmbeds) { + // Skip embedded notes entirely when hideEmbeds is true + } else if (disableLinks) { + parts.push( + + ); + } else { + parts.push( + + ); + } + } else { + // For other types, just show as styled text or link + if (disableLinks) { + parts.push( + + {fullMatch} + + ); + } else { + parts.push( + + {fullMatch} + + ); + } } } catch { // If decoding fails, just render as text @@ -79,33 +133,41 @@ export function NoteContent({ } } else if (hashtag) { // Handle hashtags - const tag = hashtag.slice(1); // Remove the # - parts.push( - - {hashtag} - - ); + if (disableLinks) { + parts.push( + + {hashtag} + + ); + } else { + const tag = hashtag.slice(1); // Remove the # + parts.push( + + {hashtag} + + ); + } } - + lastIndex = index + fullMatch.length; } - + // Add any remaining text if (lastIndex < text.length) { parts.push(text.substring(lastIndex)); } - + // If no special content was found, just use the plain text if (parts.length === 0) { parts.push(text); } - + return parts; - }, [event]); + }, [event, disableLinks, hideEmbeds]); return (
@@ -114,24 +176,173 @@ export function NoteContent({ ); } -// Helper component to display user mentions -function NostrMention({ pubkey }: { pubkey: string }) { +// Helper component to display user mentions with avatar +function NostrMention({ pubkey, disableLink = false }: { pubkey: string; disableLink?: boolean }) { const author = useAuthor(pubkey); const npub = nip19.npubEncode(pubkey); const hasRealName = !!author.data?.metadata?.name; const displayName = author.data?.metadata?.name ?? genUserName(pubkey); + const picture = author.data?.metadata?.picture; + + const content = ( + <> + + + {displayName.slice(0, 2).toUpperCase()} + + @{displayName} + + ); + + if (disableLink) { + return ( + + {content} + + ); + } return ( - - @{displayName} + {content} ); +} + +// Helper component to display embedded events +function NostrEventEmbed({ eventId }: { eventId: string }) { + const { nostr } = useNostr(); + + const { data: event, isLoading } = useQuery({ + queryKey: ['nostr', 'event', eventId], + queryFn: async (c) => { + const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]); + const [event] = await nostr.query([{ ids: [eventId], limit: 1 }], { signal }); + return event; + }, + staleTime: 300000, + }); + + const author = useAuthor(event?.pubkey); + const note1 = nip19.noteEncode(eventId); + + if (isLoading) { + return ( +
+
+
+
+ ); + } + + if (!event) { + return ( + + nostr:{note1.slice(0, 12)}... + + ); + } + + const displayName = author.data?.metadata?.name ?? genUserName(event.pubkey); + const picture = author.data?.metadata?.picture; + const contentPreview = event.content.length > 200 + ? event.content.slice(0, 200) + '...' + : event.content; + + return ( + +
+ + + {displayName.slice(0, 2).toUpperCase()} + + {displayName} + + {new Date(event.created_at * 1000).toLocaleDateString()} + +
+

+ {contentPreview} +

+ + ); +} + +// Helper component to display embedded events without links (for use inside clickable cards) +function NostrEventPreview({ eventId }: { eventId: string }) { + const { nostr } = useNostr(); + + const { data: event, isLoading } = useQuery({ + queryKey: ['nostr', 'event', eventId], + queryFn: async (c) => { + const signal = AbortSignal.any([c.signal, AbortSignal.timeout(5000)]); + const [event] = await nostr.query([{ ids: [eventId], limit: 1 }], { signal }); + return event; + }, + staleTime: 300000, + }); + + const author = useAuthor(event?.pubkey); + + if (isLoading) { + return ( +
+
+
+
+ ); + } + + if (!event) { + return ( + + [quoted note] + + ); + } + + const displayName = author.data?.metadata?.name ?? genUserName(event.pubkey); + const picture = author.data?.metadata?.picture; + const contentPreview = event.content.length > 200 + ? event.content.slice(0, 200) + '...' + : event.content; + + return ( +
+
+ + + {displayName.slice(0, 2).toUpperCase()} + + {displayName} + + {new Date(event.created_at * 1000).toLocaleDateString()} + +
+

+ {contentPreview} +

+
+ ); } \ No newline at end of file diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index 108f5f5a..f544b974 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Plus, Folder, GitBranch, Loader2, ChevronDown, ChevronRight, Star, Columns2, X, Settings, HelpCircle, Search, Tag, Folders } from 'lucide-react'; +import { Plus, Folder, GitBranch, Loader2, ChevronDown, ChevronRight, Star, Columns2, X, Settings, HelpCircle, Search, Tag, Folders, Users } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { Input } from '@/components/ui/input'; @@ -511,7 +511,7 @@ export function ProjectSidebar({
- {/* Settings and Help at Bottom */} + {/* Settings, Community, and Help at Bottom */}
+ + +
+
+
+ +
+
+ {/* Hero Section */} +
+

+ Welcome to the Shakespeare Community +

+

+ Connect with builders, get help with your projects, and be part of the future of AI-powered web development. +

+ +
+ + {/* How to Get Involved - 3 Cards */} +
+

How to Get Involved

+
+ {/* Join Community Online */} + +
+ Community chat +
+ +
+ +
+ Join Community Online + + Chat with other Shakespeare builders, get help with your projects, and share what you're creating. + +
+ + + +
+ + {/* Connect IRL */} + +
+ Community events +
+ +
+ +
+ Connect IRL + + Attend conferences, workshops, and meetups. Learn from experts and network with fellow builders. + +
+ + + +
+ + {/* Become an Ambassador */} + +
+ Ambassador program +
+ +
+ +
+ Become an Ambassador + + Host workshops in your city, teach others to build with Shakespeare, and earn recognition. + +
+ + + +
+
+
+ + {/* #ShakespeareDIY Feed */} +
+
+
+

+ + #ShakespeareDIY Feed +

+

See what the community is building

+
+ Live from Nostr +
+ + {feedLoading ? ( +
+ {Array.from({ length: 4 }).map((_, i) => ( + + +
+ +
+ + +
+
+
+
+ ))} +
+ ) : feedPosts && feedPosts.length > 0 ? ( +
+ {feedPosts.map((post) => ( + + ))} +
+ ) : ( + + +

+ No posts yet. Be the first to share with #ShakespeareDIY! +

+
+
+ )} +
+ + {/* Events Section */} +
+
+
+

+ + Upcoming Events +

+

Conferences, workshops, and meetups

+
+
+ + {eventsLoading ? ( +
+ {Array.from({ length: 2 }).map((_, i) => ( + + + + + + + + ))} +
+ ) : events && events.length > 0 ? ( +
+ {events.map((event) => ( + + ))} +
+ ) : ( + + + +

+ No upcoming events. Check back soon! +

+
+
+ )} +
+ + {/* Ambassador Program */} +
+
+ + +
+ +
+ Shakespeare Ambassador Program + + Become a community leader by hosting workshops in your city. Teach others how to build with Shakespeare + and help grow the community. + +
+ +
    +
  • +
    + Host local workshops and meetups +
  • +
  • +
    + Get exclusive access to new features +
  • +
  • +
    + Earn free credits for teaching +
  • +
  • +
    + Be recognized in the community +
  • +
+ +
+
+ + +
+ Workshop +
+ + Host a Workshop + + Already know Shakespeare well? Host a workshop in your area and teach others how to build amazing + websites with AI. + + + + + +
+
+
+ + {/* Chat Channels */} +
+
+

+ + Chat Channels +

+

Explore the different channels in Shakespeare Chat

+
+ +
+ + +
+
+ +
+ #announcements +
+
+ +

+ Official updates about Shakespeare features, releases, and important news from the team. +

+
+
+ + + +
+
+ +
+ #feedback +
+
+ +

+ Share your ideas, suggestions, and feedback to help improve Shakespeare. +

+
+
+ + + +
+
+ +
+ #git +
+
+ +

+ Follow along with the latest commits and development activity on Shakespeare. +

+
+
+ + + +
+
+ +
+ #prompts +
+
+ +

+ Share and discover effective prompts for building better projects with AI. +

+
+
+ + + +
+
+ +
+ #showcase +
+
+ +

+ Show off your Shakespeare creations and get inspired by what others have built. +

+
+
+ + + +
+
+ +
+ #support +
+
+ +

+ Get help from the community when you're stuck or have questions about using Shakespeare. +

+
+
+
+ + +
+ + {/* Resources Section */} +
+

+ + Resources +

+
+ {/* Blog Posts */} + + + Featured Guides + Learn tips and tricks from the community + + + {BLOG_POSTS.map((post, i) => ( + +
+

+ {post.title} +

+

by {post.author}

+
+ +
+ ))} + +
+
+ + {/* FAQs */} + + + + + Frequently Asked Questions + + + + + {FAQS.map((faq, i) => ( + + + {faq.question} + + + {faq.answer} + + + ))} + + + + +
+
+ + {/* Final CTA */} +
+

Ready to Join?

+

+ Join Shakespeare Chat to connect with the community, get help with your projects, and be part of the + conversation. +

+ +
+
+
+
+ ); +} + +// Feed Post Component +function FeedPost({ event }: { event: NostrEvent }) { + const { data: author } = useAuthor(event.pubkey); + const displayName = author?.metadata?.name || genUserName(event.pubkey); + const picture = author?.metadata?.picture; + const timeAgo = getTimeAgo(event.created_at); + const nevent = nip19.neventEncode({ id: event.id, author: event.pubkey }); + const njumpUrl = `https://njump.me/${nevent}`; + + return ( + + + +
+ + + {displayName.slice(0, 2).toUpperCase()} + +
+
+ {displayName} + {timeAgo} +
+
+ +
+
+
+
+
+
+ ); +} + +// Event Card Component +function EventCard({ event }: { event: NostrEvent }) { + const eventData = extractCalendarEventData(event); + const formattedDate = formatEventDate(eventData.start, eventData.kind, eventData.startTzid); + + return ( + + {eventData.image && ( +
+ {eventData.title} +
+ )} + +
+
+ {eventData.title} + {eventData.summary && ( + {eventData.summary} + )} +
+
+
+ +
+ + {formattedDate} +
+ {eventData.location && ( +
+ + {eventData.location} +
+ )} + {eventData.hashtags.length > 0 && ( +
+ {eventData.hashtags.slice(0, 3).map((tag, i) => ( + + #{tag} + + ))} +
+ )} +
+
+ ); +} + +// Helper function +function getTimeAgo(timestamp: number): string { + const seconds = Math.floor(Date.now() / 1000 - timestamp); + if (seconds < 60) return 'just now'; + const minutes = Math.floor(seconds / 60); + if (minutes < 60) return `${minutes}m`; + const hours = Math.floor(minutes / 60); + if (hours < 24) return `${hours}h`; + const days = Math.floor(hours / 24); + if (days < 7) return `${days}d`; + const weeks = Math.floor(days / 7); + if (weeks < 4) return `${weeks}w`; + const months = Math.floor(days / 30); + if (months < 12) return `${months}mo`; + return `${Math.floor(months / 12)}y`; +}