2025-02-25 19:31:01 +08:00
|
|
|
import React, { useState, useMemo } from "react";
|
2025-02-25 16:23:36 +08:00
|
|
|
import { useNavigate } from "react-router-dom";
|
2025-02-25 19:31:01 +08:00
|
|
|
import { Button, Typography, Skeleton } from "antd";
|
|
|
|
import { ArrowRightOutlined } from "@ant-design/icons";
|
|
|
|
import { TaxonomySlug, TermDto } from "@nice/common";
|
2025-02-25 16:23:36 +08:00
|
|
|
import { api } from "@nice/client";
|
2025-02-25 17:45:00 +08:00
|
|
|
import { CoursesSectionTag } from "./CoursesSectionTag";
|
2025-02-25 20:40:34 +08:00
|
|
|
import CourseList from "../../../../components/models/course/list/CourseList";
|
2025-02-24 08:52:50 +08:00
|
|
|
interface GetTaxonomyProps {
|
2025-02-25 16:23:36 +08:00
|
|
|
categories: string[];
|
|
|
|
isLoading: boolean;
|
2025-02-24 08:52:50 +08:00
|
|
|
}
|
2025-02-24 19:10:38 +08:00
|
|
|
function useGetTaxonomy({ type }): GetTaxonomyProps {
|
2025-02-25 16:23:36 +08:00
|
|
|
const { data, isLoading }: { data: TermDto[]; isLoading: boolean } =
|
|
|
|
api.term.findMany.useQuery({
|
|
|
|
where: {
|
|
|
|
taxonomy: {
|
|
|
|
slug: type,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
take: 10, // 只取前10个
|
|
|
|
});
|
|
|
|
const categories = useMemo(() => {
|
|
|
|
const allCategories = isLoading
|
|
|
|
? []
|
|
|
|
: data?.map((course) => course.name);
|
|
|
|
return [...Array.from(new Set(allCategories))];
|
|
|
|
}, [data]);
|
|
|
|
return { categories, isLoading };
|
2025-02-24 08:52:50 +08:00
|
|
|
}
|
2025-02-06 16:32:31 +08:00
|
|
|
const { Title, Text } = Typography;
|
|
|
|
interface CoursesSectionProps {
|
2025-02-25 16:23:36 +08:00
|
|
|
title: string;
|
|
|
|
description: string;
|
|
|
|
initialVisibleCoursesCount?: number;
|
2025-02-06 16:32:31 +08:00
|
|
|
}
|
|
|
|
const CoursesSection: React.FC<CoursesSectionProps> = ({
|
2025-02-25 16:23:36 +08:00
|
|
|
title,
|
|
|
|
description,
|
2025-02-25 19:31:01 +08:00
|
|
|
initialVisibleCoursesCount = 8,
|
2025-02-06 16:32:31 +08:00
|
|
|
}) => {
|
2025-02-25 16:23:36 +08:00
|
|
|
const navigate = useNavigate();
|
|
|
|
const [selectedCategory, setSelectedCategory] = useState<string>("全部");
|
|
|
|
const gateGory: GetTaxonomyProps = useGetTaxonomy({
|
|
|
|
type: TaxonomySlug.CATEGORY,
|
|
|
|
});
|
|
|
|
return (
|
|
|
|
<section className="relative py-20 overflow-hidden bg-gradient-to-b from-gray-50 to-white">
|
|
|
|
<div className="max-w-screen-2xl mx-auto px-6 relative">
|
|
|
|
<div className="flex justify-between items-end mb-16">
|
|
|
|
<div>
|
|
|
|
<Title
|
|
|
|
level={2}
|
|
|
|
className="font-bold text-5xl mb-6 bg-gradient-to-r from-blue-600 to-purple-600 bg-clip-text text-transparent">
|
|
|
|
{title}
|
|
|
|
</Title>
|
|
|
|
<Text
|
|
|
|
type="secondary"
|
|
|
|
className="text-xl font-light text-gray-600">
|
|
|
|
{description}
|
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div className="mb-12 flex flex-wrap gap-4">
|
|
|
|
{gateGory.isLoading ? (
|
2025-02-25 19:31:01 +08:00
|
|
|
<Skeleton paragraph={{ rows: 2 }}></Skeleton>
|
2025-02-25 16:23:36 +08:00
|
|
|
) : (
|
|
|
|
<>
|
2025-02-25 19:31:01 +08:00
|
|
|
{["全部", ...gateGory.categories].map(
|
|
|
|
(category, idx) => (
|
|
|
|
<CoursesSectionTag
|
|
|
|
key={idx}
|
|
|
|
category={category}
|
|
|
|
selectedCategory={selectedCategory}
|
|
|
|
setSelectedCategory={
|
|
|
|
setSelectedCategory
|
|
|
|
}
|
|
|
|
/>
|
|
|
|
)
|
|
|
|
)}
|
2025-02-25 16:23:36 +08:00
|
|
|
</>
|
|
|
|
)}
|
|
|
|
</div>
|
2025-02-25 19:31:01 +08:00
|
|
|
<CourseList
|
|
|
|
params={{
|
|
|
|
page: 1,
|
|
|
|
pageSize: initialVisibleCoursesCount,
|
|
|
|
where: {
|
|
|
|
terms: !(selectedCategory === "全部")
|
|
|
|
? {
|
|
|
|
some: {
|
|
|
|
name: selectedCategory,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
: {},
|
|
|
|
},
|
|
|
|
}}
|
|
|
|
showPagination={false}
|
|
|
|
cols={4}></CourseList>
|
2025-02-25 16:23:36 +08:00
|
|
|
{
|
|
|
|
<div className="flex items-center gap-4 justify-between mt-12">
|
|
|
|
<div className="h-[1px] flex-grow bg-gradient-to-r from-transparent via-gray-300 to-transparent"></div>
|
|
|
|
<div className="flex justify-end">
|
|
|
|
<Button
|
|
|
|
type="link"
|
|
|
|
onClick={() => navigate("/courses")}
|
|
|
|
className="flex items-center gap-2 text-gray-600 hover:text-blue-600 font-medium transition-colors duration-300">
|
|
|
|
查看更多
|
|
|
|
<ArrowRightOutlined />
|
|
|
|
</Button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
}
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
);
|
2025-02-06 16:32:31 +08:00
|
|
|
};
|
|
|
|
export default CoursesSection;
|