Remove repos list from homepage

This commit is contained in:
Alex Gleason committed 2025-08-20 13:52:35 -05:00
1 parent 3accc0e158
commit c649698806
3 files changed
+4 -588

No files matched your search

-272
View File
@@ -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 <HardDrive className="h-4 w-4 text-blue-500" />;
case 'published':
return <Upload className="h-4 w-4 text-green-500" />;
case 'remote-only':
return <Cloud className="h-4 w-4 text-orange-500" />;
case 'synced':
return <RefreshCw className="h-4 w-4 text-emerald-500" />;
}
};
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 (
<Card
className={cn(
"transition-all duration-300 bg-gradient-to-br from-card to-card/80 border-primary/10 hover:border-primary/20",
canOpen && "cursor-pointer hover:shadow-xl hover:shadow-primary/10 hover:scale-[1.02]",
className
)}
onClick={canOpen ? handleCardClick : undefined}
tabIndex={canOpen ? 0 : undefined}
onKeyDown={canOpen ? (e) => {
if (e.key === 'Enter' || e.key === ' ') {
e.preventDefault();
handleCardClick();
}
} : undefined}
>
<CardHeader className="pb-2">
<div className="flex items-start justify-between">
<div className="flex-1 min-w-0">
<CardTitle className="text-base md:text-lg flex items-center gap-2 truncate">
{repo.status === 'remote-only' ? (
<GitBranch className="h-4 w-4 text-primary flex-shrink-0" />
) : (
<Folder className="h-4 w-4 text-primary flex-shrink-0" />
)}
<span className="truncate">{repo.name}</span>
</CardTitle>
{repo.description && (
<CardDescription className="text-sm mt-1 line-clamp-2">
{repo.description}
</CardDescription>
)}
</div>
<div className="flex items-center gap-2 ml-2">
<Badge variant="outline" className={cn("text-xs", getStatusColor())}>
<span className="flex items-center gap-1">
{getStatusIcon()}
{getStatusText()}
</span>
</Badge>
</div>
</div>
<CardDescription className="text-sm">
Modified {repo.lastModified.toLocaleDateString()}
</CardDescription>
</CardHeader>
<CardContent className="space-y-3">
{/* Tags */}
{repo.tags.length > 0 && (
<div className="flex flex-wrap gap-1">
{repo.tags.slice(0, 3).map((tag) => (
<Badge key={tag} variant="secondary" className="text-xs">
{tag}
</Badge>
))}
{repo.tags.length > 3 && (
<Badge variant="outline" className="text-xs">
+{repo.tags.length - 3}
</Badge>
)}
</div>
)}
{/* Repository info */}
{(repo.maintainers.length > 0 || repo.webUrls.length > 0) && (
<div className="flex items-center gap-4 text-xs text-muted-foreground">
{repo.maintainers.length > 0 && (
<div className="flex items-center gap-1">
<Users className="h-3 w-3" />
<span>{repo.maintainers.length} maintainer{repo.maintainers.length !== 1 ? 's' : ''}</span>
</div>
)}
{repo.webUrls.length > 0 && (
<div className="flex items-center gap-1">
<Globe className="h-3 w-3" />
<span>Web</span>
</div>
)}
</div>
)}
{/* Actions */}
{(canClone || repo.webUrls.length > 0) && (
<div className="flex gap-2" onClick={(e) => e.stopPropagation()}>
{canClone && (
<Button
onClick={handleCloneRepo}
disabled={isCloning}
className="flex-1"
size="sm"
>
{isCloning ? (
<>
<div className="animate-spin rounded-full h-3 w-3 border-b-2 border-white mr-2"></div>
Cloning...
</>
) : (
<>
<Download className="h-3 w-3 mr-2" />
Clone
</>
)}
</Button>
)}
{repo.webUrls.length > 0 && (
<Button
variant="outline"
size="sm"
onClick={() => window.open(repo.webUrls[0], '_blank')}
className="px-3"
>
<ExternalLink className="h-3 w-3" />
</Button>
)}
</div>
)}
</CardContent>
</Card>
);
}
-223
View File
@@ -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<string, UnifiedRepo>();
// 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
});
}
+4 -93
View File
@@ -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() {
</Card>
</div>
<div>
<h2 className="text-xl md:text-2xl font-semibold mb-4 md:mb-6">Your Repositories</h2>
{isLoading ? (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{[...Array(6)].map((_, i) => (
<Card key={i}>
<CardContent className="p-4 md:p-6">
<Skeleton className="h-4 w-3/4 mb-2" />
<Skeleton className="h-3 w-1/2" />
</CardContent>
</Card>
))}
</div>
) : error ? (
<Card className="border-destructive/20">
<CardContent className="py-6 text-center">
<p className="text-destructive">Failed to load repositories</p>
</CardContent>
</Card>
) : repos.length === 0 ? (
<Card className="bg-gradient-to-br from-muted/50 to-muted/20 border-dashed border-2 border-muted-foreground/20">
<CardContent className="text-center py-8 md:py-12">
<div className="flex items-center justify-center gap-2 mb-4">
<Folder className="h-10 w-10 md:h-12 md:w-12 text-muted-foreground" />
</div>
<p className="text-muted-foreground text-sm md:text-base">No repositories yet. Create your first project above!</p>
</CardContent>
</Card>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{repos.map((repo) => (
<RepoCard
key={repo.id}
repo={repo}
onRepoCloned={handleRepoRefresh}
/>
))}
</div>
)}
</div>
</div>
</div>
@@ -282,7 +233,7 @@ export default function Index() {
onProjectCreated={(projectId) => {
console.log('Project created during onboarding:', projectId);
setStoredPrompt('');
handleRepoRefresh();
loadProjects();
}}
/>
</div>
@@ -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();
}}
/>
<div className="min-h-screen flex bg-background">
@@ -401,47 +352,7 @@ export default function Index() {
</Card>
</div>
<div>
<h2 className="text-xl md:text-2xl font-semibold mb-4 md:mb-6">Your Repositories</h2>
{isLoading ? (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{[...Array(6)].map((_, i) => (
<Card key={i}>
<CardContent className="p-4 md:p-6">
<Skeleton className="h-4 w-3/4 mb-2" />
<Skeleton className="h-3 w-1/2" />
</CardContent>
</Card>
))}
</div>
) : error ? (
<Card className="border-destructive/20">
<CardContent className="py-6 text-center">
<p className="text-destructive">Failed to load repositories</p>
</CardContent>
</Card>
) : repos.length === 0 ? (
<Card className="bg-gradient-to-br from-muted/50 to-muted/20 border-dashed border-2 border-muted-foreground/20">
<CardContent className="text-center py-8 md:py-12">
<div className="flex items-center justify-center gap-2 mb-4">
<Folder className="h-10 w-10 md:h-12 md:w-12 text-muted-foreground" />
</div>
<p className="text-muted-foreground text-sm md:text-base">No repositories yet. Create your first project above!</p>
</CardContent>
</Card>
) : (
<div className="grid grid-cols-1 sm:grid-cols-2 lg:grid-cols-3 gap-4">
{repos.map((repo) => (
<RepoCard
key={repo.id}
repo={repo}
onRepoCloned={handleRepoRefresh}
/>
))}
</div>
)}
</div>
</div>
</div>
</div>