diff --git a/package-lock.json b/package-lock.json index 04568709..3f652091 100644 --- a/package-lock.json +++ b/package-lock.json @@ -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", diff --git a/src/App.tsx b/src/App.tsx index 8bfaff91..8569367f 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -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", diff --git a/src/components/AppProvider.tsx b/src/components/AppProvider.tsx index d30d8404..f6cdef46 100644 --- a/src/components/AppProvider.tsx +++ b/src/components/AppProvider.tsx @@ -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), diff --git a/src/components/AppShowcase.tsx b/src/components/AppShowcase.tsx index a0518874..cc4c8c44 100644 --- a/src/components/AppShowcase.tsx +++ b/src/components/AppShowcase.tsx @@ -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 (
@@ -106,14 +38,9 @@ export function AppShowcase() {
-
- - -
-
@@ -147,95 +74,11 @@ export function AppShowcase() { return (
- {/* Apps Grid */} -
- {/* Featured Apps */} - {displayedFeaturedApps.length > 0 && ( -
-
-
- ⭐ -
-
-

{t('featuredApps')}

-

{t('featuredAppsDescription')}

-
-
-
- {displayedFeaturedApps.map((app) => ( - - ))} -
-
- )} - - {/* Templates Section */} - {displayedTemplateApps.length > 0 && ( -
-
-
- 📋 -
-
-

{t('templates')}

-

{t('templatesDescription')}

-
-
-
- {displayedTemplateApps.map((app) => ( - - ))} -
-
- )} - - {/* More Apps (Remaining Featured, Templates, and Approved) - Collapsible */} - {moreApps.length > 0 && ( -
- - - - - -
- {moreApps.map((app) => ( - - ))} -
-
-
-
- )} +
+ {submissions.map((app) => ( + + ))}
); -} \ No newline at end of file +} diff --git a/src/components/AppShowcaseCard.tsx b/src/components/AppShowcaseCard.tsx index 4329163d..d16aef96 100644 --- a/src/components/AppShowcaseCard.tsx +++ b/src/components/AppShowcaseCard.tsx @@ -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(); - 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(); - 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(); - 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(); - 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(); - 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 ( + {/* App Icon / Header */}
)} - - {/* Actions Menu */} - {(isOwner || showModerationControls) && ( -
- - - - - - {isOwner && ( - onEdit?.(app)}> - - Edit App - - )} - {showModerationControls && isModerator && ( - <> - {isHalloweenSubmission && getContactInfo() && (getContactInfo()?.lightning || getContactInfo()?.email) && ( - - - View Contact Info - - )} - {!app.isApproved && ( - handleModerationAction('approve')} - disabled={isPending} - > - - Approve - - )} - {app.isApproved && !app.isFeatured && ( - handleModerationAction('unapprove')} - disabled={isPending} - > - - Unapprove - - )} - handleModerationAction(app.isFeatured ? 'unfeature' : 'feature')} - disabled={isPending} - > - {app.isFeatured ? ( - <> - - Un-feature - - ) : ( - <> - - Feature - - )} - - handleModerationAction(app.isHomepage ? 'unhomepage' : 'homepage')} - disabled={isPending} - > - {app.isHomepage ? ( - <> - - Remove from Homepage - - ) : ( - <> - - Add to Homepage - - )} - - handleModerationAction(app.isHidden ? 'unhide' : 'hide')} - disabled={isPending} - > - {app.isHidden ? ( - <> - - Unhide - - ) : ( - <> - - Hide - - )} - - - )} - - -
- )}
- {/* App Icon */} -
- {`${app.appName} { - const target = e.target as HTMLImageElement; - target.style.display = 'none'; - }} - /> -

{app.appName.length > 50 ? `${app.appName.slice(0, 50)}...` : app.appName} @@ -522,7 +59,9 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro

-

{app.description}

+ {app.description && ( +

{app.description}

+ )} {/* Author Information */}
@@ -547,7 +86,7 @@ export function AppShowcaseCard({ app, onEdit, showModerationControls, hideAppro by{' '} - - Edit with Shakespeare - - + Edit with Shakespeare + + )} + {app.websiteUrl && ( + + )}
); -} \ No newline at end of file +} diff --git a/src/components/SentryProvider.test.tsx b/src/components/SentryProvider.test.tsx index 15f13a6f..88d88e3c 100644 --- a/src/components/SentryProvider.test.tsx +++ b/src/components/SentryProvider.test.tsx @@ -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', diff --git a/src/contexts/AppContext.ts b/src/contexts/AppContext.ts index 4ea8db35..8b4b9cf0 100644 --- a/src/contexts/AppContext.ts +++ b/src/contexts/AppContext.ts @@ -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 */ diff --git a/src/hooks/useAppSubmissions.ts b/src/hooks/useAppSubmissions.ts index 6fa9f396..73b8c0ca 100644 --- a/src/hooks/useAppSubmissions.ts +++ b/src/hooks/useAppSubmissions.ts @@ -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, +): Promise { + 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 => { - // Get Soapbox team follow pack for auto-approval - const teamPubkeys = new Set(); - 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(); - - // 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(); + 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(); - 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(); - 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(); - 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(); - const appReports = new Map(); - - 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; + 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, }; -} \ No newline at end of file +} diff --git a/src/hooks/useGenerateProjectInfo.test.ts b/src/hooks/useGenerateProjectInfo.test.ts index d52331ff..b114ef99 100644 --- a/src/hooks/useGenerateProjectInfo.test.ts +++ b/src/hooks/useGenerateProjectInfo.test.ts @@ -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, diff --git a/src/hooks/useGit.test.ts b/src/hooks/useGit.test.ts index 296dea26..11a94122 100644 --- a/src/hooks/useGit.test.ts +++ b/src/hooks/useGit.test.ts @@ -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', diff --git a/src/lib/SessionManager.test.ts b/src/lib/SessionManager.test.ts index 5264a5d1..494a8af2 100644 --- a/src/lib/SessionManager.test.ts +++ b/src/lib/SessionManager.test.ts @@ -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', diff --git a/src/lib/system.test.ts b/src/lib/system.test.ts index 1cb81017..a4251818 100644 --- a/src/lib/system.test.ts +++ b/src/lib/system.test.ts @@ -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', diff --git a/src/locales/en.json b/src/locales/en.json index 8d1483ea..e33e1769 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -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", diff --git a/src/locales/ha.json b/src/locales/ha.json index 0ceda941..bd95306b 100644 --- a/src/locales/ha.json +++ b/src/locales/ha.json @@ -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", diff --git a/src/locales/ig.json b/src/locales/ig.json index dc154b84..58b24e41 100644 --- a/src/locales/ig.json +++ b/src/locales/ig.json @@ -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ụ", diff --git a/src/locales/pt.json b/src/locales/pt.json index fe44bc9d..b3e97f27 100644 --- a/src/locales/pt.json +++ b/src/locales/pt.json @@ -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", diff --git a/src/locales/yo.json b/src/locales/yo.json index d655ba76..2a83cf7a 100644 --- a/src/locales/yo.json +++ b/src/locales/yo.json @@ -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", diff --git a/src/locales/zh.json b/src/locales/zh.json index 8dbaac49..45af437d 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -51,8 +51,8 @@ "showcase": "展示", "showcaseEnabled": "启用展示", "showcaseEnabledDescription": "在主页上显示应用展示部分", - "showcaseModerator": "展示管理员", - "showcaseModeratorDescription": "可以审核展示提交的用户的Nostr公钥(npub)", + "showcaseCurator": "展示策展人", + "showcaseCuratorDescription": "NIP-19 标识符(note1、nevent1 或 naddr1),指向一个事件,其 p 标签定义策展人作者", "filesystemPaths": "文件系统路径", "projectsDirectory": "项目目录", "projectsDirectoryDescription": "存储项目的文件系统路径", diff --git a/src/pages/SystemSettings.tsx b/src/pages/SystemSettings.tsx index a132339a..023aa5db 100644 --- a/src/pages/SystemSettings.tsx +++ b/src/pages/SystemSettings.tsx @@ -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() {

{t('showcase')}

- {(isModified.showcaseEnabled || isModified.showcaseModerator) && ( + {(isModified.showcaseEnabled || isModified.showcaseCurator) && (
)}
@@ -685,34 +685,34 @@ export function SystemSettings() {
-
diff --git a/src/test/TestApp.tsx b/src/test/TestApp.tsx index 2d044571..2b6f36a5 100644 --- a/src/test/TestApp.tsx +++ b/src/test/TestApp.tsx @@ -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/' },