Skip to content

Commit 04a0d46

Browse files
committed
rankings page: rotate avatar while page is loading
1 parent c339d55 commit 04a0d46

File tree

4 files changed

+49
-17
lines changed

4 files changed

+49
-17
lines changed

app/by/[rankingType]/components/link-with-stop-propagation.tsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,22 @@
33
import Link from 'next/link';
44
import { FC, ReactNode } from 'react';
55

6+
import { cn } from '@/lib/utils';
7+
68
type LinkWithStopPropagationProps = {
79
children: ReactNode;
810
href: string;
11+
className?: string;
912
};
1013

11-
export const LinkWithStopPropagation: FC<LinkWithStopPropagationProps> = ({ children, href }) => {
14+
export const LinkWithStopPropagation: FC<LinkWithStopPropagationProps> = ({ children, href, className }) => {
1215
return (
13-
<Link href={href} onClick={(event) => event.stopPropagation()} prefetch={false}>
16+
<Link
17+
href={href}
18+
onClick={(event) => event.stopPropagation()}
19+
prefetch={false}
20+
className={cn('flex items-center gap-2', className)}
21+
>
1422
{children}
1523
</Link>
1624
);
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
'use client';
2+
import { AvatarFallback } from '@radix-ui/react-avatar';
3+
import { useLinkStatus } from 'next/link';
4+
import { FC } from 'react';
5+
6+
import { Avatar, AvatarImage } from '@/components/ui/avatar';
7+
import { cn } from '@/lib/utils';
8+
9+
type ProfileAvatarProps = {
10+
url?: string | null;
11+
initials?: string | null;
12+
};
13+
14+
export const ProfileAvatar: FC<ProfileAvatarProps> = ({ url, initials }) => {
15+
const { pending } = useLinkStatus();
16+
17+
if (!url) {
18+
return null;
19+
}
20+
21+
return (
22+
<Avatar>
23+
<AvatarImage src={url} className={cn('rounded-full', { 'animate-spin': pending })} width={36} height={36} />
24+
<AvatarFallback>{initials}</AvatarFallback>
25+
</Avatar>
26+
);
27+
};

app/by/[rankingType]/page.tsx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { Page } from '@/components/page/page';
22
import { RankDelta } from '@/components/rank-delta/rank-delta';
3-
import { Avatar, AvatarFallback, AvatarImage } from '@/components/ui/avatar';
43
import {
54
Pagination,
65
PaginationContent,
@@ -15,6 +14,7 @@ import { getInitials } from '@/utils/get-initials';
1514

1615
import { ClickableRow } from './components/clickale-row';
1716
import { LinkWithStopPropagation } from './components/link-with-stop-propagation';
17+
import { ProfileAvatar } from './components/profile-avatar';
1818

1919
const ITEMS_PER_PAGE = 100;
2020

@@ -93,14 +93,11 @@ export default async function GlobalRanking({
9393
<RankDelta current={item[rankPropName]} previous={item[`${rankPropName}M`]} />
9494
</div>
9595
</TableCell>
96-
<TableCell className="flex items-center gap-2">
97-
{!!user?.avatarUrl && (
98-
<Avatar>
99-
<AvatarImage src={user.avatarUrl} className="rounded-full" width={36} height={36} />
100-
<AvatarFallback>{getInitials(user?.login)}</AvatarFallback>
101-
</Avatar>
102-
)}
103-
<LinkWithStopPropagation href={`/profile/${user?.login}`}>{user?.login}</LinkWithStopPropagation>
96+
<TableCell>
97+
<LinkWithStopPropagation href={`/profile/${user?.login}`}>
98+
<ProfileAvatar url={user?.avatarUrl} initials={getInitials(user?.login)} />
99+
{user?.login}
100+
</LinkWithStopPropagation>
104101
</TableCell>
105102
<TableCell className="hidden sm:table-cell break-all whitespace-normal">{user?.location}</TableCell>
106103
<TableCell className="text-right">{user?.[rankPropName]?.toLocaleString('en-US')}</TableCell>

next.config.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@ const nextConfig: NextConfig = {
1313
async rewrites() {
1414
return [
1515
{
16-
source: "/ingest/static/:path*",
17-
destination: "https://eu-assets.i.posthog.com/static/:path*",
16+
source: '/ingest/static/:path*',
17+
destination: 'https://eu-assets.i.posthog.com/static/:path*',
1818
},
1919
{
20-
source: "/ingest/:path*",
21-
destination: "https://eu.i.posthog.com/:path*",
20+
source: '/ingest/:path*',
21+
destination: 'https://eu.i.posthog.com/:path*',
2222
},
2323
{
24-
source: "/ingest/decide",
25-
destination: "https://eu.i.posthog.com/decide",
24+
source: '/ingest/decide',
25+
destination: 'https://eu.i.posthog.com/decide',
2626
},
2727
];
2828
},

0 commit comments

Comments
 (0)