diff --git a/src/components/RepositoryCard.tsx b/src/components/RepositoryCard.tsx index 89e01180..dac33308 100644 --- a/src/components/RepositoryCard.tsx +++ b/src/components/RepositoryCard.tsx @@ -36,13 +36,38 @@ import { Zap } from 'lucide-react'; import type { Event } from 'nostr-tools'; import type { NostrMetadata } from '@nostrify/nostrify'; +/** + * Formats a Unix timestamp to a relative time string (e.g., "1 hr.", "4 days", "3 wk.", "10 mo.", "5 yr.") + */ +function formatRelativeTime(timestamp: number): string { + const now = Math.floor(Date.now() / 1000); + const diff = now - timestamp; + + const minutes = Math.floor(diff / 60); + const hours = Math.floor(diff / 3600); + const days = Math.floor(diff / 86400); + const weeks = Math.floor(diff / 604800); + const months = Math.floor(diff / 2592000); // ~30 days + const years = Math.floor(diff / 31536000); // ~365 days + + if (years > 0) return `${years} yr.`; + if (months > 0) return `${months} mo.`; + if (weeks > 0) return `${weeks} wk.`; + if (days > 0) return `${days} days`; + if (hours > 0) return `${hours} hr.`; + if (minutes > 0) return `${minutes} min.`; + return 'just now'; +} + interface RepositoryCardProps { repo: Repository; /** Pre-fetched author metadata to avoid individual fetches */ authorMetadata?: NostrMetadata; + /** Callback when a tag is clicked - receives the tag value */ + onTagClick?: (tag: string) => void; } -function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata }: RepositoryCardProps) { +function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata, onTagClick }: RepositoryCardProps) { // Only fetch author data if not preloaded const { data: authorData } = useAuthor(preloadedMetadata ? undefined : repo.pubkey); const metadata = preloadedMetadata ?? authorData?.metadata; @@ -186,9 +211,14 @@ function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata }: Reposi {/* Header with name and menu */}