--- import { getDatabase, schema } from "@/db"; import { getInboxItems } from "@/lib/inbox"; import BaseLayout from "@/layouts/BaseLayout.astro"; import { and, desc, eq, inArray, or } from "drizzle-orm"; import { BookMarked, Star, GitFork, Plus, Search, GitPullRequest, CircleDot, Layers, Inbox, Clock, Compass, ArrowRight } from "lucide-react"; const user = Astro.locals.user; if (!user) { return Astro.redirect("/login"); } const db = getDatabase(); // Fetch user's repositories const repos = await db.query.repositories.findMany({ where: eq(schema.repositories.ownerId, user.id), orderBy: [desc(schema.repositories.updatedAt)], }); const inboxItems = await getInboxItems(user.id); // Calculate stats const totalStars = repos.reduce((sum, r) => sum + (r.starCount || 0), 0); const totalForks = repos.reduce((sum, r) => sum + (r.forkCount || 0), 0); function timeAgo(date: string | Date) { const seconds = Math.floor( (new Date().getTime() - new Date(date).getTime()) / 1000, ); if (seconds < 60) return "just now"; if (seconds < 3600) return `${Math.floor(seconds / 60)}m ago`; if (seconds < 86400) return `${Math.floor(seconds / 3600)}h ago`; return `${Math.floor(seconds / 86400)}d ago`; } // Fetch Activity Feed const following = await db.query.userFollowers.findMany({ where: eq(schema.userFollowers.followerId, user.id), }); const followingIds = following.map((f) => f.followeeId); const activities = await db.query.activities.findMany({ where: or( eq(schema.activities.userId, user.id), followingIds.length > 0 ? inArray(schema.activities.userId, followingIds) : undefined, ), orderBy: [desc(schema.activities.createdAt)], limit: 20, with: { user: true, repository: true, }, }); ---
{user.avatarUrl ? ( {user.username} ) : (
{user.username[0]?.toUpperCase()}
)}

Welcome back, {user.displayName || user.username}

Your personal hub for repositories, reviews, and activity

Repositories
{repos.length}
Total Stars
{totalStars}
Total Forks
{totalForks}
{inboxItems.length > 0 && ( )}

Recent Activity

Explore feed
{activities.length > 0 ? (
{activities.map((activity) => { const payload = activity.payload ? JSON.parse(activity.payload) : {}; return (
{activity.user?.avatarUrl ? ( {activity.user.username} ) : (
{activity.user?.username?.[0]?.toUpperCase() || "?"}
)}

@{activity.user?.username} {" "} {activity.type === "create_repo" && "created repository"} {activity.type === "star" && "starred"} {activity.type === "fork" && "forked"} {activity.type === "follow" && "started following"} {activity.type === "issue" && `opened issue #${payload.number || ""} in`} {activity.type === "open_pr" && `opened pull request #${payload.number || ""} in`} {!["create_repo", "star", "fork", "follow", "issue", "open_pr"].includes(activity.type) && `${activity.action || ""} ${activity.type}`} {" "} {activity.repository && ( {activity.repository.name} )} {!activity.repository && activity.type === "follow" && ( @{payload.targetUsername} )}

{timeAgo(activity.createdAt)}

); })}
) : (

No recent activity

Follow developers and star repositories to see updates on your timeline.

Explore community
)}