import React, { useState, useMemo } from "react"; import { Search } from "lucide-react"; import { Button } from "@/components/ui/button"; import { useCurrentUser } from "@/hooks/useCurrentUser"; import { useAppSubmissions } from "@/hooks/useAppSubmissions"; import { AppShowcaseCard } from "@/components/AppShowcaseCard"; import { Collapsible, CollapsibleContent, CollapsibleTrigger, } from "@/components/ui/collapsible"; import { nip19 } from 'nostr-tools'; import { shuffleArray } from "@/lib/utils"; import type { AppSubmission } from "@/hooks/useAppSubmissions"; import { Skeleton } from "@/components/ui/skeleton"; import { Card, CardContent } from "@/components/ui/card"; import { RelaySelector } from "@/components/RelaySelector"; export function AppShowcase() { const { user } = useCurrentUser(); const { data: submissions = [], isLoading } = useAppSubmissions(); const [showAllApps, setShowAllApps] = useState(false); const MODERATOR_NPUB = 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc'; const MODERATOR_HEX = (() => { try { const decoded = nip19.decode(MODERATOR_NPUB); return decoded.type === 'npub' ? decoded.data : ''; } catch { return ''; } })(); const isModerator = user?.pubkey === MODERATOR_HEX; // Filter submissions const visibleSubmissions = submissions.filter(app => !app.isHidden); // Separate template apps from other apps const templateApps = useMemo(() => shuffleArray(visibleSubmissions.filter(app => app.appTags.includes('Template'))), [visibleSubmissions] ); const nonTemplateSubmissions = visibleSubmissions.filter(app => !app.appTags.includes('Template')); // Get Halloween Hackathon 2025 apps that are featured (for main showcase) const halloweenApps = useMemo(() => shuffleArray(nonTemplateSubmissions.filter(app => app.appTags.includes('Halloween Hackathon 2025') && app.isFeatured )), [nonTemplateSubmissions] ); // Filter out Halloween Hackathon 2025 apps from other sections (unless featured, they go in Halloween section) const nonHalloweenSubmissions = nonTemplateSubmissions.filter(app => !app.appTags.includes('Halloween Hackathon 2025') ); // Shuffle featured and approved apps on each component mount/render for random display order const featuredApps = useMemo(() => shuffleArray(nonHalloweenSubmissions.filter(app => app.isFeatured)), [nonHalloweenSubmissions] ); const approvedApps = useMemo(() => shuffleArray(nonHalloweenSubmissions.filter(app => app.isApproved && !app.isFeatured)), [nonHalloweenSubmissions] ); // Don't show showcase if no apps exist if (isLoading) { return (
{Array.from({ length: 6 }).map((_, i) => (
))}
); } if (!submissions.length) { return (

No apps found. Try another relay?

); } return (
{/* Apps Grid */}
{/* Featured Apps */} {featuredApps.length > 0 && (
⭐

Featured Apps

Handpicked applications showcasing the best of our community

{featuredApps.slice(0, 6).map((app) => ( ))}
)} {/* Halloween Hackathon 2025 Apps */} {halloweenApps.length > 0 && (
🎃

Halloween Hackathon 2025

Featured spooky creations from our Halloween hackathon

{halloweenApps.slice(0, 6).map((app) => ( ))}
)} {/* Templates Section */} {templateApps.length > 0 && (
📋

Templates

Ready-to-use templates to kickstart your project

{templateApps.slice(0, 6).map((app) => ( ))}
)} {/* More Apps (Approved) - Collapsible */} {approvedApps.length > 0 && (
{approvedApps.map((app) => ( ))}
)}
); }