diff --git a/src/AppRouter.tsx b/src/AppRouter.tsx index 7818c4da..00c72798 100644 --- a/src/AppRouter.tsx +++ b/src/AppRouter.tsx @@ -5,6 +5,7 @@ import { URLFragmentHandler } from "./components/URLFragmentHandler"; import Index from "./pages/Index"; import Clone from "./pages/Clone"; +import Explore from "./pages/Explore"; import Settings from "./pages/Settings"; import Preferences from "./pages/Preferences"; import NostrSettings from "./pages/NostrSettings"; @@ -38,6 +39,7 @@ export function AppRouter() { } /> } /> } /> + } /> } /> } /> } /> diff --git a/src/components/ProjectSidebar.tsx b/src/components/ProjectSidebar.tsx index 108f5f5a..a86df1a8 100644 --- a/src/components/ProjectSidebar.tsx +++ b/src/components/ProjectSidebar.tsx @@ -1,7 +1,7 @@ import React, { useEffect, useState, useMemo } from 'react'; import { useNavigate } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; -import { Plus, Folder, GitBranch, Loader2, ChevronDown, ChevronRight, Star, Columns2, X, Settings, HelpCircle, Search, Tag, Folders } from 'lucide-react'; +import { Plus, Folder, GitBranch, Loader2, ChevronDown, ChevronRight, Star, Columns2, X, Settings, HelpCircle, Search, Tag, Folders, Compass } from 'lucide-react'; import { Button } from '@/components/ui/button'; import { Skeleton } from '@/components/ui/skeleton'; import { Input } from '@/components/ui/input'; @@ -367,6 +367,13 @@ export function ProjectSidebar({ {t('importRepository')} + navigateAndClose('/explore')} + className="flex items-center gap-2 w-full" + > + + {t('exploreApps')} + setLabelsDialogOpen(true)} className="flex items-center gap-2 w-full" diff --git a/src/locales/en.json b/src/locales/en.json index beff6153..15675570 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -139,6 +139,10 @@ "emailUpdatesDescription": "Subscribe to Shakespeare updates and resources", "newProject": "New Project", "importRepository": "Import Repository", + "explore": "Explore", + "exploreApps": "Explore Apps", + "exploreRepositories": "Explore repositories from the Nostr network", + "pleaseLogInToExplore": "Please log in to explore repositories", "noProjectsYet": "No projects yet", "createFirstProject": "Create your first project to get started", "searchProjects": "Search projects...", diff --git a/src/pages/Clone.tsx b/src/pages/Clone.tsx index 0de35c33..729d6a4a 100644 --- a/src/pages/Clone.tsx +++ b/src/pages/Clone.tsx @@ -1,32 +1,19 @@ -import { useState, useEffect, useCallback, useRef, useMemo } from 'react'; +import { useState, useEffect, useCallback, useRef } from 'react'; import { useNavigate, useSearchParams } from 'react-router-dom'; import { useTranslation } from 'react-i18next'; import { AppLayout } from '@/components/AppLayout'; import { Button } from '@/components/ui/button'; import { Input } from '@/components/ui/input'; -import { GitBranch, Loader2, AlertCircle, FileArchive, MoreHorizontal, Search } from 'lucide-react'; +import { GitBranch, Loader2, AlertCircle, FileArchive, MoreHorizontal } from 'lucide-react'; import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useToast } from '@/hooks/useToast'; import { ZipImportDialog } from '@/components/ZipImportDialog'; import { useSeoMeta } from '@unhead/react'; import { DropdownMenu, DropdownMenuTrigger, DropdownMenuContent, DropdownMenuItem } from '@/components/ui/dropdown-menu'; import { useCurrentUser } from '@/hooks/useCurrentUser'; -import { useUserRepositories } from '@/hooks/useUserRepositories'; -import { useContacts } from '@/hooks/useContacts'; -import { useFollowedRepositories } from '@/hooks/useFollowedRepositories'; -import { RepositoryCard } from '@/components/RepositoryCard'; -import { Skeleton } from '@/components/ui/skeleton'; -import { Card, CardContent } from '@/components/ui/card'; -import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'; -import type { Repository } from '@/hooks/useUserRepositories'; -import { useNostr } from '@nostrify/react'; -import { useQuery } from '@tanstack/react-query'; -import { nip19 } from 'nostr-tools'; -import { NSchema as n } from '@nostrify/nostrify'; -import type { NostrMetadata } from '@nostrify/nostrify'; -import { NostrURI } from '@/lib/NostrURI'; import { useGitSettings } from '@/hooks/useGitSettings'; import { detectFork } from '@/lib/detectFork'; +import { NostrURI } from '@/lib/NostrURI'; export default function Clone() { const { t } = useTranslation(); @@ -41,46 +28,6 @@ export default function Clone() { const [isZipDialogOpen, setIsZipDialogOpen] = useState(false); const { user } = useCurrentUser(); const { settings: gitSettings } = useGitSettings(); - const { data: repositories = [], isLoading: isLoadingRepos } = useUserRepositories(user?.pubkey); - const { data: contacts = [] } = useContacts(user?.pubkey); - const { data: followedRepositories = [], isLoading: isLoadingFollowedRepos } = useFollowedRepositories(contacts); - const [activeTab, setActiveTab] = useState<'my-projects' | 'follows'>('my-projects'); - const [searchQuery, setSearchQuery] = useState(''); - - // Get unique pubkeys from all repositories - const allRepos = useMemo(() => [...repositories, ...followedRepositories], [repositories, followedRepositories]); - const uniquePubkeys = useMemo(() => { - const pubkeys = new Set(); - allRepos.forEach(repo => pubkeys.add(repo.pubkey)); - return Array.from(pubkeys); - }, [allRepos]); - - // Fetch author metadata for all unique pubkeys - const { nostr } = useNostr(); - const { data: authorMetadataMap = new Map() } = useQuery({ - queryKey: ['repository-authors', uniquePubkeys.sort().join(',')], - queryFn: async () => { - if (uniquePubkeys.length === 0) return new Map(); - - const events = await nostr.query( - [{ kinds: [0], authors: uniquePubkeys, limit: uniquePubkeys.length }], - { signal: AbortSignal.timeout(3000) } - ); - - const metadataMap = new Map(); - for (const event of events) { - try { - const metadata = n.json().pipe(n.metadata()).parse(event.content); - metadataMap.set(event.pubkey, metadata); - } catch { - // If parsing fails, continue without metadata for this pubkey - } - } - return metadataMap; - }, - enabled: uniquePubkeys.length > 0, - staleTime: 60000, // 1 minute - }); useSeoMeta({ title: `${t('importRepository')} - Shakespeare`, @@ -256,65 +203,6 @@ export default function Clone() { } }; - // Filter repositories based on search query - const filterRepositories = useCallback((repos: Repository[], query: string): Repository[] => { - if (!query.trim()) { - return repos; - } - - const lowerQuery = query.toLowerCase(); - - return repos.filter((repo) => { - // Filter by repository name - if (repo.name.toLowerCase().includes(lowerQuery)) { - return true; - } - - // Filter by description - if (repo.description?.toLowerCase().includes(lowerQuery)) { - return true; - } - - // Filter by tags (hashtags) - if (repo.repoTags.some(tag => tag.toLowerCase().includes(lowerQuery))) { - return true; - } - - // Filter by hex pubkey - if (repo.pubkey.toLowerCase().includes(lowerQuery)) { - return true; - } - - // Filter by npub (bech32 encoded pubkey) - try { - const npub = nip19.npubEncode(repo.pubkey); - if (npub.toLowerCase().includes(lowerQuery)) { - return true; - } - } catch { - // If encoding fails, skip npub search - } - - // Filter by author name - const authorMetadata = authorMetadataMap.get(repo.pubkey); - if (authorMetadata?.name?.toLowerCase().includes(lowerQuery)) { - return true; - } - - return false; - }); - }, [authorMetadataMap]); - - // Filtered repositories for "My Projects" tab - const filteredMyRepositories = useMemo(() => { - return filterRepositories(repositories, searchQuery); - }, [repositories, searchQuery, filterRepositories]); - - // Filtered repositories for "Follows" tab - const filteredFollowedRepositories = useMemo(() => { - return filterRepositories(followedRepositories, searchQuery); - }, [followedRepositories, searchQuery, filterRepositories]); - return (
@@ -399,180 +287,6 @@ export default function Clone() { open={isZipDialogOpen} onOpenChange={setIsZipDialogOpen} /> - - {/* NIP-34 Repositories with Tabs */} - {user && ( -
- setActiveTab(value as 'my-projects' | 'follows')}> -
- - - My Projects - - - Follows - - - - {/* Search Input */} - {(repositories.length > 0 || followedRepositories.length > 0) && ( -
- - setSearchQuery(e.target.value)} - className="pl-9 h-10 text-sm" - /> -
- )} -
- - - {isLoadingRepos ? ( -
- {Array.from({ length: 3 }).map((_, i) => ( - - -
- -
- - -
-
-
- - -
-
- - -
-
- - -
-
-
- ))} -
- ) : filteredMyRepositories.length > 0 ? ( -
- {filteredMyRepositories.map((repo) => ( - - ))} -
- ) : searchQuery.trim() ? ( - - -
- -

- No repositories found matching "{searchQuery}". -

- -
-
-
- ) : ( - - -
-

- No repositories found. Publish your first repository to Nostr to see it here. -

-
-
-
- )} -
- - - {isLoadingFollowedRepos ? ( -
- {Array.from({ length: 6 }).map((_, i) => ( - - -
- -
- - -
-
-
- - -
-
- - -
-
- - -
-
-
- ))} -
- ) : filteredFollowedRepositories.length > 0 ? ( -
- {filteredFollowedRepositories.map((repo) => ( - - ))} -
- ) : searchQuery.trim() ? ( - - -
- -

- No repositories found matching "{searchQuery}". -

- -
-
-
- ) : contacts.length > 0 ? ( - - -
-

- None of the people you follow have published repositories yet. -

-
-
-
- ) : ( - - -
-

- You're not following anyone yet. Follow people on Nostr to see their repositories here. -

-
-
-
- )} -
-
-
- )} ); -} \ No newline at end of file +} diff --git a/src/pages/Explore.tsx b/src/pages/Explore.tsx new file mode 100644 index 00000000..94fb6934 --- /dev/null +++ b/src/pages/Explore.tsx @@ -0,0 +1,329 @@ +import { useState, useMemo, useCallback } from 'react'; +import { useTranslation } from 'react-i18next'; +import { AppLayout } from '@/components/AppLayout'; +import { Input } from '@/components/ui/input'; +import { Search, Compass } from 'lucide-react'; +import { useCurrentUser } from '@/hooks/useCurrentUser'; +import { useUserRepositories } from '@/hooks/useUserRepositories'; +import { useContacts } from '@/hooks/useContacts'; +import { useFollowedRepositories } from '@/hooks/useFollowedRepositories'; +import { RepositoryCard } from '@/components/RepositoryCard'; +import { Skeleton } from '@/components/ui/skeleton'; +import { Card, CardContent } from '@/components/ui/card'; +import { Tabs, TabsList, TabsTrigger, TabsContent } from '@/components/ui/tabs'; +import { Button } from '@/components/ui/button'; +import type { Repository } from '@/hooks/useUserRepositories'; +import { useNostr } from '@nostrify/react'; +import { useQuery } from '@tanstack/react-query'; +import { nip19 } from 'nostr-tools'; +import { NSchema as n } from '@nostrify/nostrify'; +import type { NostrMetadata } from '@nostrify/nostrify'; +import { useSeoMeta } from '@unhead/react'; + +export default function Explore() { + const { t } = useTranslation(); + const { user } = useCurrentUser(); + const { data: repositories = [], isLoading: isLoadingRepos } = useUserRepositories(user?.pubkey); + const { data: contacts = [] } = useContacts(user?.pubkey); + const { data: followedRepositories = [], isLoading: isLoadingFollowedRepos } = useFollowedRepositories(contacts); + const [activeTab, setActiveTab] = useState<'my-projects' | 'follows'>('my-projects'); + const [searchQuery, setSearchQuery] = useState(''); + + // Get unique pubkeys from all repositories + const allRepos = useMemo(() => [...repositories, ...followedRepositories], [repositories, followedRepositories]); + const uniquePubkeys = useMemo(() => { + const pubkeys = new Set(); + allRepos.forEach(repo => pubkeys.add(repo.pubkey)); + return Array.from(pubkeys); + }, [allRepos]); + + // Fetch author metadata for all unique pubkeys + const { nostr } = useNostr(); + const { data: authorMetadataMap = new Map() } = useQuery({ + queryKey: ['repository-authors', uniquePubkeys.sort().join(',')], + queryFn: async () => { + if (uniquePubkeys.length === 0) return new Map(); + + const events = await nostr.query( + [{ kinds: [0], authors: uniquePubkeys, limit: uniquePubkeys.length }], + { signal: AbortSignal.timeout(3000) } + ); + + const metadataMap = new Map(); + for (const event of events) { + try { + const metadata = n.json().pipe(n.metadata()).parse(event.content); + metadataMap.set(event.pubkey, metadata); + } catch { + // If parsing fails, continue without metadata for this pubkey + } + } + return metadataMap; + }, + enabled: uniquePubkeys.length > 0, + staleTime: 60000, // 1 minute + }); + + useSeoMeta({ + title: `${t('explore')} - Shakespeare`, + description: t('exploreRepositories'), + }); + + // Filter repositories based on search query + const filterRepositories = useCallback((repos: Repository[], query: string): Repository[] => { + if (!query.trim()) { + return repos; + } + + const lowerQuery = query.toLowerCase(); + + return repos.filter((repo) => { + // Filter by repository name + if (repo.name.toLowerCase().includes(lowerQuery)) { + return true; + } + + // Filter by description + if (repo.description?.toLowerCase().includes(lowerQuery)) { + return true; + } + + // Filter by tags (hashtags) + if (repo.repoTags.some(tag => tag.toLowerCase().includes(lowerQuery))) { + return true; + } + + // Filter by hex pubkey + if (repo.pubkey.toLowerCase().includes(lowerQuery)) { + return true; + } + + // Filter by npub (bech32 encoded pubkey) + try { + const npub = nip19.npubEncode(repo.pubkey); + if (npub.toLowerCase().includes(lowerQuery)) { + return true; + } + } catch { + // If encoding fails, skip npub search + } + + // Filter by author name + const authorMetadata = authorMetadataMap.get(repo.pubkey); + if (authorMetadata?.name?.toLowerCase().includes(lowerQuery)) { + return true; + } + + return false; + }); + }, [authorMetadataMap]); + + // Filtered repositories for "My Projects" tab + const filteredMyRepositories = useMemo(() => { + return filterRepositories(repositories, searchQuery); + }, [repositories, searchQuery, filterRepositories]); + + // Filtered repositories for "Follows" tab + const filteredFollowedRepositories = useMemo(() => { + return filterRepositories(followedRepositories, searchQuery); + }, [followedRepositories, searchQuery, filterRepositories]); + + if (!user) { + return ( + +
+

+ {t('pleaseLogInToExplore')} +

+
+
+ ); + } + + return ( + +
+
+
+ +

+ {t('exploreApps')} +

+
+

+ {t('exploreRepositories')} +

+
+ + setActiveTab(value as 'my-projects' | 'follows')}> +
+ + + My Projects + + + Follows + + + + {/* Search Input */} + {(repositories.length > 0 || followedRepositories.length > 0) && ( +
+ + setSearchQuery(e.target.value)} + className="pl-9 h-10 text-sm" + /> +
+ )} +
+ + + {isLoadingRepos ? ( +
+ {Array.from({ length: 3 }).map((_, i) => ( + + +
+ +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ ))} +
+ ) : filteredMyRepositories.length > 0 ? ( +
+ {filteredMyRepositories.map((repo) => ( + + ))} +
+ ) : searchQuery.trim() ? ( + + +
+ +

+ No repositories found matching "{searchQuery}". +

+ +
+
+
+ ) : ( + + +
+

+ No repositories found. Publish your first repository to Nostr to see it here. +

+
+
+
+ )} +
+ + + {isLoadingFollowedRepos ? ( +
+ {Array.from({ length: 6 }).map((_, i) => ( + + +
+ +
+ + +
+
+
+ + +
+
+ + +
+
+ + +
+
+
+ ))} +
+ ) : filteredFollowedRepositories.length > 0 ? ( +
+ {filteredFollowedRepositories.map((repo) => ( + + ))} +
+ ) : searchQuery.trim() ? ( + + +
+ +

+ No repositories found matching "{searchQuery}". +

+ +
+
+
+ ) : contacts.length > 0 ? ( + + +
+

+ None of the people you follow have published repositories yet. +

+
+
+
+ ) : ( + + +
+

+ You're not following anyone yet. Follow people on Nostr to see their repositories here. +

+
+
+
+ )} +
+
+
+
+ ); +}