Skip to content
Merged
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
14 changes: 3 additions & 11 deletions src/app/[locale]/user/[username]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const dynamicParams = true;

type Props = {
params: Promise<{ locale?: string; username: string }>;
searchParams?: Promise<{ country?: string }>;
};

export async function generateMetadata({ params }: Props): Promise<Metadata> {
Expand Down Expand Up @@ -85,13 +84,9 @@ export async function generateMetadata({ params }: Props): Promise<Metadata> {
};
}

export default async function UserProfilePage({ params, searchParams }: Props) {
export default async function UserProfilePage({ params }: Props) {
const { username } = await params;
const cleanUsername = decodeURIComponent(username.trim());
const profileUrl = toAbsoluteUrl(`/user/${cleanUsername}`);

const resolvedSearchParams = searchParams ? await searchParams : undefined;
const countryParam = resolvedSearchParams?.country;

let profileData: Awaited<ReturnType<typeof getUserProfile>> | null = null;
let fetchErrorMessage: string | null = null;
Expand All @@ -104,9 +99,6 @@ export default async function UserProfilePage({ params, searchParams }: Props) {
source: "ssr",
routeOrJob: "/[locale]/user/[username]",
target: { username: cleanUsername },
context: {
...(countryParam ? { countryParam } : {}),
},
});
}

Expand All @@ -120,14 +112,14 @@ export default async function UserProfilePage({ params, searchParams }: Props) {

const { user, location } = profileData;
const profilePageSchema = buildUserProfileSchema(user, location);
const breadcrumbSchema = buildUserBreadcrumbSchema(user, location, countryParam);
const breadcrumbSchema = buildUserBreadcrumbSchema(user, location);

return (
<div className="mx-auto w-full max-w-5xl flex-1 px-4 py-8">
<JsonLd data={profilePageSchema} />
<JsonLd data={breadcrumbSchema} />

<UserProfileClient user={user} location={location} countryParam={countryParam} />
<UserProfileClient user={user} location={location} />
</div>
);
}
41 changes: 18 additions & 23 deletions src/features/developer/components/user-profile-client.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
"use client";
import { useEffect, useMemo, useState } from "react";
import { useSearchParams } from "next/navigation";
import type { Route } from "next";
import { useClipboardCopy } from "@/hooks";
import {
Expand Down Expand Up @@ -51,12 +50,10 @@ const countries = countriesData as CountryInfo[];
type Props = {
user: UserResult;
location?: string | null;
countryParam?: string | null;
};

export function UserProfileClient({ user, location, countryParam }: Props) {
export function UserProfileClient({ user, location }: Props) {
const { t } = useTranslation();
const searchParams = useSearchParams();
const { copied, copy } = useClipboardCopy();
const { copied: markdownCopied, copy: copyMarkdown } = useClipboardCopy();
const { copied: htmlCopied, copy: copyHtml } = useClipboardCopy();
Expand Down Expand Up @@ -110,26 +107,22 @@ export function UserProfileClient({ user, location, countryParam }: Props) {
};
}, [badgeDialogOpen]);

// Location & Country detection
const detectedSlug = detectCountry(location ?? null);
const rawCountry = (countryParam || searchParams.get("country") || detectedSlug || "")
.trim()
// Location & Country detection (purely from user info)
const detectedSlug = detectCountry(location ?? null)
?.trim()
.toLowerCase();
const activeCountrySlug = rawCountry ? rawCountry.replace(/[^a-z0-9_-]/g, "") : null;

const activeCountryInfo = activeCountrySlug
? (countries.find((c) => c.slug.toLowerCase() === activeCountrySlug) ?? {
slug: activeCountrySlug,
title: activeCountrySlug
const detectedCountryInfo = detectedSlug
? (countries.find((c) => c.slug.toLowerCase() === detectedSlug) ?? {
slug: detectedSlug,
title: detectedSlug
.split("_")
.filter(Boolean)
.map((s) => s.charAt(0).toUpperCase() + s.slice(1))
.join(" "),
})
: null;

const flagSlug = activeCountryInfo?.slug || detectedSlug;
const flagCode = flagSlug ? getCountryCode(flagSlug) : null;
const flagCode = detectedSlug ? getCountryCode(detectedSlug) : null;

const handleCopyLink = () => copy(window.location.href);

Expand All @@ -149,15 +142,15 @@ export function UserProfileClient({ user, location, countryParam }: Props) {
{/* ── Breadcrumb & Back Navigation ────────────────────────────── */}
<div className="flex flex-wrap items-center justify-between gap-3 text-sm">
<div className="flex items-center gap-2">
{activeCountryInfo ? (
<Link href={`/leaderboard/${activeCountryInfo.slug}` as Route}>
{detectedCountryInfo ? (
<Link href={`/leaderboard/${detectedCountryInfo.slug}` as Route}>
<Button
variant="ghost"
size="sm"
className="gap-1.5 text-muted-foreground hover:text-foreground"
>
<ArrowLeft className="h-4 w-4 rtl:-scale-x-100" />
<span>{t("profile.backToCountry", { country: activeCountryInfo.title })}</span>
<span>{t("profile.backToCountry", { country: detectedCountryInfo.title })}</span>
</Button>
</Link>
) : (
Expand Down Expand Up @@ -186,14 +179,14 @@ export function UserProfileClient({ user, location, countryParam }: Props) {
<Link href="/leaderboard" className="transition-colors hover:text-foreground">
{t("profile.breadcrumbs.leaderboards")}
</Link>
{activeCountryInfo ? (
{detectedCountryInfo ? (
<>
<span>/</span>
<Link
href={`/leaderboard/${activeCountryInfo.slug}` as Route}
href={`/leaderboard/${detectedCountryInfo.slug}` as Route}
className="transition-colors hover:text-foreground"
>
{activeCountryInfo.title}
{detectedCountryInfo.title}
</Link>
</>
) : null}
Expand Down Expand Up @@ -623,7 +616,9 @@ export function UserProfileClient({ user, location, countryParam }: Props) {
<h2 id="badge-dialog-title" className="text-lg font-semibold">
{t("profile.getBadge")}
</h2>
<p className="mt-1 text-sm text-muted-foreground">{t("profile.badgeDescription")}</p>
<p className="mt-1 text-sm text-muted-foreground">
{t("profile.badgeDescription")}
</p>
</div>
<button
type="button"
Expand Down
10 changes: 4 additions & 6 deletions src/features/developer/services/developer-seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,12 @@ export function buildUserProfileSchema(user: UserResult, location?: string | nul
};
}

export function buildUserBreadcrumbSchema(
user: UserResult,
location?: string | null,
countryParam?: string,
) {
export function buildUserBreadcrumbSchema(user: UserResult, location?: string | null) {
const displayName = user.name?.trim() || user.username;
const profileUrl = toAbsoluteUrl(`/user/${user.username}`);
const detectedSlug = (countryParam || detectCountry(location ?? null))?.trim().toLowerCase();
const detectedSlug = detectCountry(location ?? null)
?.trim()
.toLowerCase();
const countryInfo = detectedSlug
? countries.find((c) => c.slug.toLowerCase() === detectedSlug)
: null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,6 @@ export function CountryLeaderboardClient({
users={scored}
failedUsers={errors}
title={title}
countrySlug={countrySlug}
totalFromSource={totalFromSource}
usersProcessed={scored.length}
/>
Expand Down
8 changes: 1 addition & 7 deletions src/features/leaderboard/components/leaderboard-table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ type Props = {
users: LeaderboardEntry[];
failedUsers: string[];
title: string;
countrySlug?: string;
totalFromSource: number;
usersProcessed: number;
};
Expand Down Expand Up @@ -72,7 +71,6 @@ export function LeaderboardTable({
users,
failedUsers,
title,
countrySlug,
totalFromSource,
usersProcessed,
}: Props) {
Expand Down Expand Up @@ -349,11 +347,7 @@ export function LeaderboardTable({
</td>
<td className="px-3 py-3">
{(() => {
const profileUrl = (
countrySlug
? `/user/${user.username}?country=${encodeURIComponent(countrySlug)}`
: `/user/${user.username}`
) as Route;
const profileUrl = `/user/${user.username}` as Route;

return (
<div className="flex items-center gap-2">
Expand Down
29 changes: 29 additions & 0 deletions src/features/leaderboard/tests/leaderboard-table.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
default: ({
children,
href,
prefetch: _prefetch,

Check warning on line 13 in src/features/leaderboard/tests/leaderboard-table.test.tsx

View workflow job for this annotation

GitHub Actions / Validate (Node 24.x)

'_prefetch' is defined but never used
...props
}: {
children: React.ReactNode;
Expand Down Expand Up @@ -61,7 +61,7 @@
const actual = await importOriginal<Record<string, unknown>>();
return {
...actual,
Avatar: ({ src, alt }: { src: string; alt: string }) => <img src={src} alt={alt} />,

Check warning on line 64 in src/features/leaderboard/tests/leaderboard-table.test.tsx

View workflow job for this annotation

GitHub Actions / Validate (Node 24.x)

Using `<img>` could result in slower LCP and higher bandwidth. Consider using `<Image />` from `next/image` or a custom image loader to automatically optimize images. This may incur additional usage or cost from your provider. See: https://nextjs.org/docs/messages/no-img-element
};
});

Expand Down Expand Up @@ -428,4 +428,33 @@

expect(screen.getByText("Showing 1–100 of 150")).toBeDefined();
});

test("renders canonical /user links without ?country", () => {
render(
<LeaderboardTable
users={[
{
username: "alice",
name: "Alice",
avatarUrl: "https://example.com/alice.png",
impactRank: 1,
finalScore: 80,
repoScore: 30,
prScore: 20,
contributionScore: 40,
},
]}
failedUsers={[]}
title="Worldwide"
totalFromSource={1}
usersProcessed={1}
/>,
);

const profileLinks = screen.getAllByRole("link", { name: "Alice" });
expect(profileLinks).toHaveLength(2);
for (const link of profileLinks) {
expect(link.getAttribute("href")).toBe("/user/alice");
}
});
});
Loading