diff --git a/apps/web/src/app/main/home/components/CoursesSection.tsx b/apps/web/src/app/main/home/components/CoursesSection.tsx index 61948a1..bbbbfde 100755 --- a/apps/web/src/app/main/home/components/CoursesSection.tsx +++ b/apps/web/src/app/main/home/components/CoursesSection.tsx @@ -1,20 +1,11 @@ -import React, { useState, useMemo, useEffect } from "react"; +import React, { useState, useMemo } from "react"; import { useNavigate } from "react-router-dom"; -import { Button, Card, Typography, Tag, Spin, Empty } from "antd"; -import { - PlayCircleOutlined, - TeamOutlined, - ArrowRightOutlined, -} from "@ant-design/icons"; -import { - courseDetailSelect, - CourseDto, - TaxonomySlug, - TermDto, -} from "@nice/common"; +import { Button, Typography, Skeleton } from "antd"; +import { ArrowRightOutlined } from "@ant-design/icons"; +import { TaxonomySlug, TermDto } from "@nice/common"; import { api } from "@nice/client"; -import CourseCard from "../../courses/components/CourseCard"; import { CoursesSectionTag } from "./CoursesSectionTag"; +import CourseList from "../../courses/components/CourseList"; interface GetTaxonomyProps { categories: string[]; isLoading: boolean; @@ -27,11 +18,7 @@ function useGetTaxonomy({ type }): GetTaxonomyProps { slug: type, }, }, - include: { - children: true, - }, take: 10, // 只取前10个 - orderBy: {}, }); const categories = useMemo(() => { const allCategories = isLoading @@ -41,26 +28,6 @@ function useGetTaxonomy({ type }): GetTaxonomyProps { }, [data]); return { categories, isLoading }; } -// 不同分类跳转 -function useFetchCoursesByCategory(category: string) { - const isAll = category === "全部"; - const { data, isLoading }: { data: CourseDto[]; isLoading: boolean } = - api.post.findMany.useQuery({ - where: isAll - ? {} - : { - terms: { - some: { - name: category, - }, - }, - }, - take: 8, - select: courseDetailSelect, - }); - - return { data, isLoading }; -} const { Title, Text } = Typography; interface CoursesSectionProps { title: string; @@ -70,25 +37,13 @@ interface CoursesSectionProps { const CoursesSection: React.FC = ({ title, description, + initialVisibleCoursesCount = 8, }) => { const navigate = useNavigate(); const [selectedCategory, setSelectedCategory] = useState("全部"); const gateGory: GetTaxonomyProps = useGetTaxonomy({ type: TaxonomySlug.CATEGORY, }); - const { data, isLoading: isDataLoading } = - useFetchCoursesByCategory(selectedCategory); - const filteredCourses = useMemo(() => { - return selectedCategory === "全部" - ? data - : data?.filter((c) => - c.terms.some((t) => t.name === selectedCategory) - ); - }, [selectedCategory, data]); - const displayedCourses = isDataLoading ? [] : filteredCourses; - useEffect(()=>{ - console.log(data) - }) return (
@@ -106,28 +61,42 @@ const CoursesSection: React.FC = ({
-
{gateGory.isLoading ? ( - + ) : ( <> - {['全部',...gateGory.categories].map((category,idx) => ( - - ))} + {["全部", ...gateGory.categories].map( + (category, idx) => ( + + ) + )} )}
- -
- {isDataLoading ? ( - - ) : ( - displayedCourses?.map((course,index) => ( - - )) - )} -
+ {