Skip to content

Commit 84d0140

Browse files
✨ Add functionality to share contributors#username as link
1 parent 35bbc37 commit 84d0140

File tree

1 file changed

+32
-14
lines changed

1 file changed

+32
-14
lines changed

components/ContributorCard.tsx

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { env } from 'env.mjs';
22
import { CldImage, getCldImageUrl } from 'next-cloudinary';
3+
import { useRouter } from 'next/router';
4+
import { useEffect, useRef } from 'react';
35
import { IoLogoGithub } from 'react-icons/io';
46

57
interface Contributor {
@@ -15,6 +17,9 @@ interface Props {
1517
}
1618

1719
export default function ContributorCard({ contributor }: Props) {
20+
const router = useRouter();
21+
const cardRef = useRef<HTMLButtonElement>(null);
22+
const hash = router.asPath.split('#')[1];
1823
const url = env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
1924
? getCldImageUrl({
2025
src: contributor.avatar_url,
@@ -24,37 +29,50 @@ export default function ContributorCard({ contributor }: Props) {
2429
})
2530
: contributor.avatar_url;
2631

32+
useEffect(() => {
33+
if (hash.toLowerCase() === contributor.login.toLowerCase()) {
34+
cardRef.current?.scrollIntoView({
35+
behavior: 'smooth',
36+
block: 'center'
37+
});
38+
cardRef.current?.focus();
39+
}
40+
}, [hash, contributor.login]);
41+
2742
return (
28-
<div className="text-center shadow-2xl card">
29-
<a
30-
href={`https://github.com/${contributor.login}`}
31-
target="_blank"
32-
rel="noreferrer"
33-
>
34-
<figure className="px-10 pt-10 h-[351px] md:h-[336px] lg:h-[204px] xl:h-[268px]">
43+
<button
44+
className="text-center shadow-2xl card min-w-full justify-center focus-within:outline-sky-300"
45+
id={contributor.login}
46+
onClick={() => router.replace({ hash: contributor.login })}
47+
ref={cardRef}
48+
>
49+
<div className="w-full mx-auto pt-5">
50+
<figure className="h-full w-full">
3551
<img src={url} alt={contributor.name} className="rounded-xl" />
3652
</figure>
37-
</a>
38-
<div className="card-body items-center text-center">
39-
<h2 className="card-title text-neutral-100">{contributor.name}</h2>
53+
</div>
54+
<div className="card-body gap-3 text-center w-full">
55+
<h2 className="text-center text-2xl font-bold text-2023-bavarian-blue-1">
56+
{contributor.name}
57+
</h2>
4058
<a
4159
href={contributor.profile}
42-
className="link text-neutral-100 hover:text-[#dbe8d9]"
60+
className="link text-2023-bavarian-blue-1 hover:text-2023-bavarian-blue-2"
4361
>
4462
{contributor.profile}
4563
</a>
4664
<div className="justify-center card-actions mt-auto">
4765
<a
48-
className="text-white btn border-[#dbe8d9] hover:border-[#dbe8d9] btn-outline border-2 hover:bg-[#dbe8d9] hover:text-slate-900"
66+
className="text-2023-bavarian-blue-1 btn border-2023-bavarian-blue-2 hover:border-2023-bavarian-blue-2 btn-outline border-2 hover:bg-2023-bavarian-blue-2 hover:text-2023-bavarian-blue-4"
4967
href={`https://github.com/${contributor.login}`}
5068
target="_blank"
5169
rel="noreferrer"
5270
>
53-
<IoLogoGithub />
71+
<IoLogoGithub className="w-5 h-5" />
5472
&nbsp; Profile
5573
</a>
5674
</div>
5775
</div>
58-
</div>
76+
</button>
5977
);
6078
}

0 commit comments

Comments
 (0)