Skip to content

Commit b69cccb

Browse files
refactor: use usememo in the right way on the duration card
1 parent 4802ce5 commit b69cccb

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

src/components/ui/Duration.tsx renamed to src/components/badges/Duration.tsx

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,22 @@ import { useMemo } from "react";
66
export const DurationCard = ({ value, type = "gray" }: { value: number, type?: string }) => {
77
const router = useRouter();
88
const duration = useMemo(() => {
9-
return (value: number) => {
10-
if (!value) {
11-
return 0;
12-
}
13-
if (Number(value) !== value) return value
14-
return DateManager.humanize(value, router.locale as string);
15-
};
16-
}, [router.locale]);
9+
if (!value) {
10+
return 0;
11+
}
12+
if (Number(value) !== value) return value
13+
return DateManager.humanize(value, router.locale as string);
14+
}, [router.locale, value]);
15+
1716
return (
1817
<span className={classNames("text-xxs uppercase font-semibold px-2 rounded-3xl inline-block text-gray-500",
1918
{
2019
"bg-gray-200": type === 'gray',
2120
"border border-gray-200": type === "bordered"
2221
}
23-
)}>{duration(value)}</span>
22+
)}>
23+
{duration}
24+
</span>
2425
)
2526
}
2627

src/components/cards/Learning.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import useNavigation from "@/hooks/useNavigation";
22
import { useRouter } from "next/router";
33
import { ReactElement } from "react";
4-
import { DurationCard } from "../ui/Duration";
4+
import { DurationCard } from "../badges/Duration";
55

66
/**
77
* LearningModule interface

src/components/cards/LearningModule.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import ArrowButton from "@/components/ui/button/Arrow";
33
import Link from "next/link";
44
import { useTranslation } from "next-i18next";
55
import Tag from "../ui/Tag";
6-
import { DurationCard } from "../ui/Duration";
6+
import { DurationCard } from "@/components/badges/Duration";
77
import { useMultiSelector } from "@/hooks/useTypedSelector";
88
import { IRootState } from "@/store";
99
import { LearningModule } from "@/types/course";
@@ -37,7 +37,7 @@ export function LearningModuleCard({ data }: { data: LearningModule }): JSX.Elem
3737
<div className="flex text-xs items-center justify-between">
3838
<div className="gap-2 flex items-center">
3939
<div className="h-4.5 w-4.5 rounded-sm" style={{ backgroundColor: colors?.primary }} />
40-
<span className="uppercase">{t("communities.card.module")}</span>
40+
<span className="uppercase font-semibold">{t("communities.card.module")}</span>
4141
</div>
4242
<div className="gap-2 flex items-center">
4343
<Tag className="uppercase">{t(level)}</Tag>
@@ -70,7 +70,7 @@ export function LearningModuleCard({ data }: { data: LearningModule }): JSX.Elem
7070
<div className="w-full mb-0 justify-self-end">
7171
<Link href={`/communities/${community.slug}/challenges/${challenge?.id}/learning-modules/${data.id}`}>
7272
<ArrowButton communityStyles={true} variant="outline-primary">
73-
Start now
73+
{t("communities.overview.challenge.learning.start")}
7474
</ArrowButton>
7575
</Link>
7676
</div>

0 commit comments

Comments
 (0)