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

-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
});
}