Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add CourseCard Link in CourseList component #119

Merged
merged 2 commits into from
Jan 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 27 additions & 26 deletions src/components/CoursesList.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,56 @@
import React from "react";
import { useHistory } from "@docusaurus/router";
import { useQuery } from "react-query";
import Tag from "@site/src/components/ui/Tag";
import { Skeleton } from "@site/src/components/ui/Skeleton";
import { getCourses } from "@site/src/api/course";
import { TCourse } from "../typings/course";
import useDocusaurusContext from "@docusaurus/useDocusaurusContext";
import Translate from "@docusaurus/Translate";
import Link from "@docusaurus/Link";

type TProps = {
course: TCourse;
};

const CourseCard = (props: TProps) => {
const { course } = props;
const history = useHistory();

const viewCourse = (path: string) => {
const courseRoutePath = (path: string) => {
if (path.startsWith("http")) {
window.location.href = path;
return path;
} else {
history.push(path);
return `/${path}`;
}
};

return (
<div
onClick={() => viewCourse(course.route_path)}
className="w-full overflow-hidden border border-solid md:w-[300px] rounded-md shadow-sm transition-shadow hover:shadow-lg"
<Link
to={courseRoutePath(course.route_path)}
className="hover:no-underline hover:text-gray-900"
>
<div className="w-full bg-background-subtle h-[150px]">
<img
src={course.cover_img}
alt=""
className="object-cover w-full h-full"
/>
</div>
<div className="flex flex-col p-4">
<div className="flex items-center justify-between font-bold text-[22px] leading-[25px] font-ubuntu">
<span>{course.title}</span>
<div className="w-full overflow-hidden border border-solid md:w-[300px] rounded-md shadow-sm transition-shadow hover:shadow-lg">
<div className="w-full bg-background-subtle h-[150px]">
<img
src={course.cover_img}
alt=""
className="object-cover w-full h-full"
/>
</div>
<div className="text-sm leading-[17px] mt-[10px]">
{course.description}
</div>
{Boolean(course.user_cnt) && (
<div className="flex gap-2 mt-[14px]">
<Tag className="bg-brand-muted">{`${course.user_cnt} learners`}</Tag>
<div className="flex flex-col p-4">
<div className="flex items-center justify-between font-bold text-[22px] leading-[25px] font-ubuntu">
<span>{course.title}</span>
</div>
)}
<div className="text-sm leading-[17px] mt-[10px]">
{course.description}
</div>
{Boolean(course.user_cnt) && (
<div className="flex gap-2 mt-[14px]">
<Tag className="bg-brand-muted">{`${course.user_cnt} learners`}</Tag>
</div>
)}
</div>
</div>
</div>
</Link>
);
};

Expand Down