Skip to content

Commit 325e446

Browse files
committed
country flag
1 parent f446f73 commit 325e446

File tree

13 files changed

+106
-16
lines changed

13 files changed

+106
-16
lines changed

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,15 @@ import {
1212
PaginationPrevious,
1313
} from '@/components/ui/pagination';
1414
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table';
15+
import { fetchCountryList } from '@/graphql/helpers/fetch-countries';
1516
import { graphqlDirect } from '@/lib/graphql/graphql-direct';
1617
import { GlobalRankingsDocument, RankOrder } from '@/types/generated/graphql';
1718
import { getInitials } from '@/utils/get-initials';
1819

1920
import { ClickableRow } from './components/clickale-row';
2021
import { LinkWithStopPropagation } from './components/link-with-stop-propagation';
2122
import { ProfileAvatar } from './components/profile-avatar';
23+
import { getCountryFlag } from './utils/get-country-flag';
2224

2325
const ITEMS_PER_PAGE = 100;
2426

@@ -64,7 +66,10 @@ export default async function GlobalRanking({ params }: { params: Promise<{ rank
6466
const page = parseInt(pageParam, 10);
6567
const [queryOrder, rankPropName, title, subtitle, rankingBaseEntity] = getConfigByRankingType(rankingType);
6668
const offset = (page - 1) * ITEMS_PER_PAGE;
67-
const data = await graphqlDirect(GlobalRankingsDocument, { order: queryOrder, offset });
69+
const [{ globalRankings }, countries] = await Promise.all([
70+
graphqlDirect(GlobalRankingsDocument, { order: queryOrder, offset }),
71+
fetchCountryList(),
72+
]);
6873

6974
return (
7075
<Page className="max-w-5xl gap-6">
@@ -83,7 +88,7 @@ export default async function GlobalRanking({ params }: { params: Promise<{ rank
8388
</TableRow>
8489
</TableHeader>
8590
<TableBody>
86-
{data.globalRankings.map((item) => {
91+
{globalRankings.map((item) => {
8792
const { githubId, user } = item;
8893
return (
8994
<ClickableRow key={githubId} className="border-b-0" href={`/profile/${user?.login}`}>
@@ -101,7 +106,9 @@ export default async function GlobalRanking({ params }: { params: Promise<{ rank
101106
{user?.login}
102107
</LinkWithStopPropagation>
103108
</TableCell>
104-
<TableCell className="hidden sm:table-cell break-all whitespace-normal">{user?.location}</TableCell>
109+
<TableCell className="hidden sm:table-cell break-all whitespace-normal">
110+
{getCountryFlag(countries, user?.country)} {user?.location}
111+
</TableCell>
105112
<TableCell className="text-right">{user?.[rankPropName]?.toLocaleString('en-US')}</TableCell>
106113
</ClickableRow>
107114
);
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { CountryQuery } from '@/types/generated/graphql';
2+
3+
export const getCountryFlag = (countryList: CountryQuery['country'], country?: string | null) => {
4+
if (!country || !countryList?.length) {
5+
return null;
6+
}
7+
8+
return countryList.find((c) => c.name === country)?.flag || null;
9+
};

app/profile/[login]/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import { ProfileTimeline } from './components/profile-timeline';
99
import { RanksOverview } from './components/ranks-overview';
1010
import { RepositoriesOverview } from './components/repositories-overiview';
1111
import NotFound from './not-found';
12-
import { fetchProfileData } from './utils/fetch-profile-data';
12+
import { fetchProfileData } from '../../../graphql/helpers/fetch-profile-data';
1313

1414
export async function generateMetadata({ params }: { params: Promise<{ login: string }> }): Promise<Metadata> {
1515
const { login } = await params;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ import { notFound } from 'next/navigation';
77

88
import { Button } from '@/components/ui/button';
99

10-
import { LayoutLeftColumn } from '../components/layout-left-column';
11-
import { fetchProfileData } from '../utils/fetch-profile-data';
1210
import { RankCard } from './components/rank-card';
1311
import { getBestRankType } from './utils/get-best-rank-type';
12+
import { fetchProfileData } from '../../../../graphql/helpers/fetch-profile-data';
13+
import { LayoutLeftColumn } from '../components/layout-left-column';
1414

1515
export default async function ProfileRanks({ params }: { params: Promise<{ login: string }> }) {
1616
const { login } = await params;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
import { unstable_cacheLife as cacheLife, unstable_cacheTag as cacheTag } from 'next/cache';
44
import { notFound } from 'next/navigation';
55

6-
import { LayoutLeftColumn } from '../components/layout-left-column';
7-
import { fetchProfileData } from '../utils/fetch-profile-data';
86
import { UserContriutionsList } from './components/user-contriutions-list';
97
import { UserRepositoriesList } from './components/user-repositories-list';
8+
import { fetchProfileData } from '../../../../graphql/helpers/fetch-profile-data';
9+
import { LayoutLeftColumn } from '../components/layout-left-column';
1010

1111
export default async function ProfileRepositories({ params }: { params: Promise<{ login: string }> }) {
1212
const { login } = await params;

graphql/country-list.gql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
query Country {
2+
country {
3+
name
4+
flag
5+
}
6+
}

graphql/global-rankings.gql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ query GlobalRankings($order: RankOrder, $offset: Int) {
1414
c
1515
f
1616
location
17+
country
1718
}
1819
}
1920
}

graphql/helpers/fetch-countries.ts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { unstable_cacheLife as cacheLife } from 'next/cache';
2+
import { cache } from 'react';
3+
4+
import { graphqlDirect } from '@/lib/graphql/graphql-direct';
5+
import { CountryDocument } from '@/types/generated/graphql';
6+
7+
export const fetchCountryList = cache(async () => {
8+
'use cache';
9+
cacheLife('max');
10+
11+
const { country } = (await graphqlDirect(CountryDocument)) ?? {};
12+
13+
if (!country) {
14+
return [];
15+
}
16+
17+
return country;
18+
});
File renamed without changes.

0 commit comments

Comments
 (0)