import React, { useState, useMemo } from "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 { Skeleton } from "@/components/ui/skeleton"; import { Card, CardContent } from "@/components/ui/card"; import { RelaySelector } from "@/components/RelaySelector"; import { useAppContext } from "@/hooks/useAppContext"; export function AppShowcase() { const { user } = useCurrentUser(); const { config } = useAppContext(); const { data: submissions = [], isLoading } = useAppSubmissions(); const [showAllApps, setShowAllApps] = useState(false); // Get moderator hex from config const MODERATOR_HEX = useMemo(() => { try { const decoded = nip19.decode(config.showcaseModerator); return decoded.type === 'npub' ? decoded.data : ''; } catch { return ''; } }, [config.showcaseModerator]); const isModerator = user?.pubkey === MODERATOR_HEX; // Filter and shuffle submissions - memoized with stable dependency const { templateApps, halloweenApps, featuredApps, approvedApps } = useMemo(() => { // Filter visible submissions const visibleSubmissions = submissions.filter(app => !app.isHidden); // Separate template apps from other apps const templates = shuffleArray(visibleSubmissions.filter(app => app.appTags.includes('Template'))); const nonTemplateSubmissions = visibleSubmissions.filter(app => !app.appTags.includes('Template')); // Get Halloween Hackathon 2025 apps that are featured (for main showcase) const halloween = shuffleArray(nonTemplateSubmissions.filter(app => app.appTags.includes('Halloween Hackathon 2025') && app.isFeatured )); // 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 for random display order const featured = shuffleArray(nonHalloweenSubmissions.filter(app => app.isFeatured)); const approved = shuffleArray(nonHalloweenSubmissions.filter(app => app.isApproved && !app.isFeatured)); return { templateApps: templates, halloweenApps: halloween, featuredApps: featured, approvedApps: approved, }; }, [submissions]); // Only depend on submissions, not intermediate filtered arrays // Don't show showcase if disabled in settings if (!config.showcaseEnabled) { return null; } // 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) => ( ))}
)}
); }