From a092d924fce07e8b8f0ed4a606b04ac63e2ac715 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Wed, 20 Aug 2025 13:52:35 -0500 Subject: [PATCH] Remove repos list from homepage --- src/components/RepoCard.tsx | 272 ------------------------------------ src/hooks/useRepos.ts | 223 ----------------------------- src/pages/Index.tsx | 97 +------------ 3 files changed, 4 insertions(+), 588 deletions(-) delete mode 100644 src/components/RepoCard.tsx delete mode 100644 src/hooks/useRepos.ts diff --git a/src/components/RepoCard.tsx b/src/components/RepoCard.tsx deleted file mode 100644 index d19fd140..00000000 --- a/src/components/RepoCard.tsx +++ /dev/null @@ -1,272 +0,0 @@ -import { useState } from 'react'; -import { useNavigate } from 'react-router-dom'; -import { useProjectsManager } from '@/hooks/useProjectsManager'; -import { useToast } from '@/hooks/useToast'; -import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Button } from '@/components/ui/button'; -import { Badge } from '@/components/ui/badge'; -import { - Folder, - GitBranch, - Download, - ExternalLink, - Users, - Globe, - Cloud, - HardDrive, - RefreshCw, - Upload -} from 'lucide-react'; -import { cn } from '@/lib/utils'; -import { nip19 } from 'nostr-tools'; -import git from 'isomorphic-git'; -import http from 'isomorphic-git/http/web'; -import type { UnifiedRepo } from '@/hooks/useRepos'; - -interface RepoCardProps { - repo: UnifiedRepo; - onRepoCloned?: () => void; - className?: string; -} - -export function RepoCard({ repo, onRepoCloned, className }: RepoCardProps) { - const navigate = useNavigate(); - const projectsManager = useProjectsManager(); - const { toast } = useToast(); - const [isCloning, setIsCloning] = useState(false); - - const getStatusIcon = () => { - switch (repo.status) { - case 'local-only': - return ; - case 'published': - return ; - case 'remote-only': - return ; - case 'synced': - return ; - } - }; - - const getStatusText = () => { - switch (repo.status) { - case 'local-only': - return 'Local only'; - case 'published': - return 'Published'; - case 'remote-only': - return 'Remote only'; - case 'synced': - return 'Synced'; - } - }; - - const getStatusColor = () => { - switch (repo.status) { - case 'local-only': - return 'bg-blue-100 text-blue-800 dark:bg-blue-900 dark:text-blue-200'; - case 'published': - return 'bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'; - case 'remote-only': - return 'bg-orange-100 text-orange-800 dark:bg-orange-900 dark:text-orange-200'; - case 'synced': - return 'bg-emerald-100 text-emerald-800 dark:bg-emerald-900 dark:text-emerald-200'; - } - }; - - const handleCardClick = () => { - if (repo.localProject) { - navigate(`/project/${repo.localProject.id}`); - } - }; - - const handleCloneRepo = async () => { - if (!repo.nostrRepo || !repo.cloneUrls.length) { - toast({ - title: "No clone URL", - description: "This repository doesn't have any clone URLs configured.", - variant: "destructive", - }); - return; - } - - setIsCloning(true); - - try { - await projectsManager.init(); - - // Create project directory - const projectPath = `/projects/${repo.id}`; - - // Clone the repository - const cloneUrl = repo.cloneUrls[0]; // Use the first clone URL - await git.clone({ - fs: projectsManager.fs, - http, - dir: projectPath, - url: cloneUrl, - singleBranch: true, - depth: 1, - }); - - // Set git config to mark this as a nostr-enabled project - const naddr = nip19.naddrEncode({ - identifier: repo.id, - pubkey: repo.nostrRepo.event.pubkey, - kind: 30617, - relays: repo.relays.length > 0 ? repo.relays : undefined, - }); - - await git.setConfig({ - fs: projectsManager.fs, - dir: projectPath, - path: 'nostr.repo', - value: naddr, - }); - - toast({ - title: "Repository cloned", - description: `${repo.name} has been cloned to your projects.`, - }); - - // Call the callback to refresh the repos list - if (onRepoCloned) { - onRepoCloned(); - } - } catch (error) { - console.error('Failed to clone repository:', error); - toast({ - title: "Clone failed", - description: `Failed to clone ${repo.name}. Please try again.`, - variant: "destructive", - }); - } finally { - setIsCloning(false); - } - }; - - const canOpen = repo.status === 'local-only' || repo.status === 'published' || repo.status === 'synced'; - const canClone = repo.status === 'remote-only' && repo.cloneUrls.length > 0; - - return ( - { - if (e.key === 'Enter' || e.key === ' ') { - e.preventDefault(); - handleCardClick(); - } - } : undefined} - > - -
-
- - {repo.status === 'remote-only' ? ( - - ) : ( - - )} - {repo.name} - - {repo.description && ( - - {repo.description} - - )} -
-
- - - {getStatusIcon()} - {getStatusText()} - - -
-
- - Modified {repo.lastModified.toLocaleDateString()} - -
- - - {/* Tags */} - {repo.tags.length > 0 && ( -
- {repo.tags.slice(0, 3).map((tag) => ( - - {tag} - - ))} - {repo.tags.length > 3 && ( - - +{repo.tags.length - 3} - - )} -
- )} - - {/* Repository info */} - {(repo.maintainers.length > 0 || repo.webUrls.length > 0) && ( -
- {repo.maintainers.length > 0 && ( -
- - {repo.maintainers.length} maintainer{repo.maintainers.length !== 1 ? 's' : ''} -
- )} - {repo.webUrls.length > 0 && ( -
- - Web -
- )} -
- )} - - {/* Actions */} - {(canClone || repo.webUrls.length > 0) && ( -
e.stopPropagation()}> - {canClone && ( - - )} - - {repo.webUrls.length > 0 && ( - - )} -
- )} -
-
- ); -} \ No newline at end of file diff --git a/src/hooks/useRepos.ts b/src/hooks/useRepos.ts deleted file mode 100644 index 9e5c712e..00000000 --- a/src/hooks/useRepos.ts +++ /dev/null @@ -1,223 +0,0 @@ -import { useQuery } from '@tanstack/react-query'; -import { useProjectsManager } from './useProjectsManager'; -import { useCurrentUser } from './useCurrentUser'; -import { useNostr } from '@nostrify/react'; -import { nip19 } from 'nostr-tools'; -import type { Project } from '@/lib/ProjectsManager'; -import type { NostrEvent } from '@nostrify/nostrify'; - -export interface NostrRepo { - event: NostrEvent; - id: string; // d tag value - name: string; - description?: string; - webUrls: string[]; - cloneUrls: string[]; - relays: string[]; - maintainers: string[]; - tags: string[]; - earliestCommit?: string; -} - -export type RepoStatus = - | 'local-only' // Exists only locally, not published to Nostr - | 'published' // Local project that's also published to Nostr - | 'remote-only' // Exists on Nostr but not cloned locally - | 'synced'; // Local and remote are in sync - -export interface UnifiedRepo { - id: string; - name: string; - description?: string; - status: RepoStatus; - lastModified: Date; - - // Local project data (if exists locally) - localProject?: Project; - - // Nostr repo data (if exists on Nostr) - nostrRepo?: NostrRepo; - - // Additional metadata - tags: string[]; - webUrls: string[]; - cloneUrls: string[]; - maintainers: string[]; - relays: string[]; -} - -function parseRepoEvent(event: NostrEvent): NostrRepo | null { - // Validate that this is a repository announcement event - if (event.kind !== 30617) return null; - - const dTag = event.tags.find(([name]) => name === 'd')?.[1]; - if (!dTag) return null; - - const name = event.tags.find(([name]) => name === 'name')?.[1] || dTag; - const description = event.tags.find(([name]) => name === 'description')?.[1]; - - const webUrls = event.tags - .filter(([name]) => name === 'web') - .map(([, url]) => url) - .filter(Boolean); - - const cloneUrls = event.tags - .filter(([name]) => name === 'clone') - .map(([, url]) => url) - .filter(Boolean); - - const relays = event.tags - .filter(([name]) => name === 'relays') - .map(([, relay]) => relay) - .filter(Boolean); - - const maintainers = event.tags - .filter(([name]) => name === 'maintainers') - .map(([, pubkey]) => pubkey) - .filter(Boolean); - - const tags = event.tags - .filter(([name]) => name === 't') - .map(([, tag]) => tag) - .filter(Boolean); - - const earliestCommit = event.tags - .find(([name, , marker]) => name === 'r' && marker === 'euc')?.[1]; - - return { - event, - id: dTag, - name, - description, - webUrls, - cloneUrls, - relays, - maintainers, - tags, - earliestCommit, - }; -} - -export function useRepos() { - const projectsManager = useProjectsManager(); - const { user } = useCurrentUser(); - const { nostr } = useNostr(); - - return useQuery({ - queryKey: ['unified-repos', user?.pubkey], - queryFn: async (c) => { - try { - if (!user?.pubkey) return []; - - const signal = AbortSignal.any([c.signal, AbortSignal.timeout(3000)]); - - // Fetch Nostr repos and local projects in parallel - const [events, localProjects] = await Promise.all([ - nostr.query([ - { - kinds: [30617], // Repository announcements - authors: [user.pubkey], - limit: 50, - } - ], { signal }), - (async () => { - await projectsManager.init(); - return projectsManager.getProjects(); - })() - ]); - - // Parse and validate Nostr events - const nostrRepos = events - .map(parseRepoEvent) - .filter((repo): repo is NostrRepo => repo !== null) - .sort((a, b) => b.event.created_at - a.event.created_at); - - // Create a map to track repos by their identifier - const repoMap = new Map(); - - // First, add all local projects - for (const project of localProjects) { - const naddr = await projectsManager.getNostrRepoAddress(project.id); - let repoId = project.id; - let status: RepoStatus = 'local-only'; - - // If this project has a Nostr address, extract the repo ID - if (naddr) { - try { - const decoded = nip19.decode(naddr); - if (decoded.type === 'naddr') { - repoId = decoded.data.identifier; - status = 'published'; - } - } catch { - // If we can't decode the naddr, treat as local-only - } - } - - repoMap.set(repoId, { - id: repoId, - name: project.name, - description: undefined, - status, - lastModified: project.lastModified, - localProject: project, - tags: [], - webUrls: [], - cloneUrls: [], - maintainers: [], - relays: [], - }); - } - - // Then, add or update with Nostr repos - for (const nostrRepo of nostrRepos) { - const existingRepo = repoMap.get(nostrRepo.id); - - if (existingRepo) { - // Update existing repo with Nostr data - existingRepo.nostrRepo = nostrRepo; - existingRepo.description = nostrRepo.description; - existingRepo.tags = nostrRepo.tags; - existingRepo.webUrls = nostrRepo.webUrls; - existingRepo.cloneUrls = nostrRepo.cloneUrls; - existingRepo.maintainers = nostrRepo.maintainers; - existingRepo.relays = nostrRepo.relays; - - // Update status based on local presence - if (existingRepo.localProject) { - existingRepo.status = 'synced'; - } - } else { - // Add new remote-only repo - repoMap.set(nostrRepo.id, { - id: nostrRepo.id, - name: nostrRepo.name, - description: nostrRepo.description, - status: 'remote-only', - lastModified: new Date(nostrRepo.event.created_at * 1000), - nostrRepo, - tags: nostrRepo.tags, - webUrls: nostrRepo.webUrls, - cloneUrls: nostrRepo.cloneUrls, - maintainers: nostrRepo.maintainers, - relays: nostrRepo.relays, - }); - } - } - - // Convert map to array and sort by last modified - const repos = Array.from(repoMap.values()).sort((a, b) => - b.lastModified.getTime() - a.lastModified.getTime() - ); - - return repos; - } catch (error) { - console.error('Failed to load unified repos:', error); - return []; - } - }, - enabled: !!user?.pubkey, - staleTime: 30 * 1000, // 30 seconds - gcTime: 60 * 1000, // 1 minute - }); -} \ No newline at end of file diff --git a/src/pages/Index.tsx b/src/pages/Index.tsx index 5e8481d0..785d2757 100644 --- a/src/pages/Index.tsx +++ b/src/pages/Index.tsx @@ -5,16 +5,13 @@ import { useProjectsManager } from '@/hooks/useProjectsManager'; import { useOnboarding } from '@/hooks/useOnboarding'; import { useLocalStorage } from '@/hooks/useLocalStorage'; import { useCurrentUser } from '@/hooks/useCurrentUser'; -import { useRepos } from '@/hooks/useRepos'; import { ProjectSidebar } from '@/components/ProjectSidebar'; import { OnboardingDialog } from '@/components/onboarding'; -import { RepoCard } from '@/components/RepoCard'; import { Button } from '@/components/ui/button'; import { Textarea } from '@/components/ui/textarea'; import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'; -import { Skeleton } from '@/components/ui/skeleton'; -import { Plus, Folder, Menu, Columns2, Sparkles } from 'lucide-react'; +import { Plus, Menu, Columns2, Sparkles } from 'lucide-react'; import { useIsMobile } from '@/hooks/useIsMobile'; import { useSeoMeta } from '@unhead/react'; import { cn } from '@/lib/utils'; @@ -28,7 +25,6 @@ export default function Index() { const projectsManager = useProjectsManager(); const isMobile = useIsMobile(); const { user: _user } = useCurrentUser(); - const { data: repos = [], isLoading, error, refetch } = useRepos(); const { hasCompletedOnboarding, currentStep, @@ -89,8 +85,6 @@ export default function Index() { setIsCreating(true); try { const project = await projectsManager.createProject(prompt.trim()); - // Refresh repos after creating a new project - refetch(); navigate(`/project/${project.id}`); } catch (error) { console.error('Failed to create project:', error); @@ -99,10 +93,7 @@ export default function Index() { } }; - const handleRepoRefresh = () => { - refetch(); - loadProjects(); - }; + const handleProjectSelect = (project: Project | null) => { if (project) { @@ -227,47 +218,7 @@ export default function Index() { -
-

Your Repositories

- {isLoading ? ( -
- {[...Array(6)].map((_, i) => ( - - - - - - - ))} -
- ) : error ? ( - - -

Failed to load repositories

-
-
- ) : repos.length === 0 ? ( - - -
- -
-

No repositories yet. Create your first project above!

-
-
- ) : ( -
- {repos.map((repo) => ( - - ))} -
- )} -
@@ -282,7 +233,7 @@ export default function Index() { onProjectCreated={(projectId) => { console.log('Project created during onboarding:', projectId); setStoredPrompt(''); - handleRepoRefresh(); + loadProjects(); }} /> @@ -303,7 +254,7 @@ export default function Index() { // Handle project creation during onboarding console.log('Project created during onboarding:', projectId); setStoredPrompt(''); // Clear stored prompt after project creation - handleRepoRefresh(); + loadProjects(); }} />
@@ -401,47 +352,7 @@ export default function Index() {
-
-

Your Repositories

- {isLoading ? ( -
- {[...Array(6)].map((_, i) => ( - - - - - - - ))} -
- ) : error ? ( - - -

Failed to load repositories

-
-
- ) : repos.length === 0 ? ( - - -
- -
-

No repositories yet. Create your first project above!

-
-
- ) : ( -
- {repos.map((repo) => ( - - ))} -
- )} -