Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 33 additions & 44 deletions src/app/u/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import BadgeSection from "@/components/BadgeSection";
import ContributionGraph from "@/components/ContributionGraph";
import StreakTracker from "@/components/StreakTracker";
import TopRepos from "@/components/TopRepos";
import StatsCard from "@/components/StatsCard";
import BackToDashboard from "@/components/BackToDashboard";

interface PublicProfileData {
username: string;
Expand Down Expand Up @@ -50,8 +50,7 @@ export async function generateMetadata({
}): Promise<Metadata> {
const { username } = params;
const profile = await fetchPublicProfile(username);

const baseUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.NEXTAUTH_URL || "http://localhost:3000";
const baseUrl = process.env.NEXT_PUBLIC_APP_URL || process.env.NEXTAUTH_URL || "http://localhost:3000";
const profileUrl = `${baseUrl}/u/${username}`;

if (!profile) {
Expand Down Expand Up @@ -87,53 +86,43 @@ export default async function PublicProfilePage({
const { username } = params;
const profile = await fetchPublicProfile(username);

if (!profile) {
return (
<div className="min-h-screen bg-[var(--background)] p-4 md:p-8 text-[var(--foreground)] transition-colors flex items-center justify-center">
<div className="text-center">
<h1 className="text-3xl md:text-4xl font-bold mb-2">
Profile Not Found
</h1>
<p className="text-[var(--muted-foreground)] mb-6">
This profile is not available or is private.
</p>
<a
href="/"
className="inline-block px-6 py-2 bg-[var(--accent)] text-[var(--accent-foreground)] rounded-lg hover:opacity-90 transition-opacity"
>
Back to Home
</a>
</div>

if (!profile) {
return (
<div className="min-h-screen bg-[var(--background)] p-4 md:p-8 text-[var(--foreground)] transition-colors flex items-center justify-center">
<div className="text-center">
<h1 className="text-3xl md:text-4xl font-bold mb-2">
Profile Not Found
</h1>
<p className="text-[var(--muted-foreground)] mb-6">
This profile is not available or is private.
</p>
<a
href="/"
className="inline-block px-6 py-2 bg-[var(--accent)] text-[var(--accent-foreground)] rounded-lg hover:opacity-90 transition-opacity"
>
Back to Home
</a>
</div>
);
}

const avatarUrl = `https://avatars.githubusercontent.com/${profile.username}`;
const topRepo = profile.repos[0]?.name ?? "";
</div>
);
}


return (
<div className="min-h-screen bg-[var(--background)] p-4 md:p-8 text-[var(--foreground)] transition-colors">
{/* Header */}
<div className="mb-8 flex flex-wrap items-start justify-between gap-4">
<div>
<h1 className="text-3xl md:text-4xl font-bold text-[var(--foreground)]">
@{profile.username}&apos;s Profile
</h1>
<p className="mt-2 text-[var(--muted-foreground)]">
GitHub activity and coding stats
</p>
</div>
{/* Download stats card button — client component */}
<StatsCard
username={profile.username}
avatarUrl={avatarUrl}
currentStreak={profile.streak.current}
longestStreak={profile.streak.longest}
totalCommits={profile.contributions.total}
topRepo={topRepo}
/>
</div>
<div className="mb-8">
<BackToDashboard username={username} />

<h1 className="text-3xl md:text-4xl font-bold text-[var(--foreground)]">
@{profile.username}&apos;s Profile
</h1>

<p className="mt-2 text-[var(--muted-foreground)]">
GitHub activity and coding stats
</p>
</div>
{/* Row 1: Contribution graph + Streak */}
<div className="grid grid-cols-1 lg:grid-cols-3 gap-6">
<div className="lg:col-span-2">
Expand Down
26 changes: 26 additions & 0 deletions src/components/BackToDashboard.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
"use client";

import Link from "next/link";
import { useSession } from "next-auth/react";

interface Props {
username: string;
}

export default function BackToDashboard({ username }: Props) {
const { data: session } = useSession();

const currentUser = session?.githubLogin;
const isOwner = currentUser === username;

if (!isOwner) return null;

return (
<Link
href="/dashboard"
className="inline-block mb-4 text-[var(--muted-foreground)] hover:text-[var(--card-foreground)] transition-colors"
>
← Back to dashboard
</Link>
);
}