Implement app showcase on New Project view

- Add useAppSubmissions hook to query Nostr events (kind 31733)
- Create AppShowcaseCard component for displaying individual apps
- Add AppShowcase component with search, filtering, and categorization
- Include featured apps, Halloween hackathon apps, templates, and approved apps sections
- Add shuffleArray utility function for randomizing app display order
- Integrate showcase into Index page underneath the prompt text box
- Support moderation controls for authorized users
- Add responsive design with mobile-friendly tag filtering
- Include empty states with relay selector for no results
This commit is contained in:
shakespeare.diy committed 2025-10-12 18:45:59 -05:00
1 parent fe45508297
commit 13a197e80d
5 files changed
+1385

No files matched your search

+447
View File
@@ -0,0 +1,447 @@
import React, { useState, useMemo, useEffect } from "react";
import { Plus, Search, Filter, Eye, EyeOff } from "lucide-react";
import { Button } from "@/components/ui/button";
import { Badge } from "@/components/ui/badge";
import { Input } from "@/components/ui/input";
import { useCurrentUser } from "@/hooks/useCurrentUser";
import { useAppSubmissions } from "@/hooks/useAppSubmissions";
import { AppShowcaseCard } from "@/components/AppShowcaseCard";
import { useIsMobile } from "@/hooks/useIsMobile";
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 isMobile = useIsMobile();
const [searchTerm, setSearchTerm] = useState("");
const [selectedTag, setSelectedTag] = useState<string | null>(null);
const [showAllApps, setShowAllApps] = useState(false);
const [showAllTags, setShowAllTags] = 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]
);
// Apply search and tag filters
const filterApps = (apps: AppSubmission[]) => {
return apps.filter(app => {
const matchesSearch = !searchTerm ||
app.appName.toLowerCase().includes(searchTerm.toLowerCase()) ||
app.description.toLowerCase().includes(searchTerm.toLowerCase()) ||
app.appTags.some(tag => tag.toLowerCase().includes(searchTerm.toLowerCase()));
const matchesTag = !selectedTag || app.appTags.includes(selectedTag);
return matchesSearch && matchesTag;
});
};
const filteredFeaturedApps = filterApps(featuredApps);
const filteredHalloweenApps = filterApps(halloweenApps);
const filteredApprovedApps = filterApps(approvedApps);
const filteredTemplateApps = filterApps(templateApps);
// Get all unique tags from approved and featured apps only (exclude pending, hidden, and template apps)
const allTags = Array.from(new Set([...featuredApps, ...approvedApps].flatMap(app => app.appTags))).sort();
// Get the most popular tags based on frequency (excluding Halloween Hackathon 2025 tag)
const tagCounts = new Map<string, number>();
[...featuredApps, ...approvedApps, ...templateApps].forEach(app => {
app.appTags.forEach(tag => {
// Don't include Halloween Hackathon 2025 in the tag filters
if (tag !== 'Halloween Hackathon 2025') {
tagCounts.set(tag, (tagCounts.get(tag) || 0) + 1);
}
});
});
const sortedTags = Array.from(tagCounts.entries())
.sort((a, b) => b[1] - a[1]) // Sort by count descending
.map(([tag]) => tag); // Extract just the tag names
// Always show Template as the first tag if templates exist
const topTags: string[] = [];
if (templateApps.length > 0) {
topTags.push('Template');
// Remove Template from sortedTags to avoid duplication
const templateIndex = sortedTags.indexOf('Template');
if (templateIndex > -1) {
sortedTags.splice(templateIndex, 1);
}
}
// Show fewer tags on mobile, more on desktop
const maxTagsToShow = isMobile ? 3 : 5;
const availableSlots = maxTagsToShow - topTags.length;
const popularTags = [...topTags, ...sortedTags.slice(0, availableSlots)];
const remainingTags = sortedTags.slice(availableSlots);
const handleTagSelect = (tag: string | null) => {
setSelectedTag(tag);
};
// Don't show showcase if no apps exist
if (isLoading) {
return (
<div className="mt-16 max-w-4xl mx-auto">
<div className="text-center mb-8">
<h2 className="text-2xl md:text-3xl font-bold mb-4">Community Showcase</h2>
<p className="text-muted-foreground mb-6">
Discover amazing applications built by our community
</p>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{Array.from({ length: 6 }).map((_, i) => (
<Card key={i} className="h-full flex flex-col">
<Skeleton className="aspect-video rounded-t-lg" />
<CardContent className="p-6 flex flex-col flex-1">
<div className="flex items-center gap-3 mb-3">
<Skeleton className="w-12 h-12 rounded-lg" />
<div className="space-y-2">
<Skeleton className="h-4 w-32" />
<Skeleton className="h-3 w-24" />
</div>
</div>
<div className="space-y-2 mb-4">
<Skeleton className="h-4 w-full" />
<Skeleton className="h-4 w-4/5" />
</div>
<div className="flex gap-1 mb-4">
<Skeleton className="h-5 w-16" />
<Skeleton className="h-5 w-20" />
</div>
<div className="mt-auto flex gap-2">
<Skeleton className="h-6 flex-1" />
<Skeleton className="h-8 w-8" />
<Skeleton className="h-8 w-8" />
</div>
</CardContent>
</Card>
))}
</div>
</div>
);
}
if (!submissions.length) {
return (
<div className="mt-16 max-w-4xl mx-auto">
<div className="text-center mb-8">
<h2 className="text-2xl md:text-3xl font-bold mb-4">Community Showcase</h2>
<p className="text-muted-foreground mb-6">
Discover amazing applications built by our community
</p>
</div>
<Card className="border-dashed">
<CardContent className="py-12 px-8 text-center">
<div className="max-w-sm mx-auto space-y-6">
<p className="text-muted-foreground">
No apps found. Try another relay?
</p>
<RelaySelector className="w-full" />
</div>
</CardContent>
</Card>
</div>
);
}
return (
<div className="mt-16 max-w-4xl mx-auto">
{/* Header */}
<div className="text-center mb-8">
<h2 className="text-2xl md:text-3xl font-bold mb-4">Community Showcase</h2>
<p className="text-muted-foreground mb-6">
Discover amazing applications built by our community
</p>
{/* Search and Filter */}
<div className="space-y-4">
<div className="relative max-w-md mx-auto">
<Search className="absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400 w-4 h-4" />
<Input
placeholder="Search apps..."
value={searchTerm}
onChange={(e) => setSearchTerm(e.target.value)}
className="pl-10"
/>
</div>
{/* Tag Filters */}
<div className="space-y-3">
<div className="flex flex-wrap gap-2 justify-center">
<Button
variant={selectedTag ? "outline" : "default"}
size="sm"
onClick={() => handleTagSelect(null)}
className="shrink-0"
>
All Tags
</Button>
{popularTags.map((tag) => (
<Button
key={tag}
variant={selectedTag === tag ? "default" : "outline"}
size="sm"
onClick={() => handleTagSelect(selectedTag === tag ? null : tag)}
className="shrink-0"
>
{tag === 'Template' ? 'Templates' : tag}
</Button>
))}
{/* Show More Tags Button */}
{remainingTags.length > 0 && (
<Button
variant="ghost"
size="sm"
onClick={() => setShowAllTags(!showAllTags)}
className="shrink-0 text-primary hover:text-primary/80"
>
{showAllTags ? 'Show Less' : `+${remainingTags.length} More`}
</Button>
)}
</div>
{/* Additional Tags (Collapsible) */}
{showAllTags && remainingTags.length > 0 && (
<div className="flex flex-wrap gap-2 pt-2 border-t border-gray-200 justify-center">
{remainingTags.map((tag) => (
<Button
key={tag}
variant={selectedTag === tag ? "default" : "outline"}
size="sm"
onClick={() => handleTagSelect(selectedTag === tag ? null : tag)}
className="shrink-0"
>
{tag === 'Template' ? 'Templates' : tag}
</Button>
))}
</div>
)}
</div>
</div>
</div>
{/* Apps Grid */}
<div className="space-y-12">
{/* When Template tag is selected, show only Templates */}
{selectedTag === 'Template' ? (
<>
{/* Templates Section */}
{filteredTemplateApps.length > 0 && (
<div>
<div className="flex items-center gap-3 mb-6">
<div className="w-8 h-8 bg-purple-100 rounded-lg flex items-center justify-center">
<span className="text-sm">📋</span>
</div>
<div>
<h3 className="text-xl font-bold text-gray-900">Templates</h3>
<p className="text-sm text-gray-600">Ready-to-use templates to kickstart your project</p>
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredTemplateApps.slice(0, 6).map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
showModerationControls={isModerator}
hideApprovalStatus={true}
/>
))}
</div>
</div>
)}
</>
) : (
<>
{/* Featured Apps */}
{filteredFeaturedApps.length > 0 && (
<div>
<div className="flex items-center gap-3 mb-6">
<div className="w-8 h-8 bg-yellow-100 rounded-lg flex items-center justify-center">
<span className="text-sm">⭐</span>
</div>
<div>
<h3 className="text-xl font-bold text-gray-900">Featured Apps</h3>
<p className="text-sm text-gray-600">Handpicked applications showcasing the best of our community</p>
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredFeaturedApps.slice(0, 6).map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
showModerationControls={isModerator}
hideApprovalStatus={true}
/>
))}
</div>
</div>
)}
{/* Halloween Hackathon 2025 Apps */}
{filteredHalloweenApps.length > 0 && (
<div>
<div className="flex items-center gap-3 mb-6">
<div className="w-8 h-8 bg-orange-100 rounded-lg flex items-center justify-center">
<span className="text-sm">🎃</span>
</div>
<div>
<h3 className="text-xl font-bold text-gray-900">Halloween Hackathon 2025</h3>
<p className="text-sm text-gray-600">Featured spooky creations from our Halloween hackathon</p>
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredHalloweenApps.slice(0, 6).map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
showModerationControls={isModerator}
hideApprovalStatus={true}
/>
))}
</div>
</div>
)}
{/* All Apps (Approved) - Collapsible */}
{filteredApprovedApps.length > 0 && (
<div>
<Collapsible open={showAllApps} onOpenChange={setShowAllApps}>
<CollapsibleTrigger asChild>
<Button variant="ghost" className="p-0 h-auto mb-6 hover:bg-transparent">
<div className="flex items-center gap-3">
<div className="w-8 h-8 bg-blue-100 rounded-lg flex items-center justify-center">
<span className="text-sm">📱</span>
</div>
<div className="text-left">
<h3 className="text-xl font-bold text-gray-900">
All Apps ({filteredApprovedApps.length})
</h3>
<p className="text-sm text-gray-600">
{showAllApps ? 'Click to collapse' : 'Click to view all approved community apps'}
</p>
</div>
</div>
</Button>
</CollapsibleTrigger>
<CollapsibleContent>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredApprovedApps.map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
showModerationControls={isModerator}
hideApprovalStatus={true}
/>
))}
</div>
</CollapsibleContent>
</Collapsible>
</div>
)}
{/* Templates Section */}
{filteredTemplateApps.length > 0 && (
<div>
<div className="flex items-center gap-3 mb-6">
<div className="w-8 h-8 bg-purple-100 rounded-lg flex items-center justify-center">
<span className="text-sm">📋</span>
</div>
<div>
<h3 className="text-xl font-bold text-gray-900">Templates</h3>
<p className="text-sm text-gray-600">Ready-to-use templates to kickstart your project</p>
</div>
</div>
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
{filteredTemplateApps.slice(0, 6).map((app) => (
<AppShowcaseCard
key={app.id}
app={app}
showModerationControls={isModerator}
hideApprovalStatus={true}
/>
))}
</div>
</div>
)}
</>
)}
{/* Empty State */}
{(() => {
if (selectedTag === 'Template') {
return filteredTemplateApps.length === 0;
}
return filteredFeaturedApps.length === 0 && filteredHalloweenApps.length === 0 && filteredApprovedApps.length === 0 && filteredTemplateApps.length === 0;
})() && (
<div className="text-center py-12">
<div className="w-16 h-16 bg-gray-100 rounded-2xl flex items-center justify-center mx-auto mb-6">
<Search className="w-8 h-8 text-gray-400" />
</div>
<h3 className="text-xl font-semibold text-gray-900 mb-2">
{selectedTag === 'Template' ? 'No templates found' : 'No apps found'}
</h3>
<p className="text-gray-600 mb-6">
{searchTerm || selectedTag
? "Try adjusting your search or filters"
: "Be the first to submit an app to the showcase!"
}
</p>
</div>
)}
</div>
</div>
);
}
+657
View File
@@ -0,0 +1,657 @@
import React, { useState } from 'react';
import { Badge } from '@/components/ui/badge';
import { Button } from '@/components/ui/button';
import { Card, CardContent } from '@/components/ui/card';
import {
ExternalLink,
GitBranch,
Edit,
Star,
StarOff,
Eye,
EyeOff,
MoreVertical,
CheckCircle,
XCircle,
User,
Home,
Contact,
Copy
} from 'lucide-react';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
import type { AppSubmission } from '@/hooks/useAppSubmissions';
import { useCurrentUser } from '@/hooks/useCurrentUser';
import { useNostrPublish } from '@/hooks/useNostrPublish';
import { useNostr } from '@nostrify/react';
import { useAuthor } from '@/hooks/useAuthor';
import { nip19 } from 'nostr-tools';
import { useToast } from '@/hooks/useToast';
import { useQueryClient } from '@tanstack/react-query';
interface AppShowcaseCardProps {
app: AppSubmission;
onEdit?: (app: AppSubmission) => void;
showModerationControls?: boolean;
hideApprovalStatus?: boolean; // Hide pending/approval badges
}
export function AppShowcaseCard({ app, onEdit, showModerationControls, hideApprovalStatus }: AppShowcaseCardProps) {
const { user } = useCurrentUser();
const { nostr } = useNostr();
const { mutate: publishEvent, isPending } = useNostrPublish();
const queryClient = useQueryClient();
const [imageError, setImageError] = useState(false);
const { toast } = useToast();
// Get author pubkey from authorNpub field
const authorPubkey = React.useMemo(() => {
if (!app.authorNpub) return app.pubkey; // Fallback to event pubkey
try {
// If it's already a hex key, use it directly
if (app.authorNpub.length === 64 && /^[0-9a-f]+$/i.test(app.authorNpub)) {
return app.authorNpub;
}
// Otherwise try to decode as npub
const decoded = nip19.decode(app.authorNpub);
return decoded.type === 'npub' ? decoded.data : app.pubkey;
} catch {
return app.pubkey; // Fallback to event pubkey if decode fails
}
}, [app.authorNpub, app.pubkey]);
const { data: authorData } = useAuthor(authorPubkey);
const isOwner = user?.pubkey === app.pubkey;
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;
// Check if this is a Halloween submission by looking for Halloween tags
const isHalloweenSubmission = app.appTags.includes('Halloween Hackathon 2025');
// Get contact info from Halloween submissions (these have lightning/email tags)
const getContactInfo = () => {
if (!isHalloweenSubmission) return null;
// Look for lightning and email tags in the event tags
const lightningTag = app.tags?.find((tag: string[]) => tag[0] === 'lightning')?.[1];
const emailTag = app.tags?.find((tag: string[]) => tag[0] === 'email')?.[1];
return { lightning: lightningTag, email: emailTag };
};
const handleCopyContactInfo = () => {
const contactInfo = getContactInfo();
if (!contactInfo) return;
const info: string[] = [];
if (contactInfo.lightning) info.push(`Lightning: ${contactInfo.lightning}`);
if (contactInfo.email) info.push(`Email: ${contactInfo.email}`);
const textToCopy = info.join('\n');
navigator.clipboard.writeText(textToCopy);
toast({
title: 'Contact Info Copied!',
description: `Copied ${info.length} contact method(s) to clipboard`
});
};
const handleModerationAction = async (action: 'feature' | 'unfeature' | 'approve' | 'unapprove' | 'hide' | 'unhide' | 'homepage' | 'unhomepage') => {
if (!isModerator || !user) return;
const dTag = app.tags.find(tag => tag[0] === 'd')?.[1];
if (!dTag) {
toast({
title: 'Error',
description: 'Cannot perform moderation action: missing app identifier',
variant: 'destructive'
});
return;
}
const appCoordinate = `${app.kind}:${app.pubkey}:${dTag}`;
try {
if (action === 'homepage' || action === 'unhomepage') {
// Get current homepage apps list
const currentHomepageLists = await nostr.query([{
kinds: [30267],
authors: [MODERATOR_HEX],
'#d': ['soapbox-homepage-apps'],
limit: 1
}]);
const currentHomepageList = currentHomepageLists.reduce((latest: any, current: any) =>
!latest || current.created_at > latest.created_at ? current : latest,
null
);
// Get current homepage app coordinates
const currentHomepageApps = new Set<string>();
if (currentHomepageList) {
currentHomepageList.tags
.filter(tag => tag[0] === 'a')
.forEach(tag => currentHomepageApps.add(tag[1]));
}
// Update the homepage set
if (action === 'homepage') {
currentHomepageApps.add(appCoordinate);
} else {
currentHomepageApps.delete(appCoordinate);
}
// Publish updated homepage apps list
publishEvent({
kind: 30267,
content: 'Soapbox homepage apps curated by moderators',
tags: [
['d', 'soapbox-homepage-apps'],
['title', 'Soapbox Homepage Apps'],
['description', 'Apps displayed on the Soapbox homepage'],
...Array.from(currentHomepageApps).map(coord => ['a', coord])
],
created_at: Math.floor(Date.now() / 1000)
});
// If adding to homepage, also ensure it's approved
if (action === 'homepage') {
// Get current approved apps list
const currentApprovedLists = await nostr.query([{
kinds: [30267],
authors: [MODERATOR_HEX],
'#d': ['soapbox-approved-apps'],
limit: 1
}]);
const currentApprovedList = currentApprovedLists.reduce((latest: any, current: any) =>
!latest || current.created_at > latest.created_at ? current : latest,
null
);
// Get current approved app coordinates
const currentApprovedApps = new Set<string>();
if (currentApprovedList) {
currentApprovedList.tags
.filter(tag => tag[0] === 'a')
.forEach(tag => currentApprovedApps.add(tag[1]));
}
// Add to approved list if not already there
currentApprovedApps.add(appCoordinate);
// Publish updated approved apps list
publishEvent({
kind: 30267,
content: 'Soapbox approved apps curated by moderators',
tags: [
['d', 'soapbox-approved-apps'],
['title', 'Soapbox Approved Apps'],
['description', 'Apps approved for the Soapbox showcase'],
...Array.from(currentApprovedApps).map(coord => ['a', coord])
],
created_at: Math.floor(Date.now() / 1000)
});
}
} else if (action === 'feature' || action === 'unfeature') {
// Get current featured apps list
const currentFeaturedLists = await nostr.query([{
kinds: [30267],
authors: [MODERATOR_HEX],
'#d': ['soapbox-featured-apps'],
limit: 1
}]);
const currentFeaturedList = currentFeaturedLists.reduce((latest: any, current: any) =>
!latest || current.created_at > latest.created_at ? current : latest,
null
);
// Get current featured app coordinates
const currentFeaturedApps = new Set<string>();
if (currentFeaturedList) {
currentFeaturedList.tags
.filter(tag => tag[0] === 'a')
.forEach(tag => currentFeaturedApps.add(tag[1]));
}
// Update the featured set
if (action === 'feature') {
currentFeaturedApps.add(appCoordinate);
} else {
currentFeaturedApps.delete(appCoordinate);
}
// Publish updated featured apps list
publishEvent({
kind: 30267,
content: 'Soapbox featured apps curated by moderators',
tags: [
['d', 'soapbox-featured-apps'],
['title', 'Soapbox Featured Apps'],
['description', 'Apps featured in the Soapbox showcase'],
...Array.from(currentFeaturedApps).map(coord => ['a', coord])
],
created_at: Math.floor(Date.now() / 1000)
});
// If featuring an app, also ensure it's approved
if (action === 'feature') {
// Get current approved apps list
const currentApprovedLists = await nostr.query([{
kinds: [30267],
authors: [MODERATOR_HEX],
'#d': ['soapbox-approved-apps'],
limit: 1
}]);
const currentApprovedList = currentApprovedLists.reduce((latest: any, current: any) =>
!latest || current.created_at > latest.created_at ? current : latest,
null
);
// Get current approved app coordinates
const currentApprovedApps = new Set<string>();
if (currentApprovedList) {
currentApprovedList.tags
.filter(tag => tag[0] === 'a')
.forEach(tag => currentApprovedApps.add(tag[1]));
}
// Add to approved list if not already there
currentApprovedApps.add(appCoordinate);
// Publish updated approved apps list
publishEvent({
kind: 30267,
content: 'Soapbox approved apps curated by moderators',
tags: [
['d', 'soapbox-approved-apps'],
['title', 'Soapbox Approved Apps'],
['description', 'Apps approved for the Soapbox showcase'],
...Array.from(currentApprovedApps).map(coord => ['a', coord])
],
created_at: Math.floor(Date.now() / 1000)
});
}
} else if (action === 'approve' || action === 'unapprove') {
// Get current approved apps list
const currentApprovedLists = await nostr.query([{
kinds: [30267],
authors: [MODERATOR_HEX],
'#d': ['soapbox-approved-apps'],
limit: 1
}]);
const currentApprovedList = currentApprovedLists.reduce((latest: any, current: any) =>
!latest || current.created_at > latest.created_at ? current : latest,
null
);
// Get current approved app coordinates
const currentApprovedApps = new Set<string>();
if (currentApprovedList) {
currentApprovedList.tags
.filter(tag => tag[0] === 'a')
.forEach(tag => currentApprovedApps.add(tag[1]));
}
// Update the approved set
if (action === 'approve') {
currentApprovedApps.add(appCoordinate);
} else {
currentApprovedApps.delete(appCoordinate);
}
// Publish updated approved apps list
publishEvent({
kind: 30267,
content: 'Soapbox approved apps curated by moderators',
tags: [
['d', 'soapbox-approved-apps'],
['title', 'Soapbox Approved Apps'],
['description', 'Apps approved for the Soapbox showcase'],
...Array.from(currentApprovedApps).map(coord => ['a', coord])
],
created_at: Math.floor(Date.now() / 1000)
});
} else if (action === 'hide' || action === 'unhide') {
// Create NIP-56 report event
publishEvent({
kind: 1984,
content: `App ${action}den by moderator: "${app.appName}"`,
tags: [
['a', appCoordinate, action === 'hide' ? 'spam' : 'other'],
['p', app.pubkey],
['L', 'soapbox.moderation'],
['l', action === 'hide' ? 'hidden' : 'unhidden', 'soapbox.moderation']
],
created_at: Math.floor(Date.now() / 1000)
});
}
// Invalidate queries to refresh the data
queryClient.invalidateQueries({ queryKey: ['app-submissions'] });
// If this is a Halloween app, also invalidate Halloween queries
if (isHalloweenSubmission) {
queryClient.invalidateQueries({ queryKey: ['halloween-submissions'] });
queryClient.invalidateQueries({ queryKey: ['halloween-submissions-with-contacts'] });
}
toast({
title: 'Success!',
description: `App "${app.appName}" ${action}d successfully`
});
} catch (error) {
console.error('Moderation action failed:', error);
toast({
title: 'Error',
description: `Failed to ${action} app "${app.appName}"`,
variant: 'destructive'
});
}
};
return (
<Card className="group hover:shadow-lg transition-all duration-300 hover:border-primary/20 h-full flex flex-col">
<div className="relative">
{/* App Screenshot */}
<a
href={app.websiteUrl}
target="_blank"
rel="noopener noreferrer"
className="block aspect-video bg-gradient-to-br from-gray-50 to-gray-100 rounded-t-lg overflow-hidden cursor-pointer"
>
{!imageError ? (
<img
src={app.screenshotUrl}
alt={`${app.appName} screenshot`}
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
onError={() => setImageError(true)}
/>
) : (
<div className="w-full h-full flex items-center justify-center text-gray-400">
<div className="text-center">
<div className="w-16 h-16 mx-auto mb-2 bg-gray-200 rounded-lg flex items-center justify-center">
<ExternalLink className="w-8 h-8" />
</div>
<p className="text-sm">Screenshot unavailable</p>
</div>
</div>
)}
</a>
{/* Status Badges */}
<div className="absolute top-3 left-3 flex flex-col gap-1">
{app.isFeatured && (
<Badge className="bg-yellow-500 text-yellow-50">
<Star className="w-3 h-3 mr-1" />
Featured
</Badge>
)}
{app.isHomepage && isModerator && (
<Badge className="bg-blue-500 text-blue-50">
<Home className="w-3 h-3 mr-1" />
Homepage
</Badge>
)}
{!app.isApproved && !hideApprovalStatus && (
<Badge variant="secondary" className="bg-orange-100 text-orange-700 border-orange-200">
<span className="w-2 h-2 bg-orange-500 rounded-full mr-1"></span>
Pending
</Badge>
)}
</div>
{/* Actions Menu */}
{(isOwner || showModerationControls) && (
<div className="absolute top-3 right-3">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="secondary" size="sm" className="h-8 w-8 p-0">
<MoreVertical className="w-4 h-4" />
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{isOwner && (
<DropdownMenuItem onClick={() => onEdit?.(app)}>
<Edit className="w-4 h-4 mr-2" />
Edit App
</DropdownMenuItem>
)}
{showModerationControls && isModerator && (
<>
{isHalloweenSubmission && getContactInfo() && (getContactInfo()?.lightning || getContactInfo()?.email) && (
<DropdownMenuItem
onClick={handleCopyContactInfo}
>
<Contact className="w-4 h-4 mr-2" />
View Contact Info
</DropdownMenuItem>
)}
{!app.isApproved && (
<DropdownMenuItem
onClick={() => handleModerationAction('approve')}
disabled={isPending}
>
<CheckCircle className="w-4 h-4 mr-2" />
Approve
</DropdownMenuItem>
)}
{app.isApproved && !app.isFeatured && (
<DropdownMenuItem
onClick={() => handleModerationAction('unapprove')}
disabled={isPending}
>
<XCircle className="w-4 h-4 mr-2" />
Unapprove
</DropdownMenuItem>
)}
<DropdownMenuItem
onClick={() => handleModerationAction(app.isFeatured ? 'unfeature' : 'feature')}
disabled={isPending}
>
{app.isFeatured ? (
<>
<StarOff className="w-4 h-4 mr-2" />
Un-feature
</>
) : (
<>
<Star className="w-4 h-4 mr-2" />
Feature
</>
)}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleModerationAction(app.isHomepage ? 'unhomepage' : 'homepage')}
disabled={isPending}
>
{app.isHomepage ? (
<>
<Home className="w-4 h-4 mr-2" />
Remove from Homepage
</>
) : (
<>
<Home className="w-4 h-4 mr-2" />
Add to Homepage
</>
)}
</DropdownMenuItem>
<DropdownMenuItem
onClick={() => handleModerationAction(app.isHidden ? 'unhide' : 'hide')}
disabled={isPending}
>
{app.isHidden ? (
<>
<Eye className="w-4 h-4 mr-2" />
Unhide
</>
) : (
<>
<EyeOff className="w-4 h-4 mr-2" />
Hide
</>
)}
</DropdownMenuItem>
</>
)}
</DropdownMenuContent>
</DropdownMenu>
</div>
)}
</div>
<CardContent className="p-6 flex flex-col flex-1">
<div className="flex items-start justify-between mb-3">
<div className="flex items-center gap-3">
{/* App Icon */}
<div className="w-12 h-12 rounded-lg overflow-hidden bg-gray-100 flex-shrink-0">
<img
src={app.appIconUrl}
alt={`${app.appName} icon`}
className="w-full h-full object-cover"
onError={(e) => {
const target = e.target as HTMLImageElement;
target.style.display = 'none';
}}
/>
</div>
<div>
<h3 className="text-xl font-semibold text-gray-900 mb-1" title={app.appName}>
{app.appName.length > 50 ? `${app.appName.slice(0, 50)}...` : app.appName}
</h3>
</div>
</div>
</div>
<p className="text-gray-600 mb-3 line-clamp-3">{app.description}</p>
{/* Author Information */}
<div className="flex items-center gap-2 mb-4">
<div className="w-6 h-6 rounded-full overflow-hidden bg-gray-100 flex-shrink-0">
{authorData?.metadata?.picture ? (
<img
src={authorData.metadata.picture}
alt={`${authorData.metadata.name || 'Author'} avatar`}
className="w-full h-full object-cover"
onError={(e) => {
const target = e.target as HTMLImageElement;
target.style.display = 'none';
target.parentElement!.innerHTML = '<div class="w-full h-full flex items-center justify-center"><svg class="w-3 h-3 text-gray-400" fill="currentColor" viewBox="0 0 20 20"><path fill-rule="evenodd" d="M10 9a3 3 0 100-6 3 3 0 000 6zm-7 9a7 7 0 1114 0H3z" clip-rule="evenodd"></path></svg></div>';
}}
/>
) : (
<div className="w-full h-full flex items-center justify-center">
<User className="w-3 h-3 text-gray-400" />
</div>
)}
</div>
<span className="text-sm text-gray-600">
by{' '}
<a
href={`https://ditto.pub/${app.authorNpub || nip19.npubEncode(authorPubkey)}`}
target="_blank"
rel="noopener noreferrer"
className="text-primary hover:text-primary/80 transition-colors hover:underline"
>
{authorData?.metadata?.name || authorData?.metadata?.display_name || 'Anonymous'}
</a>
</span>
</div>
{/* Tags */}
{app.appTags.length > 0 && (
<div className="flex flex-wrap gap-1 mb-4">
{app.appTags.slice(0, 3).map((tag) => (
<Badge key={tag} variant="secondary" className="text-xs">
{tag}
</Badge>
))}
{app.appTags.length > 3 && (
<Badge variant="secondary" className="text-xs">
+{app.appTags.length - 3} more
</Badge>
)}
</div>
)}
{/* Spacer to push action links to bottom */}
<div className="flex-1"></div>
{/* Action Links */}
<div className="flex items-center gap-2 mt-auto">
<a
href={`https://shakespeare.diy/clone?url=${encodeURIComponent(app.repositoryUrl)}`}
target="_blank"
rel="noopener noreferrer"
className="flex-1"
>
<img
src="https://shakespeare.diy/badge.svg"
alt="Edit with Shakespeare"
className="h-6 hover:opacity-80 transition-opacity"
/>
</a>
<Button variant="outline" size="sm" asChild>
<a
href={app.websiteUrl}
target="_blank"
rel="noopener noreferrer"
title="Visit app"
>
<ExternalLink className="w-4 h-4" />
</a>
</Button>
{app.repositoryUrl.startsWith('nostr://') ? (
<Button
variant="outline"
size="sm"
onClick={() => {
navigator.clipboard.writeText(app.repositoryUrl);
toast({
title: 'Copied!',
description: 'Nostr git URL copied to clipboard'
});
}}
title="Copy Nostr git URL"
>
<GitBranch className="w-4 h-4" />
</Button>
) : (
<Button variant="outline" size="sm" asChild>
<a
href={app.repositoryUrl}
target="_blank"
rel="noopener noreferrer"
title="View repository"
>
<GitBranch className="w-4 h-4" />
</a>
</Button>
)}
</div>
</CardContent>
</Card>
);
}