Skip to content

Commit af35f64

Browse files
committed
migrate to new rank/user keys
1 parent 5afafcb commit af35f64

File tree

15 files changed

+165
-208
lines changed

15 files changed

+165
-208
lines changed

app/by/[rankingType]/[page]/page.tsx

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,31 +19,31 @@ import { ProfileAvatar } from './components/profile-avatar';
1919
const ITEMS_PER_PAGE = 100;
2020

2121
function getConfigByRankingType(rankingType: string) {
22-
let propName: 'contributedStars' | 'followersCount' | 'ownedStars';
22+
let propName: 'c' | 'f' | 's';
2323
let queryOrder: RankOrder;
2424
let title: string;
2525
let subtitle: string;
2626
let rankingBaseEntity: string;
2727

2828
switch (rankingType) {
2929
case 'contributions':
30-
queryOrder = RankOrder.StarsContributed;
31-
propName = 'contributedStars';
30+
queryOrder = RankOrder.Contributions;
31+
propName = 'c';
3232
title = 'Contribution ranking';
3333
subtitle = "Rank is based on the stars from repositories where you've merged pull requests — excluding your own.";
3434
rankingBaseEntity = 'Stars';
3535
break;
3636
case 'followers':
37-
queryOrder = RankOrder.FollowersCount;
38-
propName = 'followersCount';
37+
queryOrder = RankOrder.Followers;
38+
propName = 'f';
3939
title = 'Followers ranking';
4040
subtitle = 'Rank is based on the number of followers the user has on GitHub.';
4141
rankingBaseEntity = 'Followers';
4242
break;
4343
case 'stars':
4444
default:
45-
queryOrder = RankOrder.StarsOwned;
46-
propName = 'ownedStars';
45+
queryOrder = RankOrder.Stars;
46+
propName = 's';
4747
title = 'Star ranking';
4848
subtitle = 'Rank is based on the total number of stars across repositories owned by a user.';
4949
rankingBaseEntity = 'Stars';

app/by/[rankingType]/[page]/rank-list.query.gql

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
query Rankings($order: RankOrder, $offset: Int) {
22
rankings(order: $order, offset: $offset) {
33
githubId
4-
contributedStars
5-
contributedStarsM
6-
followersCount
7-
followersCountM
8-
ownedStars
9-
ownedStarsM
4+
c
5+
cM
6+
f
7+
fM
8+
s
9+
sM
1010
user {
1111
login
1212
avatarUrl
13-
ownedStars
14-
contributedStars
15-
followersCount
13+
s
14+
c
15+
f
1616
location
1717
}
1818
}

app/profile/[login]/components/layout-left-column.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export const LayoutLeftColumn: FC<LayoutLeftColumnProps> = ({ user, children, cl
7272
Icon={Timer}
7373
/>
7474
<ProfileListItem
75-
value={`${user.followersCount?.toLocaleString('en-US')} followers • ${user.followingCount?.toLocaleString(
75+
value={`${user.f?.toLocaleString('en-US')} followers • ${user.followingCount?.toLocaleString(
7676
'en-US',
7777
)} following`}
7878
Icon={UsersRound}

app/profile/[login]/components/ranks-overview.tsx

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,28 +18,20 @@ export const RanksOverview: FC<RanksOverviewProps> = ({ ranksData, login }) => {
1818
<ProfileCardContent>
1919
<div className="flex items-center">
2020
⭐&nbsp;&nbsp;Stars rank:&nbsp;
21-
<RankNumber
22-
rank={ranksData?.ownedStars}
23-
rankPrevious={ranksData?.ownedStarsM}
24-
rankProvisional={ranksData?.ownedStarsProvisional}
25-
/>
21+
<RankNumber rank={ranksData?.s} rankPrevious={ranksData?.sM} rankProvisional={ranksData?.sProvisional} />
2622
</div>
2723
<div className="flex items-center">
2824
🔀&nbsp;&nbsp;Contributor rank:&nbsp;
2925
<RankNumber
30-
rank={ranksData?.contributedStars}
31-
rankPrevious={ranksData?.contributedStarsM}
32-
rankProvisional={ranksData?.contributedStarsProvisional}
26+
rank={ranksData?.c}
27+
rankPrevious={ranksData?.cM}
28+
rankProvisional={ranksData?.cProvisional}
3329
showDelta={false}
3430
/>
3531
</div>
3632
<div className="flex items-center">
3733
👥&nbsp;&nbsp;Followers rank:&nbsp;
38-
<RankNumber
39-
rank={ranksData?.followersCount}
40-
rankPrevious={ranksData?.followersCountM}
41-
rankProvisional={ranksData?.followersCountProvisional}
42-
/>
34+
<RankNumber rank={ranksData?.f} rankPrevious={ranksData?.fM} rankProvisional={ranksData?.fProvisional} />
4335
</div>
4436
</ProfileCardContent>
4537
<ProfileCardActions>

app/profile/[login]/components/repositories-overiview.tsx

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,17 +11,17 @@ type RepositoriesOverviewProps = {
1111
topRepoStars?: number;
1212
contributedRepoCount?: number | null;
1313
repositoriesCount?: number | null;
14-
ownedStars: User['ownedStars'];
15-
contributedStars: User['contributedStars'];
14+
s: User['s'];
15+
c: User['c'];
1616
login: string;
1717
};
1818

1919
export const RepositoriesOverview: FC<RepositoriesOverviewProps> = ({
2020
topRepoStars,
2121
repositoriesCount,
2222
contributedRepoCount,
23-
ownedStars,
24-
contributedStars,
23+
s,
24+
c,
2525
login,
2626
}) => {
2727
return (
@@ -30,15 +30,15 @@ export const RepositoriesOverview: FC<RepositoriesOverviewProps> = ({
3030
<ProfileCardContent>
3131
<p>
3232
📦&nbsp;&nbsp;Owns {repositoriesCount ?? 0} repos
33-
{!!ownedStars && ` • ⭐ ${ownedStars?.toLocaleString('en-US')} total`}
33+
{!!s && ` • ⭐ ${s?.toLocaleString('en-US')} total`}
3434
</p>
3535
<p>
3636
🏆&nbsp;&nbsp;Top repository
3737
{topRepoStars ? ` • ⭐ ${topRepoStars?.toLocaleString('en-US')}` : ' not found ( •_•) 🔍'}
3838
</p>
3939
<p>
4040
🤝&nbsp;&nbsp;Contributed to {contributedRepoCount} repos
41-
{!!contributedRepoCount && ` • ⭐ ${contributedStars?.toLocaleString('en-US')} total`}
41+
{!!contributedRepoCount && ` • ⭐ ${c?.toLocaleString('en-US')} total`}
4242
</p>
4343
</ProfileCardContent>
4444
<ProfileCardActions>

app/profile/[login]/page.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ export async function generateMetadata({ params }: { params: Promise<{ login: st
1616
return { title: 'GitHub Profile Analytics & Rankings · GitRanks' };
1717
}
1818

19-
const { ownedStars, contributedStars, followersCount } = user.rank ?? {};
19+
const { s, c, f } = user.rank ?? {};
2020

2121
return {
2222
title: `${login} – GitHub Profile Analytics & Rankings · GitRanks`,
23-
description: `Explore GitHub analytics for ${login} – ranked #${ownedStars} by stars, #${contributedStars} by contributions, and #${followersCount} by followers. See how your code impacts the world and where you stand in the global developer community with GitRanks.`,
23+
description: `Explore GitHub analytics for ${login} – ranked #${s} by stars, #${c} by contributions, and #${f} by followers. See how your code impacts the world and where you stand in the global developer community with GitRanks.`,
2424
openGraph: {
2525
images: [user.avatarUrl!],
2626
},
@@ -50,8 +50,8 @@ export default async function Profile({ params }: { params: Promise<{ login: str
5050
topRepoStars={user.repositories?.[0]?.stargazerCount ?? 0}
5151
contributedRepoCount={user.contributedRepoCount}
5252
repositoriesCount={user.repositoriesCount}
53-
ownedStars={user.ownedStars}
54-
contributedStars={user.contributedStars}
53+
s={user.s}
54+
c={user.c}
5555
login={login}
5656
/>
5757
</div>

app/profile/[login]/profile-summary.gql

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ query User($login: String!) {
2626
login
2727
avatarUrl
2828
location
29-
followersCount
30-
ownedStars
31-
contributedStars
29+
f
30+
s
31+
c
3232
company
3333
email
3434
followingCount
@@ -74,18 +74,15 @@ query User($login: String!) {
7474
createdAt
7575
}
7676
rank {
77-
ownedStars
78-
ownedStarsProvisional
79-
ownedStarsM
80-
ownedStarsY
81-
contributedStars
82-
contributedStarsProvisional
83-
contributedStarsM
84-
contributedStarsY
85-
followersCount
86-
followersCountProvisional
87-
followersCountM
88-
followersCountY
77+
s
78+
sProvisional
79+
sM
80+
c
81+
cProvisional
82+
cM
83+
f
84+
fProvisional
85+
fM
8986
}
9087
}
9188
}

app/profile/[login]/ranks/components/rank-card.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { ProfileCard, ProfileCardContent, ProfileCardHeader } from '../../compon
1111
type RankCardProps = {
1212
rank?: number | null;
1313
rankM?: number | null;
14-
rankY?: number | null;
1514
rankProvisional?: number | null;
1615
showDelta?: boolean;
1716
title: string;
@@ -24,7 +23,6 @@ export const RankCard: FC<RankCardProps> = ({
2423
rank,
2524
rankProvisional,
2625
rankM,
27-
rankY,
2826
title,
2927
entityValue,
3028
entityName,
@@ -43,19 +41,14 @@ export const RankCard: FC<RankCardProps> = ({
4341
{!!rankPercentile && (
4442
<RankCardItem Icon={Trophy}>You&apos;re in the top {rankPercentile}% of all users!</RankCardItem>
4543
)}
46-
{(rank !== rankM || rank !== rankY) && showDelta !== false && (
44+
{rank !== rankM && showDelta !== false && (
4745
<RankCardItem Icon={TrendingUp}>
4846
<span>
4947
Trend:{' '}
5048
{rank !== rankM && (
5149
<>
5250
<RankDelta current={rank} previous={rankM} className="text-base" /> this month;
5351
</>
54-
)}{' '}
55-
{rank !== rankY && (
56-
<>
57-
<RankDelta current={rank} previous={rankY} className="text-base" /> this year
58-
</>
5952
)}
6053
</span>
6154
</RankCardItem>

app/profile/[login]/ranks/page.tsx

Lines changed: 14 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,57 +17,41 @@ export default async function ProfileRanks({ params }: { params: Promise<{ login
1717
notFound();
1818
}
1919

20-
const {
21-
ownedStars,
22-
contributedStars,
23-
contributedStarsM,
24-
contributedStarsY,
25-
followersCount,
26-
ownedStarsProvisional,
27-
contributedStarsProvisional,
28-
followersCountProvisional,
29-
ownedStarsM,
30-
followersCountM,
31-
ownedStarsY,
32-
followersCountY,
33-
} = user.rank ?? {};
20+
const { s, c, cM, f, sProvisional, cProvisional, fProvisional, sM, fM } = user.rank ?? {};
3421

35-
const bestRankType = getBestRankType({ ownedStars, contributedStars, followersCount });
22+
const bestRankType = getBestRankType({ s, c, f });
3623

3724
return (
3825
<LayoutLeftColumn user={user}>
3926
<div>
4027
<div className="flex flex-col md:flex-row flex-wrap gap-6">
4128
<RankCard
42-
rank={ownedStars}
43-
rankM={ownedStarsM}
44-
rankY={ownedStarsY}
45-
rankProvisional={ownedStarsProvisional}
29+
rank={s}
30+
rankM={sM}
31+
rankProvisional={sProvisional}
4632
title="Stars rank"
47-
entityValue={user.ownedStars}
33+
entityValue={user.s}
4834
entityName="stars"
4935
description="Rank is based on the total number of stars across repositories owned by the user."
5036
/>
5137

5238
<RankCard
53-
rank={followersCount}
54-
rankM={followersCountM}
55-
rankY={followersCountY}
56-
rankProvisional={followersCountProvisional}
39+
rank={f}
40+
rankM={fM}
41+
rankProvisional={fProvisional}
5742
showDelta={false}
5843
title="Followers rank"
59-
entityValue={user.followersCount}
44+
entityValue={user.f}
6045
entityName="followers"
6146
description="Rank is based on the number of followers the user has on GitHub."
6247
/>
6348

6449
<RankCard
65-
rank={contributedStars}
66-
rankM={contributedStarsM}
67-
rankY={contributedStarsY}
68-
rankProvisional={contributedStarsProvisional}
50+
rank={c}
51+
rankM={cM}
52+
rankProvisional={cProvisional}
6953
title="Contributor rank"
70-
entityValue={user.contributedStars}
54+
entityValue={user.c}
7155
entityName="stars"
7256
description="Rank is based on the total number of stars across repositories where the user has merged pull requests —
7357
excluding their own repositories."

app/profile/[login]/ranks/utils/get-best-rank-type.ts

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
import { RankingType } from '@/types/ranking.types';
22

3-
export function getBestRankType(params: {
4-
ownedStars?: number | null;
5-
contributedStars?: number | null;
6-
followersCount?: number | null;
7-
}): RankingType {
8-
const { ownedStars, contributedStars, followersCount } = params;
3+
export function getBestRankType(params: { s?: number | null; c?: number | null; f?: number | null }): RankingType {
4+
const { s, c, f } = params;
95

10-
if (
11-
(ownedStars || Infinity) < (contributedStars || Infinity) &&
12-
(ownedStars || Infinity) < (followersCount || Infinity)
13-
) {
6+
if ((s || Infinity) < (c || Infinity) && (s || Infinity) < (f || Infinity)) {
147
return RankingType.Star;
158
}
169

17-
if ((contributedStars || Infinity) < (followersCount || Infinity)) {
10+
if ((c || Infinity) < (f || Infinity)) {
1811
return RankingType.Contribution;
1912
}
2013

0 commit comments

Comments
 (0)