Skip to content

Commit 5273c62

Browse files
committed
refactor: replace div with onClick link with anchor tag for accessibility
1 parent 40781ea commit 5273c62

File tree

2 files changed

+13
-16
lines changed

2 files changed

+13
-16
lines changed

src/components/cards/Bounty.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
import { useTranslation } from "next-i18next";
22
import { ReactElement, useMemo } from "react";
33
import { useRouter } from "next/router";
4-
import { Bounty, Submission } from "@/types/bounty";
4+
import { Bounty } from "@/types/bounty";
55

66
import DateManager from "@/utilities/DateManager";
77
import Badge from "@/components/ui/Badge";
88
import Avatar from "@/components/ui/Avatar";
99
import Reward from "@/components/badges/RewardBadge";
1010
import Link from "next/link";
1111
import useNavigation from "@/hooks/useNavigation";
12-
import useSafePush from "@/hooks/useSafePush";
1312

1413
export enum RewardType {
1514
submission = "SUBMISSION",
@@ -39,7 +38,6 @@ export default function BountyCard({ bounty }: BountyProps): ReactElement {
3938
const { t } = useTranslation();
4039
const { locale } = useRouter();
4140
const navigation = useNavigation();
42-
const { safePush } = useSafePush();
4341

4442
const convertDate = (date: Date) => DateManager.fromNow(date, locale);
4543

@@ -57,10 +55,9 @@ export default function BountyCard({ bounty }: BountyProps): ReactElement {
5755
}, [bounty.challenge, bounty.course?.slug, bounty.slug, bounty.submissions?.link, bounty.url, isChallenge, navigation.community]);
5856

5957
const Component = link.startsWith("http") ? "a" : Link;
60-
const onSubmissionClick = (submission: Submission) => safePush(navigation.community.submissionPath(submission.id, bounty.challenge, bounty?.slug));
6158

6259
return (
63-
<div className="cursor-pointer flex md:flex-row-reverse md:space-x-5 px-5 min-h-32 md:h-auto md:w-full justify-between hover:bg-secondary relative">
60+
<div className="p-5 flex md:flex-row-reverse md:space-x-5 px-5 min-h-32 md:h-auto md:w-full justify-between hover:bg-secondary relative">
6461
<div className="bg-theme-accent flex-col w-full h-full justify-between md:-space-y-1 pl-3 pr-5 mt-7 mb-5">
6562
<Component className="relative w-full block" href={link}>
6663
<div className="font-medium text-md md:pt-1.5">{bounty.course ? bounty.course.name : bounty.name}</div>
@@ -74,11 +71,16 @@ export default function BountyCard({ bounty }: BountyProps): ReactElement {
7471
{bounty.submissions?.length ? (
7572
<div className="mt-4 space-y-0 divide-y divide-gray-200 border-t border-t-solid border-gray-200">
7673
{bounty.submissions.map((submission) => (
77-
<div className="flex space-x-1 relative text-sm font-medium py-3 cursor-pointer" key={submission.id} onClick={() => onSubmissionClick(submission)}>
74+
<div className="flex space-x-1 relative text-sm font-medium py-3" key={submission.id}>
7875
<div className="flex justify-between w-full pr-0 gap-1 sm:gap-0">
7976
<div className="flex space-x-1">
8077
<Avatar user={submission.user} size="mini" />
81-
<div className="text-ellipsis overflow-hidden w-17 sm:w-auto whitespace-nowrap">{submission.user.displayName}</div>
78+
<Link
79+
className="text-ellipsis overflow-hidden w-17 sm:w-auto whitespace-nowrap"
80+
href={navigation.community.submissionPath(submission.id, bounty.challenge, bounty?.slug)}
81+
>
82+
{submission.user.displayName}
83+
</Link>
8284
<div className="flex align-middle text-gray-500 text-middle bg-gray-200 px-2 text-xxs rounded-xl m-0 h-5">
8385
{submission.metadata && submission.metadata.feedbacks ? submission.metadata.feedbacks : 0}
8486
</div>

src/components/cards/Reputation.tsx

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import Currency from "@/components/ui/Currency";
33
import { Community } from "@/types/community";
44
import { ReactElement } from "react";
55
import { User } from "@/types/bounty";
6-
import useSafePush from "@/hooks/useSafePush";
6+
import Link from "next/link";
77

88
/**
99
* Interface for the reputation card props
@@ -31,21 +31,16 @@ interface ReputationCardProps {
3131
* @returns {ReactElement}
3232
*/
3333
export default function ReputationCard({ details = {} }: ReputationCardProps): ReactElement {
34-
const { safePush } = useSafePush();
35-
const handleClick = (details: ReputationCardProps["details"]) => {
36-
if (!details?.community) return;
37-
safePush(`/communities/${details.community.slug}`);
38-
};
3934
return (
40-
<div onClick={() => handleClick(details)} className="flex space-x-3 text-left hover:bg-gray-50 pb-3 -mx-5 px-5 cursor-pointer">
35+
<div className="flex space-x-3 text-left hover:bg-gray-50 pb-3 -mx-5 px-5">
4136
<Avatar icon={details.community?.icon} color={details.community?.colors?.cover?.background || details.community?.colors.primary} size="medium" shape="rounded" />
4237
{details?.score && (
43-
<div className="pt-1">
38+
<Link href={details?.community ? `/communities/${details.community.slug}` : ""} className="pt-1">
4439
<span className="block text-base font-medium leading-normal">
4540
<Currency value={details.score} token="REP" />
4641
</span>
4742
<span className="block font-normal text-sm">{details.community?.name}</span>
48-
</div>
43+
</Link>
4944
)}
5045
</div>
5146
);

0 commit comments

Comments
 (0)