Skip to content

Commit 2c217d3

Browse files
lazzymsO2sa
authored andcommitted
feat: enhance user avatar handling in comparison table and update GitHub user data fetching
1 parent 990dc64 commit 2c217d3

2 files changed

Lines changed: 9 additions & 9 deletions

File tree

components/comparison-table.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ export function ComparisonTable({ user1, user2 }: ComparisonTableProps) {
1212
return (
1313
<div className="grid md:grid-cols-2 gap-6">
1414
{[user1, user2].map((user, idx) => (
15-
<Card key={user.username} className="overflow-hidden transition-all hover:shadow-lg">
15+
<Card key={`${user.username}-${idx}`} className="overflow-hidden transition-all hover:shadow-lg">
1616
<CardHeader className={`pb-4 ${user.isWinner ? "border-b-2 border-primary/30" : "border-b-2 border-muted"}`}>
1717
<CardTitle className="flex items-center justify-between">
1818
<div className="flex items-center gap-3">
1919
<Image
2020
src={user.avatarUrl}
21-
alt={user.username}
21+
alt={`${user.name || user.username}'s avatar`}
2222
width={40}
2323
height={40}
2424
className="rounded-full ring-2 ring-border"

lib/github.ts

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { ContributionTotals, GitHubUserData, PullRequestNode, RepoNode } from "@/types/github";
2+
import { graphql } from "@octokit/graphql";
23

34
type GitHubRawUser = {
45
name: string | null;
@@ -7,7 +8,6 @@ type GitHubRawUser = {
78
pullRequests: { nodes: PullRequestNode[] };
89
contributionsCollection: ContributionTotals;
910
};
10-
import { graphql } from "@octokit/graphql";
1111

1212
if (!process.env.GITHUB_TOKEN) {
1313
throw new Error("Missing GITHUB_TOKEN");
@@ -24,7 +24,7 @@ const QUERY = /* GraphQL */ `
2424
query FetchUserData($login: String!, $repoCount: Int = 100, $prCount: Int = 100) {
2525
user(login: $login) {
2626
name
27-
avatarUrl
27+
avatarUrl(size: 80)
2828
repositories(
2929
first: $repoCount
3030
privacy: PUBLIC
@@ -77,10 +77,10 @@ export async function fetchGitHubUserData(
7777
}
7878

7979
return {
80-
name: user.name as string | null,
81-
avatarUrl: user.avatarUrl as string,
82-
repos: user.repositories.nodes as RepoNode[],
83-
pullRequests: user.pullRequests.nodes as PullRequestNode[],
84-
contributions: user.contributionsCollection as ContributionTotals,
80+
name: user.name,
81+
avatarUrl: user.avatarUrl,
82+
repos: user.repositories.nodes,
83+
pullRequests: user.pullRequests.nodes,
84+
contributions: user.contributionsCollection,
8585
};
8686
}

0 commit comments

Comments
 (0)