Skip to content

Commit

Permalink
Merge pull request #119 from yzhxxyz/course-card-link
Browse files Browse the repository at this point in the history
feat: add CourseCard Link in CourseList component
  • Loading branch information
chongqiangchen authored Jan 14, 2024
2 parents eb59923 + 7ed803d commit 89f899d
Showing 1 changed file with 27 additions and 26 deletions.
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

1 comment on commit 89f899d

@vercel
Copy link

@vercel vercel bot commented on 89f899d Jan 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Successfully deployed to the following URLs:

frontend – ./

frontend-git-main-wtfacademy.vercel.app
www.wtf.academy
frontend-wtfacademy.vercel.app
wtf.academy

Please sign in to comment.