mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-06 08:37:22 +00:00
Merge branch 'main' into 'main'
Implement app showcase on New Project view See merge request soapbox-pub/shakespeare!56
This commit is contained in:
commit
3de4b3771d
5 files changed
+1110
No files matched your search
@@ -0,0 +1,240 @@
|
|||||||
|
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 (
|
||||||
|
<div className="mt-16 max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
<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-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
<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-7xl mx-auto px-4 sm:px-6 lg:px-8">
|
||||||
|
{/* Apps Grid */}
|
||||||
|
<div className="space-y-12">
|
||||||
|
{/* Featured Apps */}
|
||||||
|
{featuredApps.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">
|
||||||
|
{featuredApps.slice(0, 6).map((app) => (
|
||||||
|
<AppShowcaseCard
|
||||||
|
key={app.id}
|
||||||
|
app={app}
|
||||||
|
showModerationControls={isModerator}
|
||||||
|
hideApprovalStatus={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Halloween Hackathon 2025 Apps */}
|
||||||
|
{halloweenApps.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">
|
||||||
|
{halloweenApps.slice(0, 6).map((app) => (
|
||||||
|
<AppShowcaseCard
|
||||||
|
key={app.id}
|
||||||
|
app={app}
|
||||||
|
showModerationControls={isModerator}
|
||||||
|
hideApprovalStatus={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* Templates Section */}
|
||||||
|
{templateApps.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">
|
||||||
|
{templateApps.slice(0, 6).map((app) => (
|
||||||
|
<AppShowcaseCard
|
||||||
|
key={app.id}
|
||||||
|
app={app}
|
||||||
|
showModerationControls={isModerator}
|
||||||
|
hideApprovalStatus={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
|
||||||
|
{/* More Apps (Approved) - Collapsible */}
|
||||||
|
{approvedApps.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">
|
||||||
|
More Apps ({approvedApps.length})
|
||||||
|
</h3>
|
||||||
|
<p className="text-sm text-gray-600">
|
||||||
|
{showAllApps ? 'Click to collapse' : 'Click to view more community apps'}
|
||||||
|
</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</Button>
|
||||||
|
</CollapsibleTrigger>
|
||||||
|
<CollapsibleContent>
|
||||||
|
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||||
|
{approvedApps.map((app) => (
|
||||||
|
<AppShowcaseCard
|
||||||
|
key={app.id}
|
||||||
|
app={app}
|
||||||
|
showModerationControls={isModerator}
|
||||||
|
hideApprovalStatus={true}
|
||||||
|
/>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
</CollapsibleContent>
|
||||||
|
</Collapsible>
|
||||||
|
</div>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,589 @@
|
|||||||
|
import React, { useState } from 'react';
|
||||||
|
import { Button } from '@/components/ui/button';
|
||||||
|
import { Card, CardContent } from '@/components/ui/card';
|
||||||
|
import {
|
||||||
|
ExternalLink,
|
||||||
|
Edit,
|
||||||
|
Star,
|
||||||
|
StarOff,
|
||||||
|
Eye,
|
||||||
|
EyeOff,
|
||||||
|
MoreVertical,
|
||||||
|
CheckCircle,
|
||||||
|
XCircle,
|
||||||
|
User,
|
||||||
|
Home,
|
||||||
|
Contact
|
||||||
|
} 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>
|
||||||
|
|
||||||
|
{/* 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>
|
||||||
|
|
||||||
|
{/* 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>
|
||||||
|
</div>
|
||||||
|
</CardContent>
|
||||||
|
</Card>
|
||||||
|
);
|
||||||
|
}
|
||||||
@@ -0,0 +1,265 @@
|
|||||||
|
import { useNostr } from '@nostrify/react';
|
||||||
|
import { useQuery } from '@tanstack/react-query';
|
||||||
|
import { nip19 } from 'nostr-tools';
|
||||||
|
import type { NostrEvent } from '@nostrify/nostrify';
|
||||||
|
|
||||||
|
// Kind 31733 for app submissions (addressable events)
|
||||||
|
const APP_SUBMISSION_KIND = 31733;
|
||||||
|
|
||||||
|
// The moderator npub and hex
|
||||||
|
const MODERATOR_NPUB = 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc';
|
||||||
|
const MODERATOR_HEX = (() => {
|
||||||
|
try {
|
||||||
|
const decoded = nip19.decode(MODERATOR_NPUB);
|
||||||
|
return decoded.type === 'npub' ? decoded.data : '';
|
||||||
|
} catch {
|
||||||
|
return '';
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
// Soapbox team follow pack naddr (same as used on About page)
|
||||||
|
const SOAPBOX_TEAM_NADDR = 'naddr1qvzqqqyckypzpyexz3t34l966ngh5xg7u2q788hthdqmj0av3lv8s2tz9t43zt6dqqxxkdrsx4mnqm3jxfeh2ess5pyrw';
|
||||||
|
|
||||||
|
export interface AppSubmission extends NostrEvent {
|
||||||
|
appName: string;
|
||||||
|
websiteUrl: string;
|
||||||
|
repositoryUrl: string;
|
||||||
|
description: string;
|
||||||
|
appIconUrl: string;
|
||||||
|
screenshotUrl: string;
|
||||||
|
appTags: string[];
|
||||||
|
authorNpub: string;
|
||||||
|
isFeatured: boolean;
|
||||||
|
isApproved: boolean;
|
||||||
|
isHidden: boolean;
|
||||||
|
isHomepage: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useAppSubmissions() {
|
||||||
|
const { nostr } = useNostr();
|
||||||
|
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ['app-submissions'],
|
||||||
|
queryFn: async (): Promise<AppSubmission[]> => {
|
||||||
|
// Get Soapbox team follow pack for auto-approval
|
||||||
|
let teamPubkeys = new Set<string>();
|
||||||
|
try {
|
||||||
|
const decoded = nip19.decode(SOAPBOX_TEAM_NADDR);
|
||||||
|
if (decoded.type === 'naddr') {
|
||||||
|
const addrData = decoded.data;
|
||||||
|
const teamEvents = await nostr.query([{
|
||||||
|
kinds: [addrData.kind],
|
||||||
|
authors: [addrData.pubkey],
|
||||||
|
'#d': [addrData.identifier],
|
||||||
|
limit: 1
|
||||||
|
}]);
|
||||||
|
|
||||||
|
if (teamEvents.length > 0) {
|
||||||
|
const teamEvent = teamEvents[0];
|
||||||
|
// Extract pubkeys from 'p' tags
|
||||||
|
teamEvent.tags
|
||||||
|
.filter(([name]) => name === 'p')
|
||||||
|
.forEach(([, pubkey]) => {
|
||||||
|
if (pubkey) teamPubkeys.add(pubkey);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to fetch Soapbox team follow pack:', error);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get all app submissions (kind 31733)
|
||||||
|
const submissionEvents = await nostr.query([{
|
||||||
|
kinds: [APP_SUBMISSION_KIND],
|
||||||
|
'#t': ['soapbox-app-submission'],
|
||||||
|
limit: 1000
|
||||||
|
}]);
|
||||||
|
|
||||||
|
// Get featured app lists from moderators (NIP-51 kind 30267)
|
||||||
|
const featuredLists = await nostr.query([{
|
||||||
|
kinds: [30267],
|
||||||
|
authors: [MODERATOR_HEX],
|
||||||
|
'#d': ['soapbox-featured-apps'],
|
||||||
|
limit: 10
|
||||||
|
}]);
|
||||||
|
|
||||||
|
// Get approved app lists from moderators (NIP-51 kind 30267)
|
||||||
|
const approvedLists = await nostr.query([{
|
||||||
|
kinds: [30267],
|
||||||
|
authors: [MODERATOR_HEX],
|
||||||
|
'#d': ['soapbox-approved-apps'],
|
||||||
|
limit: 10
|
||||||
|
}]);
|
||||||
|
|
||||||
|
// Get homepage app lists from moderators (NIP-51 kind 30267)
|
||||||
|
const homepageLists = await nostr.query([{
|
||||||
|
kinds: [30267],
|
||||||
|
authors: [MODERATOR_HEX],
|
||||||
|
'#d': ['soapbox-homepage-apps'],
|
||||||
|
limit: 10
|
||||||
|
}]);
|
||||||
|
|
||||||
|
// Get reporting events for hidden apps (NIP-56 kind 1984)
|
||||||
|
const reportEvents = await nostr.query([{
|
||||||
|
kinds: [1984],
|
||||||
|
authors: [MODERATOR_HEX],
|
||||||
|
limit: 1000
|
||||||
|
}]);
|
||||||
|
|
||||||
|
// Process submissions and apply moderation
|
||||||
|
const submissions: AppSubmission[] = [];
|
||||||
|
const submissionMap = new Map<string, NostrEvent>();
|
||||||
|
|
||||||
|
// Group regular submissions by d-tag (identifier) to get latest version
|
||||||
|
for (const event of submissionEvents) {
|
||||||
|
const dTag = event.tags.find(tag => tag[0] === 'd')?.[1];
|
||||||
|
if (!dTag) continue;
|
||||||
|
|
||||||
|
const existing = submissionMap.get(dTag);
|
||||||
|
if (!existing || event.created_at > existing.created_at) {
|
||||||
|
submissionMap.set(dTag, event);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get the latest featured list
|
||||||
|
const latestFeaturedList = featuredLists.reduce((latest, current) =>
|
||||||
|
!latest || current.created_at > latest.created_at ? current : latest,
|
||||||
|
null as NostrEvent | null
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get the latest approved list
|
||||||
|
const latestApprovedList = approvedLists.reduce((latest, current) =>
|
||||||
|
!latest || current.created_at > latest.created_at ? current : latest,
|
||||||
|
null as NostrEvent | null
|
||||||
|
);
|
||||||
|
|
||||||
|
// Get the latest homepage list
|
||||||
|
const latestHomepageList = homepageLists.reduce((latest, current) =>
|
||||||
|
!latest || current.created_at > latest.created_at ? current : latest,
|
||||||
|
null as NostrEvent | null
|
||||||
|
);
|
||||||
|
|
||||||
|
// Extract featured app coordinates from the list
|
||||||
|
const featuredAppCoords = new Set<string>();
|
||||||
|
if (latestFeaturedList) {
|
||||||
|
latestFeaturedList.tags
|
||||||
|
.filter(tag => tag[0] === 'a')
|
||||||
|
.forEach(tag => featuredAppCoords.add(tag[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract approved app coordinates from the list
|
||||||
|
const approvedAppCoords = new Set<string>();
|
||||||
|
if (latestApprovedList) {
|
||||||
|
latestApprovedList.tags
|
||||||
|
.filter(tag => tag[0] === 'a')
|
||||||
|
.forEach(tag => approvedAppCoords.add(tag[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Extract homepage app coordinates from the list
|
||||||
|
const homepageAppCoords = new Set<string>();
|
||||||
|
if (latestHomepageList) {
|
||||||
|
latestHomepageList.tags
|
||||||
|
.filter(tag => tag[0] === 'a')
|
||||||
|
.forEach(tag => homepageAppCoords.add(tag[1]));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get hidden app coordinates from reports
|
||||||
|
const hiddenAppCoords = new Set<string>();
|
||||||
|
const appReports = new Map<string, { hidden: number; unhidden: number }>();
|
||||||
|
|
||||||
|
for (const report of reportEvents) {
|
||||||
|
// Look for app coordinate in 'a' tags
|
||||||
|
const aTag = report.tags.find(tag => tag[0] === 'a');
|
||||||
|
if (!aTag || !aTag[1]) continue;
|
||||||
|
|
||||||
|
const appCoord = aTag[1];
|
||||||
|
const reportType = aTag[2];
|
||||||
|
|
||||||
|
// Check if this is a moderation label
|
||||||
|
const moderationLabel = report.tags.find(tag =>
|
||||||
|
tag[0] === 'l' && tag[2] === 'soapbox.moderation'
|
||||||
|
)?.[1];
|
||||||
|
|
||||||
|
if (moderationLabel === 'hidden' && (reportType === 'spam' || reportType === 'other')) {
|
||||||
|
if (!appReports.has(appCoord)) {
|
||||||
|
appReports.set(appCoord, { hidden: 0, unhidden: 0 });
|
||||||
|
}
|
||||||
|
appReports.get(appCoord)!.hidden = Math.max(
|
||||||
|
appReports.get(appCoord)!.hidden,
|
||||||
|
report.created_at
|
||||||
|
);
|
||||||
|
} else if (moderationLabel === 'unhidden' && reportType === 'other') {
|
||||||
|
if (!appReports.has(appCoord)) {
|
||||||
|
appReports.set(appCoord, { hidden: 0, unhidden: 0 });
|
||||||
|
}
|
||||||
|
appReports.get(appCoord)!.unhidden = Math.max(
|
||||||
|
appReports.get(appCoord)!.unhidden,
|
||||||
|
report.created_at
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Determine which apps are currently hidden (latest action wins)
|
||||||
|
for (const [appCoord, reports] of appReports) {
|
||||||
|
if (reports.hidden > reports.unhidden) {
|
||||||
|
hiddenAppCoords.add(appCoord);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert to AppSubmission objects
|
||||||
|
for (const [dTag, event] of submissionMap) {
|
||||||
|
try {
|
||||||
|
const appName = event.tags.find(tag => tag[0] === 'title')?.[1] || '';
|
||||||
|
const websiteUrl = event.tags.find(tag => tag[0] === 'website')?.[1] || '';
|
||||||
|
const repositoryUrl = event.tags.find(tag => tag[0] === 'repository')?.[1] || '';
|
||||||
|
const appIconUrl = event.tags.find(tag => tag[0] === 'icon')?.[1] || '';
|
||||||
|
const screenshotUrl = event.tags.find(tag => tag[0] === 'screenshot')?.[1] || '';
|
||||||
|
const authorNpub = event.tags.find(tag => tag[0] === 'author')?.[1] || event.pubkey;
|
||||||
|
const appTags = event.tags.filter(tag => tag[0] === 'app-tag').map(tag => tag[1]);
|
||||||
|
|
||||||
|
// Check if app is featured, approved, homepage, or hidden
|
||||||
|
const appCoordinate = `${APP_SUBMISSION_KIND}:${event.pubkey}:${dTag}`;
|
||||||
|
const isFeatured = featuredAppCoords.has(appCoordinate);
|
||||||
|
const isHomepage = homepageAppCoords.has(appCoordinate);
|
||||||
|
const isSubmittedByModerator = event.pubkey === MODERATOR_HEX;
|
||||||
|
const isSubmittedByTeamMember = teamPubkeys.has(event.pubkey);
|
||||||
|
const isApproved = approvedAppCoords.has(appCoordinate) || isFeatured || isSubmittedByModerator || isSubmittedByTeamMember;
|
||||||
|
const isHidden = hiddenAppCoords.has(appCoordinate);
|
||||||
|
|
||||||
|
submissions.push({
|
||||||
|
...event,
|
||||||
|
appName,
|
||||||
|
websiteUrl,
|
||||||
|
repositoryUrl,
|
||||||
|
description: event.content,
|
||||||
|
appIconUrl,
|
||||||
|
screenshotUrl,
|
||||||
|
appTags: appTags,
|
||||||
|
authorNpub,
|
||||||
|
isFeatured,
|
||||||
|
isApproved,
|
||||||
|
isHidden,
|
||||||
|
isHomepage
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
console.warn('Failed to parse app submission:', error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return submissions;
|
||||||
|
},
|
||||||
|
staleTime: 30000, // 30 seconds
|
||||||
|
refetchInterval: 60000, // 1 minute
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useUserAppSubmissions(userPubkey?: string) {
|
||||||
|
const { data: allSubmissions, ...rest } = useAppSubmissions();
|
||||||
|
|
||||||
|
const userSubmissions = allSubmissions?.filter(app => app.pubkey === userPubkey) || [];
|
||||||
|
|
||||||
|
return {
|
||||||
|
data: userSubmissions,
|
||||||
|
...rest
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -4,3 +4,15 @@ import { twMerge } from "tailwind-merge"
|
|||||||
export function cn(...inputs: ClassValue[]) {
|
export function cn(...inputs: ClassValue[]) {
|
||||||
return twMerge(clsx(inputs))
|
return twMerge(clsx(inputs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shuffles an array using the Fisher-Yates algorithm
|
||||||
|
*/
|
||||||
|
export function shuffleArray<T>(array: T[]): T[] {
|
||||||
|
const shuffled = [...array];
|
||||||
|
for (let i = shuffled.length - 1; i > 0; i--) {
|
||||||
|
const j = Math.floor(Math.random() * (i + 1));
|
||||||
|
[shuffled[i], shuffled[j]] = [shuffled[j], shuffled[i]];
|
||||||
|
}
|
||||||
|
return shuffled;
|
||||||
|
}
|
||||||
@@ -23,6 +23,7 @@ import { FileAttachment } from '@/components/ui/file-attachment';
|
|||||||
import { ArrowUp } from 'lucide-react';
|
import { ArrowUp } from 'lucide-react';
|
||||||
import { useSeoMeta } from '@unhead/react';
|
import { useSeoMeta } from '@unhead/react';
|
||||||
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
import { ShakespeareLogo } from '@/components/ShakespeareLogo';
|
||||||
|
import { AppShowcase } from '@/components/AppShowcase';
|
||||||
|
|
||||||
export default function Index() {
|
export default function Index() {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
@@ -375,6 +376,9 @@ export default function Index() {
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
{/* App Showcase */}
|
||||||
|
<AppShowcase />
|
||||||
</AppLayout>
|
</AppLayout>
|
||||||
|
|
||||||
{/* Onboarding Dialog */}
|
{/* Onboarding Dialog */}
|
||||||
|
|||||||
Reference in new issue
Block a user