From a7b45b5068c8e4b320a0050a6e402b8bd95f4e2a Mon Sep 17 00:00:00 2001 From: lemonknowsall Date: Sat, 10 Jan 2026 17:25:14 -0800 Subject: [PATCH] update repo card design and add clickable tags --- src/components/RepositoryCard.tsx | 74 ++++++++++++++++++++++++++----- src/pages/Explore.tsx | 2 + 2 files changed, 64 insertions(+), 12 deletions(-) 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 */}
-

- {repo.name} -

+
+

+ {repo.name} +

+ + {formatRelativeTime(repo.created_at)} + +
{canZap && ( @@ -233,8 +263,8 @@ function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata }: Reposi {/* Author */}
-
- +
+ {profileImage && ( )} @@ -242,7 +272,20 @@ function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata }: Reposi {displayName.slice(0, 2).toUpperCase()} - {displayName} +
+ + {metadata?.nip05 && ( + {metadata.nip05} + )} +
@@ -257,14 +300,21 @@ function RepositoryCardInner({ repo, authorMetadata: preloadedMetadata }: Reposi {repo.repoTags.length > 0 && (
{repo.repoTags.slice(0, 3).map((tag, index) => ( - - {tag} - + ))} {repo.repoTags.length > 3 && ( - + +{repo.repoTags.length - 3} - + )}
)} diff --git a/src/pages/Explore.tsx b/src/pages/Explore.tsx index c4ce3acb..eaa10845 100644 --- a/src/pages/Explore.tsx +++ b/src/pages/Explore.tsx @@ -236,6 +236,7 @@ export default function Explore() { key={repo.id} repo={repo} authorMetadata={authorMetadataMap.get(repo.pubkey)} + onTagClick={(tag) => setSearchQuery(tag)} /> ))}
@@ -306,6 +307,7 @@ export default function Explore() { key={repo.id} repo={repo} authorMetadata={authorMetadataMap.get(repo.pubkey)} + onTagClick={(tag) => setSearchQuery(tag)} /> ))}