mirror of
https://gitlab.com/soapbox-pub/shakespeare.git
synced 2026-12-03 07:57:22 +00:00
refactor: replace showcase moderator with curator using NIP-19 event p-tags
Replace the hardcoded 'moderator' npub pattern with a 'curator' field that accepts any note1/nevent1/naddr1 identifier. The p-tag pubkeys from the resolved event are used as authors in a kind 31990 (#t:shakespeare) query. Client-side filter ensures only apps with a 30617 git repo reference are shown, guaranteeing the 'Edit with Shakespeare' button can be rendered. All moderation controls (approve/feature/hide/etc.) are removed from AppShowcaseCard. AppShowcase is simplified to a flat grid.
This commit is contained in:
20 files changed
+224
-891
No files matched your search
Generated
+2
-2
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "shakespeare.diy",
|
||||
"version": "9.10.0",
|
||||
"version": "9.10.4",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "shakespeare.diy",
|
||||
"version": "9.10.0",
|
||||
"version": "9.10.4",
|
||||
"license": "AGPL-3.0-or-later",
|
||||
"dependencies": {
|
||||
"@capacitor/app": "^8.1.0",
|
||||
|
||||
+1
-1
@@ -80,7 +80,7 @@ const defaultConfig: AppConfig = {
|
||||
ngitWebUrl: "https://nostrhub.io/{naddr}",
|
||||
previewDomain: "local-shakespeare.dev",
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: "npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc",
|
||||
showcaseCurator: "",
|
||||
fsPathProjects: "/projects",
|
||||
fsPathConfig: "/config",
|
||||
fsPathTmp: "/tmp",
|
||||
|
||||
@@ -51,7 +51,7 @@ const AppConfigSchema = z.object({
|
||||
previewDomain: z.string().min(1),
|
||||
language: z.string(),
|
||||
showcaseEnabled: z.boolean(),
|
||||
showcaseModerator: z.string(),
|
||||
showcaseCurator: z.string(),
|
||||
fsPathProjects: z.string().min(1),
|
||||
fsPathConfig: z.string().min(1),
|
||||
fsPathTmp: z.string().min(1),
|
||||
|
||||
@@ -1,92 +1,24 @@
|
||||
import React, { useState, useMemo } from "react";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { useCurrentUser } from "@/hooks/useCurrentUser";
|
||||
import React from "react";
|
||||
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 { useAppContext } from "@/hooks/useAppContext";
|
||||
import { useTranslation } from 'react-i18next';
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Link } from 'react-router-dom';
|
||||
import { Settings } from 'lucide-react';
|
||||
|
||||
export function AppShowcase() {
|
||||
const { t } = useTranslation();
|
||||
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;
|
||||
|
||||
// Categorize and organize submissions - single pass for efficiency
|
||||
const {
|
||||
displayedFeaturedApps,
|
||||
displayedTemplateApps,
|
||||
moreApps
|
||||
} = useMemo(() => {
|
||||
const DISPLAY_LIMIT = 6;
|
||||
|
||||
// Single pass categorization
|
||||
const templates: typeof submissions = [];
|
||||
const featured: typeof submissions = [];
|
||||
const approved: typeof submissions = [];
|
||||
|
||||
for (const app of submissions) {
|
||||
if (app.isHidden) continue;
|
||||
|
||||
const isTemplate = app.appTags.includes('Template');
|
||||
const isFeatured = app.isFeatured;
|
||||
const isApproved = app.isApproved;
|
||||
|
||||
if (isTemplate) {
|
||||
templates.push(app);
|
||||
} else if (isFeatured) {
|
||||
featured.push(app);
|
||||
} else if (isApproved) {
|
||||
approved.push(app);
|
||||
}
|
||||
}
|
||||
|
||||
// Shuffle each category once
|
||||
const shuffledTemplates = shuffleArray(templates);
|
||||
const shuffledFeatured = shuffleArray(featured);
|
||||
const shuffledApproved = shuffleArray(approved);
|
||||
|
||||
// Split into display and more sections
|
||||
return {
|
||||
displayedFeaturedApps: shuffledFeatured.slice(0, DISPLAY_LIMIT),
|
||||
displayedTemplateApps: shuffledTemplates.slice(0, DISPLAY_LIMIT),
|
||||
moreApps: [
|
||||
...shuffledFeatured.slice(DISPLAY_LIMIT),
|
||||
...shuffledTemplates.slice(DISPLAY_LIMIT),
|
||||
...shuffledApproved,
|
||||
],
|
||||
};
|
||||
}, [submissions]);
|
||||
|
||||
// Don't show showcase if disabled in settings
|
||||
if (!config.showcaseEnabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Don't show showcase if no apps exist
|
||||
if (isLoading) {
|
||||
return (
|
||||
<div className="mt-16 max-w-7xl mx-auto">
|
||||
@@ -106,14 +38,9 @@ export function AppShowcase() {
|
||||
<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>
|
||||
@@ -147,95 +74,11 @@ export function AppShowcase() {
|
||||
|
||||
return (
|
||||
<div className="mt-16 max-w-7xl mx-auto">
|
||||
{/* Apps Grid */}
|
||||
<div className="space-y-12">
|
||||
{/* Featured Apps */}
|
||||
{displayedFeaturedApps.length > 0 && (
|
||||
<div>
|
||||
<div className="flex items-start gap-3 mb-6">
|
||||
<div className="flex-none w-8 h-8 bg-yellow-100 dark:bg-yellow-900/30 rounded-lg flex items-center justify-center">
|
||||
<span className="text-sm">⭐</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold text-foreground">{t('featuredApps')}</h3>
|
||||
<p className="text-sm text-muted-foreground">{t('featuredAppsDescription')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{displayedFeaturedApps.map((app) => (
|
||||
<AppShowcaseCard
|
||||
key={app.id}
|
||||
app={app}
|
||||
showModerationControls={isModerator}
|
||||
hideApprovalStatus={true}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Templates Section */}
|
||||
{displayedTemplateApps.length > 0 && (
|
||||
<div>
|
||||
<div className="flex items-start gap-3 mb-6">
|
||||
<div className="flex-none w-8 h-8 bg-purple-100 dark:bg-purple-900/30 rounded-lg flex items-center justify-center">
|
||||
<span className="text-sm">📋</span>
|
||||
</div>
|
||||
<div>
|
||||
<h3 className="text-xl font-bold text-foreground">{t('templates')}</h3>
|
||||
<p className="text-sm text-muted-foreground">{t('templatesDescription')}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{displayedTemplateApps.map((app) => (
|
||||
<AppShowcaseCard
|
||||
key={app.id}
|
||||
app={app}
|
||||
showModerationControls={isModerator}
|
||||
hideApprovalStatus={true}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* More Apps (Remaining Featured, Templates, and Approved) - Collapsible */}
|
||||
{moreApps.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-start gap-3">
|
||||
<div className="flex-none w-8 h-8 bg-blue-100 dark:bg-blue-900/50 rounded-lg flex items-center justify-center">
|
||||
<span className="text-sm">📱</span>
|
||||
</div>
|
||||
<div className="text-left">
|
||||
<h3 className="text-xl font-bold text-foreground">
|
||||
{t('moreAppsCount', { count: moreApps.length })}
|
||||
</h3>
|
||||
<p className="text-sm text-muted-foreground">
|
||||
{showAllApps ? t('clickToCollapse') : t('clickToViewMore')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</Button>
|
||||
</CollapsibleTrigger>
|
||||
<CollapsibleContent>
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{moreApps.map((app) => (
|
||||
<AppShowcaseCard
|
||||
key={app.id}
|
||||
app={app}
|
||||
showModerationControls={isModerator}
|
||||
hideApprovalStatus={true}
|
||||
/>
|
||||
))}
|
||||
</div>
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
</div>
|
||||
)}
|
||||
<div className="grid md:grid-cols-2 lg:grid-cols-3 gap-6">
|
||||
{submissions.map((app) => (
|
||||
<AppShowcaseCard key={app.id} app={app} />
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -2,388 +2,36 @@ import React, { useState } from 'react';
|
||||
import { Link } from 'react-router-dom';
|
||||
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 { ExternalLink, User } from 'lucide-react';
|
||||
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';
|
||||
import type { NostrEvent } from '@nostrify/nostrify';
|
||||
|
||||
interface AppShowcaseCardProps {
|
||||
app: AppSubmission;
|
||||
onEdit?: (app: AppSubmission) => void;
|
||||
showModerationControls?: boolean;
|
||||
hideApprovalStatus?: boolean; // Hide pending/approval badges
|
||||
}
|
||||
|
||||
export function AppShowcaseCard({ app, onEdit, showModerationControls, hideApprovalStatus: _hideApprovalStatus }: AppShowcaseCardProps) {
|
||||
const { user } = useCurrentUser();
|
||||
const { nostr } = useNostr();
|
||||
const { mutate: publishEvent, isPending } = useNostrPublish();
|
||||
const queryClient = useQueryClient();
|
||||
export function AppShowcaseCard({ app }: AppShowcaseCardProps) {
|
||||
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
|
||||
const { data: authorData } = useAuthor(app.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
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
|
||||
const currentHomepageList = currentHomepageLists.reduce((latest: NostrEvent | null, current: NostrEvent) =>
|
||||
!latest || current.created_at > latest.created_at ? current : latest,
|
||||
null as NostrEvent | 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
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
|
||||
const currentApprovedList = currentApprovedLists.reduce((latest: NostrEvent | null, current: NostrEvent) =>
|
||||
!latest || current.created_at > latest.created_at ? current : latest,
|
||||
null as NostrEvent | 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
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
|
||||
const currentFeaturedList = currentFeaturedLists.reduce((latest: NostrEvent | null, current: NostrEvent) =>
|
||||
!latest || current.created_at > latest.created_at ? current : latest,
|
||||
null as NostrEvent | 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
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
|
||||
const currentApprovedList = currentApprovedLists.reduce((latest: NostrEvent | null, current: NostrEvent) =>
|
||||
!latest || current.created_at > latest.created_at ? current : latest,
|
||||
null as NostrEvent | 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
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
|
||||
const currentApprovedList = currentApprovedLists.reduce((latest: NostrEvent | null, current: NostrEvent) =>
|
||||
!latest || current.created_at > latest.created_at ? current : latest,
|
||||
null as NostrEvent | 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'
|
||||
});
|
||||
}
|
||||
};
|
||||
const authorNpub = nip19.npubEncode(app.pubkey);
|
||||
|
||||
return (
|
||||
<Card className="group hover:shadow-lg transition-all duration-300 hover:border-primary/20 h-full flex flex-col">
|
||||
{/* App Icon / Header */}
|
||||
<div className="relative">
|
||||
{/* App Screenshot */}
|
||||
<a
|
||||
href={app.websiteUrl}
|
||||
href={app.websiteUrl || undefined}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="block aspect-video bg-gradient-to-br from-muted/50 to-muted rounded-t-lg overflow-hidden cursor-pointer"
|
||||
>
|
||||
{!imageError ? (
|
||||
{app.appIconUrl && !imageError ? (
|
||||
<img
|
||||
src={app.screenshotUrl}
|
||||
alt={`${app.appName} screenshot`}
|
||||
src={app.appIconUrl}
|
||||
alt={`${app.appName} icon`}
|
||||
className="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300"
|
||||
onError={() => setImageError(true)}
|
||||
/>
|
||||
@@ -393,127 +41,16 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro
|
||||
<div className="w-16 h-16 mx-auto mb-2 bg-muted rounded-lg flex items-center justify-center">
|
||||
<ExternalLink className="w-8 h-8" />
|
||||
</div>
|
||||
<p className="text-sm">Screenshot unavailable</p>
|
||||
<p className="text-sm">No preview</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-muted 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-foreground mb-1" title={app.appName}>
|
||||
{app.appName.length > 50 ? `${app.appName.slice(0, 50)}...` : app.appName}
|
||||
@@ -522,7 +59,9 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p className="text-muted-foreground mb-3 line-clamp-3">{app.description}</p>
|
||||
{app.description && (
|
||||
<p className="text-muted-foreground mb-3 line-clamp-3">{app.description}</p>
|
||||
)}
|
||||
|
||||
{/* Author Information */}
|
||||
<div className="flex items-center gap-2 mb-4">
|
||||
@@ -547,7 +86,7 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro
|
||||
<span className="text-sm text-muted-foreground">
|
||||
by{' '}
|
||||
<a
|
||||
href={`https://ditto.pub/${app.authorNpub || nip19.npubEncode(authorPubkey)}`}
|
||||
href={`https://ditto.pub/${authorNpub}`}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
className="text-primary hover:text-primary/80 transition-colors hover:underline"
|
||||
@@ -562,28 +101,32 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro
|
||||
|
||||
{/* Action Links */}
|
||||
<div className="flex items-center gap-2 mt-auto">
|
||||
<Link
|
||||
to={`/clone?url=${encodeURIComponent(app.repositoryUrl)}`}
|
||||
className="flex-1"
|
||||
>
|
||||
<img
|
||||
src="/badge.svg"
|
||||
alt="Edit with Shakespeare"
|
||||
className="h-6 hover:opacity-80 transition-opacity"
|
||||
/>
|
||||
</Link>
|
||||
<Button variant="outline" size="sm" asChild>
|
||||
<a
|
||||
href={app.websiteUrl}
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
title="Visit app"
|
||||
{app.repositoryUrl && (
|
||||
<Link
|
||||
to={`/clone?url=${encodeURIComponent(app.repositoryUrl)}`}
|
||||
className="flex-1"
|
||||
>
|
||||
<ExternalLink className="w-4 h-4" />
|
||||
</a>
|
||||
</Button>
|
||||
<img
|
||||
src="/badge.svg"
|
||||
alt="Edit with Shakespeare"
|
||||
className="h-6 hover:opacity-80 transition-opacity"
|
||||
/>
|
||||
</Link>
|
||||
)}
|
||||
{app.websiteUrl && (
|
||||
<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>
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ describe('SentryProvider', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
showcaseEnabled: false,
|
||||
showcaseModerator: '',
|
||||
showcaseCurator: '',
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
@@ -83,7 +83,7 @@ describe('SentryProvider', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
showcaseEnabled: false,
|
||||
showcaseModerator: '',
|
||||
showcaseCurator: '',
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
@@ -128,7 +128,7 @@ describe('SentryProvider', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
showcaseEnabled: false,
|
||||
showcaseModerator: '',
|
||||
showcaseCurator: '',
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
@@ -176,7 +176,7 @@ describe('SentryProvider', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'test.dev',
|
||||
showcaseEnabled: false,
|
||||
showcaseModerator: '',
|
||||
showcaseCurator: '',
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
fsPathTmp: '/tmp',
|
||||
|
||||
@@ -50,8 +50,8 @@ export interface AppConfig {
|
||||
language?: string;
|
||||
/** Whether to show the showcase section */
|
||||
showcaseEnabled: boolean;
|
||||
/** Npub of the showcase moderator */
|
||||
showcaseModerator: string;
|
||||
/** NIP-19 identifier (note1, nevent1, or naddr1) pointing at an event with p tags used as curator authors */
|
||||
showcaseCurator: string;
|
||||
/** VFS path for projects directory */
|
||||
fsPathProjects: string;
|
||||
/** VFS path for config directory */
|
||||
|
||||
+133
-186
@@ -1,24 +1,8 @@
|
||||
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';
|
||||
import type { NostrEvent, NostrFilter, NRelay, NPool } from '@nostrify/nostrify';
|
||||
import { useAppContext } from '@/hooks/useAppContext';
|
||||
|
||||
export interface AppSubmission extends NostrEvent {
|
||||
appName: string;
|
||||
@@ -26,195 +10,158 @@ export interface AppSubmission extends NostrEvent {
|
||||
repositoryUrl: string;
|
||||
description: string;
|
||||
appIconUrl: string;
|
||||
screenshotUrl: string;
|
||||
appTags: string[];
|
||||
authorNpub: string;
|
||||
isFeatured: boolean;
|
||||
isApproved: boolean;
|
||||
isHidden: boolean;
|
||||
isHomepage: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract pubkeys from the `p` tags of a Nostr event.
|
||||
*/
|
||||
function extractPubkeys(event: NostrEvent): string[] {
|
||||
return event.tags
|
||||
.filter(([name]) => name === 'p')
|
||||
.map(([, pubkey]) => pubkey)
|
||||
.filter(Boolean);
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve a NIP-19 identifier (note1, nevent1, or naddr1) to an event.
|
||||
*/
|
||||
async function resolveCuratorEvent(
|
||||
curatorIdentifier: string,
|
||||
nostr: NPool<NRelay>,
|
||||
): Promise<NostrEvent | null> {
|
||||
try {
|
||||
const decoded = nip19.decode(curatorIdentifier);
|
||||
|
||||
if (decoded.type === 'note') {
|
||||
const events = await nostr.query(
|
||||
[{ ids: [decoded.data], limit: 1 }],
|
||||
{ signal: AbortSignal.timeout(3000) },
|
||||
);
|
||||
return events[0] ?? null;
|
||||
}
|
||||
|
||||
if (decoded.type === 'nevent') {
|
||||
const filter: NostrFilter = { ids: [decoded.data.id], limit: 1 };
|
||||
if (decoded.data.author) filter.authors = [decoded.data.author];
|
||||
const events = await nostr.query([filter], { signal: AbortSignal.timeout(3000) });
|
||||
return events[0] ?? null;
|
||||
}
|
||||
|
||||
if (decoded.type === 'naddr') {
|
||||
const { kind, pubkey, identifier } = decoded.data;
|
||||
const events = await nostr.query(
|
||||
[{ kinds: [kind], authors: [pubkey], '#d': [identifier], limit: 1 }],
|
||||
{ signal: AbortSignal.timeout(3000) },
|
||||
);
|
||||
return events[0] ?? null;
|
||||
}
|
||||
} catch {
|
||||
// Invalid identifier or query failure — handled by caller
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if a kind 31990 event can render an "Edit with Shakespeare" button.
|
||||
* Requires an `a` tag referencing a kind 30617 git repository event.
|
||||
*/
|
||||
function hasGitRepository(event: NostrEvent): boolean {
|
||||
return event.tags.some(([name, value]) => name === 'a' && value?.startsWith('30617:'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Build a git clone URL from a kind 30617 `a` tag value (`30617:pubkey:d-tag`).
|
||||
* Returns a nostr:// URI usable with isomorphic-git / Shakespeare clone flow.
|
||||
*/
|
||||
function repositoryUrlFromATag(aTagValue: string): string {
|
||||
const parts = aTagValue.split(':');
|
||||
if (parts.length < 3) return '';
|
||||
const [, pubkey, identifier] = parts;
|
||||
return `nostr://${pubkey}/${identifier}`;
|
||||
}
|
||||
|
||||
export function useAppSubmissions() {
|
||||
const { nostr } = useNostr();
|
||||
const { config } = useAppContext();
|
||||
const curatorIdentifier = config.showcaseCurator;
|
||||
|
||||
return useQuery({
|
||||
queryKey: ['nostr', 'app-submissions'],
|
||||
queryKey: ['nostr', 'app-submissions', curatorIdentifier],
|
||||
queryFn: async (): Promise<AppSubmission[]> => {
|
||||
// Get Soapbox team follow pack for auto-approval
|
||||
const 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
|
||||
}], { signal: AbortSignal.timeout(1000) });
|
||||
// No curator configured — nothing to show
|
||||
if (!curatorIdentifier.trim()) return [];
|
||||
|
||||
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);
|
||||
}
|
||||
// 1. Resolve the curator event to extract author pubkeys
|
||||
const curatorEvent = await resolveCuratorEvent(curatorIdentifier, nostr);
|
||||
if (!curatorEvent) return [];
|
||||
|
||||
// Get all app submissions (kind 31733)
|
||||
const submissionEvents = await nostr.query([{
|
||||
kinds: [APP_SUBMISSION_KIND],
|
||||
'#t': ['soapbox-app-submission'],
|
||||
limit: 100,
|
||||
}], { signal: AbortSignal.timeout(3000) });
|
||||
const authorPubkeys = extractPubkeys(curatorEvent);
|
||||
if (authorPubkeys.length === 0) return [];
|
||||
|
||||
// Get list events from moderators (NIP-51 kind 30267)
|
||||
const moderatorListEvents = await nostr.query([{
|
||||
kinds: [30267],
|
||||
authors: [MODERATOR_HEX],
|
||||
'#d': [
|
||||
'soapbox-featured-apps',
|
||||
'soapbox-approved-apps',
|
||||
'soapbox-homepage-apps',
|
||||
],
|
||||
limit: 3,
|
||||
}], { signal: AbortSignal.timeout(1000) });
|
||||
// 2. Query kind 31990 events from those authors tagged with #t:shakespeare
|
||||
const appEvents = await nostr.query(
|
||||
[{
|
||||
kinds: [31990],
|
||||
authors: authorPubkeys,
|
||||
'#t': ['shakespeare'],
|
||||
limit: 200,
|
||||
}],
|
||||
{ signal: AbortSignal.timeout(5000) },
|
||||
);
|
||||
|
||||
// Get reporting events for hidden apps (NIP-56 kind 1984)
|
||||
const reportEvents = await nostr.query([{
|
||||
kinds: [1984],
|
||||
authors: [MODERATOR_HEX],
|
||||
limit: 1000
|
||||
}], { signal: AbortSignal.timeout(1000) });
|
||||
// 3. Client-side filter: only keep events that can render "Edit with Shakespeare"
|
||||
const filteredEvents = appEvents.filter(hasGitRepository);
|
||||
|
||||
// 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);
|
||||
// 4. Deduplicate: for each pubkey+d-tag, keep only the latest event
|
||||
const latestMap = new Map<string, NostrEvent>();
|
||||
for (const event of filteredEvents) {
|
||||
const dTag = event.tags.find(([name]) => name === 'd')?.[1] ?? '';
|
||||
const key = `${event.pubkey}:${dTag}`;
|
||||
const existing = latestMap.get(key);
|
||||
if (!existing || event.created_at > existing.created_at) {
|
||||
submissionMap.set(dTag, event);
|
||||
latestMap.set(key, event);
|
||||
}
|
||||
}
|
||||
|
||||
// Get the latest featured list
|
||||
const featuredList = moderatorListEvents.find(e => e.tags.find(tag => tag[0] === 'd' && tag[1] === 'soapbox-featured-apps'));
|
||||
const approvedList = moderatorListEvents.find(e => e.tags.find(tag => tag[0] === 'd' && tag[1] === 'soapbox-approved-apps'));
|
||||
const homepageList = moderatorListEvents.find(e => e.tags.find(tag => tag[0] === 'd' && tag[1] === 'soapbox-homepage-apps'));
|
||||
|
||||
// Extract featured app coordinates from the list
|
||||
const featuredAppCoords = new Set<string>();
|
||||
if (featuredList) {
|
||||
featuredList.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 (approvedList) {
|
||||
approvedList.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 (homepageList) {
|
||||
homepageList.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) {
|
||||
// 5. Shape into AppSubmission objects
|
||||
const submissions: AppSubmission[] = [];
|
||||
for (const event of latestMap.values()) {
|
||||
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]);
|
||||
let appName = '';
|
||||
let appIconUrl = '';
|
||||
let websiteUrl = '';
|
||||
let description = '';
|
||||
|
||||
// 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);
|
||||
// Parse kind-0-style metadata from content
|
||||
if (event.content) {
|
||||
try {
|
||||
const meta = JSON.parse(event.content) as Record<string, unknown>;
|
||||
if (typeof meta.name === 'string') appName = meta.name;
|
||||
if (typeof meta.about === 'string') description = meta.about;
|
||||
if (typeof meta.picture === 'string') appIconUrl = meta.picture;
|
||||
if (typeof meta.website === 'string') websiteUrl = meta.website;
|
||||
} catch {
|
||||
// Non-JSON content — ignore
|
||||
}
|
||||
}
|
||||
|
||||
// Fallback: title tag
|
||||
if (!appName) {
|
||||
appName = event.tags.find(([name]) => name === 'title')?.[1] ?? '';
|
||||
}
|
||||
|
||||
// Build repository URL from the first 30617 `a` tag
|
||||
const repoATag = event.tags.find(([name, value]) => name === 'a' && value?.startsWith('30617:'));
|
||||
const repositoryUrl = repoATag ? repositoryUrlFromATag(repoATag[1]) : '';
|
||||
|
||||
submissions.push({
|
||||
...event,
|
||||
appName,
|
||||
websiteUrl,
|
||||
repositoryUrl,
|
||||
description: event.content,
|
||||
description,
|
||||
appIconUrl,
|
||||
screenshotUrl,
|
||||
appTags: appTags,
|
||||
authorNpub,
|
||||
isFeatured,
|
||||
isApproved,
|
||||
isHidden,
|
||||
isHomepage
|
||||
});
|
||||
} catch (error) {
|
||||
console.warn('Failed to parse app submission:', error);
|
||||
@@ -223,8 +170,8 @@ export function useAppSubmissions() {
|
||||
|
||||
return submissions;
|
||||
},
|
||||
staleTime: 30000, // 30 seconds
|
||||
refetchInterval: 60000, // 1 minute
|
||||
staleTime: 30000,
|
||||
refetchInterval: 60000,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -235,6 +182,6 @@ export function useUserAppSubmissions(userPubkey?: string) {
|
||||
|
||||
return {
|
||||
data: userSubmissions,
|
||||
...rest
|
||||
...rest,
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -68,7 +68,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: {
|
||||
relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }],
|
||||
updatedAt: 0,
|
||||
@@ -232,7 +232,7 @@ describe('useGenerateProjectInfo', () => {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: {
|
||||
relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }],
|
||||
updatedAt: 0,
|
||||
|
||||
@@ -45,7 +45,7 @@ function createWrapper(corsProxy: string) {
|
||||
ngitWebUrl: 'https://nostrhub.io/{naddr}',
|
||||
previewDomain: 'local-test.dev',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 },
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
|
||||
@@ -49,7 +49,7 @@ const testConfig: AppConfig = {
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
language: 'en',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 },
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
|
||||
@@ -36,7 +36,7 @@ const testConfig: AppConfig = {
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
language: 'en',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: { relays: [{ url: 'wss://git.shakespeare.diy/' }, { url: 'wss://relay.ngit.dev/' }], updatedAt: 0 },
|
||||
fsPathProjects: '/projects',
|
||||
fsPathConfig: '/config',
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "Showcase",
|
||||
"showcaseEnabled": "Showcase Enabled",
|
||||
"showcaseEnabledDescription": "Display the app showcase section on the home page",
|
||||
"showcaseModerator": "Showcase Moderator",
|
||||
"showcaseModeratorDescription": "Nostr public key (npub) of the user who can moderate showcase submissions",
|
||||
"showcaseCurator": "Showcase Curator",
|
||||
"showcaseCuratorDescription": "NIP-19 identifier (note1, nevent1, or naddr1) pointing at an event whose p tags define the curator authors",
|
||||
"filesystemPaths": "Filesystem Paths",
|
||||
"projectsDirectory": "Projects",
|
||||
"configDirectory": "Config",
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "Nuni",
|
||||
"showcaseEnabled": "An Kunna Nuni",
|
||||
"showcaseEnabledDescription": "Nuna sashen nuni na aikace-aikace a shafin gida",
|
||||
"showcaseModerator": "Mai Kula da Nuni",
|
||||
"showcaseModeratorDescription": "Maɓallin jama'a na Nostr (npub) na mai amfani wanda zai iya kula da ƙaddamarwar nuni",
|
||||
"showcaseCurator": "Mai Zaɓi na Nuni",
|
||||
"showcaseCuratorDescription": "Alamar NIP-19 (note1, nevent1, ko naddr1) mai nuni ga wani taron da tagoginsa na p ke bayar da marubutan mai zaɓi",
|
||||
"filesystemPaths": "Hanyoyin Tsarin Fayil",
|
||||
"projectsDirectory": "Kundin Ayyuka",
|
||||
"projectsDirectoryDescription": "Hanyar tsarin fayil inda ake adana ayyuka",
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "Ngosipụta",
|
||||
"showcaseEnabled": "Ngosipụta Emechara",
|
||||
"showcaseEnabledDescription": "Gosipụta ngalaba ngosipụta ngwa na ibe ụlọ",
|
||||
"showcaseModerator": "Onye Nlekọta Ngosipụta",
|
||||
"showcaseModeratorDescription": "Igodo ọha Nostr (npub) nke onye ọrụ nwere ike ilekọta ntinye ngosipụta",
|
||||
"showcaseCurator": "Onye Nhazi Ngosipụta",
|
||||
"showcaseCuratorDescription": "Njirimara NIP-19 (note1, nevent1, ma ọ bụ naddr1) na-egosi ihe omume nke p tags ya na-atọ ụda ndị odeakwụkwọ nhazi",
|
||||
"filesystemPaths": "Ụzọ Sistemu Faịlụ",
|
||||
"projectsDirectory": "Ndekọ Ọrụ",
|
||||
"projectsDirectoryDescription": "Ụzọ sistemu faịlụ ebe echekwara ọrụ",
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "Vitrine",
|
||||
"showcaseEnabled": "Vitrine Ativada",
|
||||
"showcaseEnabledDescription": "Exibir a seção de vitrine de aplicativos na página inicial",
|
||||
"showcaseModerator": "Moderador da Vitrine",
|
||||
"showcaseModeratorDescription": "Chave pública Nostr (npub) do usuário que pode moderar envios da vitrine",
|
||||
"showcaseCurator": "Curador da Vitrine",
|
||||
"showcaseCuratorDescription": "Identificador NIP-19 (note1, nevent1 ou naddr1) apontando para um evento cujas tags p definem os autores curadores",
|
||||
"filesystemPaths": "Caminhos do Sistema de Arquivos",
|
||||
"projectsDirectory": "Diretório de Projetos",
|
||||
"projectsDirectoryDescription": "Caminho do sistema de arquivos onde os projetos são armazenados",
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "Ifihan",
|
||||
"showcaseEnabled": "Ifihan Ṣiṣẹ",
|
||||
"showcaseEnabledDescription": "Ṣafihan apakan ifihan ohun elo lori oju-iwe ile",
|
||||
"showcaseModerator": "Oluṣakoso Ifihan",
|
||||
"showcaseModeratorDescription": "Bọtini gbangba Nostr (npub) ti olumulo ti o le ṣakoso awọn ifisilẹ ifihan",
|
||||
"showcaseCurator": "Alásàánú Ifihan",
|
||||
"showcaseCuratorDescription": "Idanimọ NIP-19 (note1, nevent1, tabi naddr1) ti o tọka si iṣẹlẹ kan ti awọn tag p rẹ ṣe asọye awọn onkọwe alásàánú",
|
||||
"filesystemPaths": "Awọn Ọna Eto Faili",
|
||||
"projectsDirectory": "Itọsọna Awọn iṣẹ akanṣe",
|
||||
"projectsDirectoryDescription": "Ọna eto faili nibiti a tọju awọn iṣẹ akanṣe",
|
||||
|
||||
+2
-2
@@ -51,8 +51,8 @@
|
||||
"showcase": "展示",
|
||||
"showcaseEnabled": "启用展示",
|
||||
"showcaseEnabledDescription": "在主页上显示应用展示部分",
|
||||
"showcaseModerator": "展示管理员",
|
||||
"showcaseModeratorDescription": "可以审核展示提交的用户的Nostr公钥(npub)",
|
||||
"showcaseCurator": "展示策展人",
|
||||
"showcaseCuratorDescription": "NIP-19 标识符(note1、nevent1 或 naddr1),指向一个事件,其 p 标签定义策展人作者",
|
||||
"filesystemPaths": "文件系统路径",
|
||||
"projectsDirectory": "项目目录",
|
||||
"projectsDirectoryDescription": "存储项目的文件系统路径",
|
||||
|
||||
@@ -23,7 +23,7 @@ export function SystemSettings() {
|
||||
const [faviconUrlInput, setFaviconUrlInput] = useState(config.faviconUrl);
|
||||
const [ngitWebUrlInput, setNgitWebUrlInput] = useState(config.ngitWebUrl);
|
||||
const [previewDomainInput, setPreviewDomainInput] = useState(config.previewDomain);
|
||||
const [showcaseModeratorInput, setShowcaseModeratorInput] = useState(config.showcaseModerator);
|
||||
const [showcaseCuratorInput, setShowcaseCuratorInput] = useState(config.showcaseCurator);
|
||||
const [fsPathProjectsInput, setFsPathProjectsInput] = useState(config.fsPathProjects);
|
||||
const [fsPathConfigInput, setFsPathConfigInput] = useState(config.fsPathConfig);
|
||||
const [fsPathTmpInput, setFsPathTmpInput] = useState(config.fsPathTmp);
|
||||
@@ -41,7 +41,7 @@ export function SystemSettings() {
|
||||
ngitWebUrl: config.ngitWebUrl !== defaultConfig.ngitWebUrl,
|
||||
previewDomain: config.previewDomain !== defaultConfig.previewDomain,
|
||||
showcaseEnabled: config.showcaseEnabled !== defaultConfig.showcaseEnabled,
|
||||
showcaseModerator: config.showcaseModerator !== defaultConfig.showcaseModerator,
|
||||
showcaseCurator: config.showcaseCurator !== defaultConfig.showcaseCurator,
|
||||
fsPathProjects: config.fsPathProjects !== defaultConfig.fsPathProjects,
|
||||
fsPathConfig: config.fsPathConfig !== defaultConfig.fsPathConfig,
|
||||
fsPathTmp: config.fsPathTmp !== defaultConfig.fsPathTmp,
|
||||
@@ -105,11 +105,11 @@ export function SystemSettings() {
|
||||
});
|
||||
};
|
||||
|
||||
const restoreShowcaseModerator = () => {
|
||||
const defaultValue = defaultConfig.showcaseModerator;
|
||||
setShowcaseModeratorInput(defaultValue);
|
||||
const restoreShowcaseCurator = () => {
|
||||
const defaultValue = defaultConfig.showcaseCurator;
|
||||
setShowcaseCuratorInput(defaultValue);
|
||||
updateConfig((current) => {
|
||||
const { showcaseModerator, ...rest } = current;
|
||||
const { showcaseCurator, ...rest } = current;
|
||||
return rest;
|
||||
});
|
||||
};
|
||||
@@ -640,7 +640,7 @@ export function SystemSettings() {
|
||||
<div className="flex items-center gap-2">
|
||||
<Award className="h-4 w-4 text-muted-foreground" />
|
||||
<h4 className="text-sm font-medium">{t('showcase')}</h4>
|
||||
{(isModified.showcaseEnabled || isModified.showcaseModerator) && (
|
||||
{(isModified.showcaseEnabled || isModified.showcaseCurator) && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
@@ -685,34 +685,34 @@ export function SystemSettings() {
|
||||
|
||||
<div className="space-y-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<Label htmlFor="showcase-moderator" className="text-sm font-medium">
|
||||
{t('showcaseModerator')}
|
||||
<Label htmlFor="showcase-curator" className="text-sm font-medium">
|
||||
{t('showcaseCurator')}
|
||||
</Label>
|
||||
{isModified.showcaseModerator && (
|
||||
{isModified.showcaseCurator && (
|
||||
<div className="h-2 w-2 rounded-full bg-yellow-500" title={t('modified')} />
|
||||
)}
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Input
|
||||
id="showcase-moderator"
|
||||
id="showcase-curator"
|
||||
type="text"
|
||||
placeholder="npub1..."
|
||||
value={showcaseModeratorInput}
|
||||
placeholder="note1... / nevent1... / naddr1..."
|
||||
value={showcaseCuratorInput}
|
||||
onChange={(e) => {
|
||||
const value = e.target.value;
|
||||
setShowcaseModeratorInput(value);
|
||||
setShowcaseCuratorInput(value);
|
||||
updateConfig((current) => ({
|
||||
...current,
|
||||
showcaseModerator: value,
|
||||
showcaseCurator: value,
|
||||
}));
|
||||
}}
|
||||
className="flex-1"
|
||||
/>
|
||||
{isModified.showcaseModerator && (
|
||||
{isModified.showcaseCurator && (
|
||||
<Button
|
||||
variant="outline"
|
||||
size="icon"
|
||||
onClick={restoreShowcaseModerator}
|
||||
onClick={restoreShowcaseCurator}
|
||||
title={t('restoreToDefault')}
|
||||
>
|
||||
<RotateCcw className="h-4 w-4" />
|
||||
@@ -720,7 +720,7 @@ export function SystemSettings() {
|
||||
)}
|
||||
</div>
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('showcaseModeratorDescription')}
|
||||
{t('showcaseCuratorDescription')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -50,7 +50,7 @@ export function TestApp({ children }: TestAppProps) {
|
||||
previewDomain: 'local-shakespeare.dev',
|
||||
language: 'en',
|
||||
showcaseEnabled: true,
|
||||
showcaseModerator: 'npub1jvnpg4c6ljadf5t6ry0w9q0rnm4mksde87kglkrc993z46c39axsgq89sc',
|
||||
showcaseCurator: '',
|
||||
graspMetadata: {
|
||||
relays: [
|
||||
{ url: 'wss://git.shakespeare.diy/' },
|
||||
|
||||
Reference in new issue
Block a user