diff --git a/apps/web/src/app/main/courses/components/CourseList.tsx b/apps/web/src/app/main/courses/components/CourseList.tsx index 97001f0..2c1ce08 100755 --- a/apps/web/src/app/main/courses/components/CourseList.tsx +++ b/apps/web/src/app/main/courses/components/CourseList.tsx @@ -58,7 +58,7 @@ export default function CourseList({
{courses.length > 0 ? ( <> -
+
{isLoading ? ( ) : ( diff --git a/apps/web/src/app/main/home/components/CategorySection.tsx b/apps/web/src/app/main/home/components/CategorySection.tsx index ddfeab4..9584193 100755 --- a/apps/web/src/app/main/home/components/CategorySection.tsx +++ b/apps/web/src/app/main/home/components/CategorySection.tsx @@ -1,18 +1,13 @@ import React, { useState, useCallback, useEffect, useMemo } from "react"; -import { Typography, Button, Spin } from "antd"; +import { Typography, Button, Spin, Skeleton } from "antd"; import { stringToColor, TaxonomySlug, TermDto } from "@nice/common"; import { api } from "@nice/client"; import { ControlOutlined } from "@ant-design/icons"; import { useNavigate, useSearchParams } from "react-router-dom"; +import LookForMore from "./LookForMore"; +import CategorySectionCard from "./CategorySectionCard"; const { Title, Text } = Typography; - -interface CourseCategory { - name: string; - count: number; - description: string; -} - const CategorySection = () => { const [hoveredIndex, setHoveredIndex] = useState(null); const [showAll, setShowAll] = useState(false); @@ -39,9 +34,6 @@ const CategorySection = () => { [] ); useEffect(() => { - console.log(courseCategoriesData); - // 如果 showAll 为 true,则显示所有分类数据, - // 如果 showAll 为 false,则只显示前 8 个分类数据, if (!isLoading) { if (showAll) { setDisplayedCategories(courseCategoriesData); @@ -50,13 +42,6 @@ const CategorySection = () => { } } }, [courseCategoriesData, showAll]); - // const courseCategories: CourseCategory[] = useMemo(() => { - // return data?.map((term) => ({ - // name: term.name, - // count: term.hasChildren ? term.children.length : 0, - // description: term.description - // })) || []; - // },[data]) const handleMouseEnter = useCallback((index: number) => { setHoveredIndex(index); }, []); @@ -82,106 +67,27 @@ const CategorySection = () => {
{isLoading ? ( - + ) : ( displayedCategories.map((category, index) => { const categoryColor = stringToColor(category.name); const isHovered = hoveredIndex === index; return ( -
handleMouseEnter(index)} - onMouseLeave={handleMouseLeave} - role="button" - tabIndex={0} - aria-label={`查看${category.name}课程类别`} - onClick={() => { - console.log(category.name); - navigate( - `/courses?category=${category.name}` - ); - window.scrollTo({ - top: 0, - behavior: "smooth", - }); - }}> -
-
-
-
-
-
- - {category.name} - - {/* - {category.children.length} 门课程 - */} -
- - {category.description} - -
- 了解更多 - - → - -
-
-
+ ); }) )}
- {!isLoading && ( -
- -
- )} +
); diff --git a/apps/web/src/app/main/home/components/CategorySectionCard.tsx b/apps/web/src/app/main/home/components/CategorySectionCard.tsx new file mode 100644 index 0000000..a91525c --- /dev/null +++ b/apps/web/src/app/main/home/components/CategorySectionCard.tsx @@ -0,0 +1,64 @@ +import { useNavigate } from "react-router-dom"; +import { Typography } from "antd"; +export default function CategorySectionCard({index,handleMouseEnter,handleMouseLeave,category,categoryColor,isHovered,}) { + const navigate = useNavigate() + const { Title, Text } = Typography; + return ( +
handleMouseEnter(index)} + onMouseLeave={handleMouseLeave} + role="button" + tabIndex={0} + aria-label={`查看${category.name}课程类别`} + onClick={() => { + console.log(category.name); + navigate( + `/courses?category=${category.name}` + ); + window.scrollTo({ + top: 0, + behavior: "smooth", + }); + }}> +
+
+
+
+
+
+ + {category.name} + +
+
+ 了解更多 + + → + +
+
+
+ ) +} \ No newline at end of file diff --git a/apps/web/src/app/main/home/components/CoursesSection.tsx b/apps/web/src/app/main/home/components/CoursesSection.tsx index bbbbfde..bc2e5a4 100755 --- a/apps/web/src/app/main/home/components/CoursesSection.tsx +++ b/apps/web/src/app/main/home/components/CoursesSection.tsx @@ -6,6 +6,7 @@ import { TaxonomySlug, TermDto } from "@nice/common"; import { api } from "@nice/client"; import { CoursesSectionTag } from "./CoursesSectionTag"; import CourseList from "../../courses/components/CourseList"; +import LookForMore from "./LookForMore"; interface GetTaxonomyProps { categories: string[]; isLoading: boolean; @@ -97,20 +98,7 @@ const CoursesSection: React.FC = ({ }} showPagination={false} cols={4}> - { -
-
-
- -
-
- } +
); diff --git a/apps/web/src/app/main/home/components/LookForMore.tsx b/apps/web/src/app/main/home/components/LookForMore.tsx new file mode 100644 index 0000000..88e1b41 --- /dev/null +++ b/apps/web/src/app/main/home/components/LookForMore.tsx @@ -0,0 +1,24 @@ +import { ArrowRightOutlined } from "@ant-design/icons"; +import { Button } from "antd"; +import { useNavigate } from "react-router-dom"; + +export default function LookForMore({to}:{to:string}) { + const navigate = useNavigate(); + return ( + <> +
+
+
+ +
+
+ + ) + +}