rht0225
This commit is contained in:
parent
287bf31d0e
commit
13b8c10c62
|
@ -1,17 +1,13 @@
|
|||
import React, { useState, useCallback, useEffect, useMemo } from "react";
|
||||
import { Typography, Button, Spin, Skeleton } from "antd";
|
||||
import { Typography, 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;
|
||||
const CategorySection = () => {
|
||||
const [hoveredIndex, setHoveredIndex] = useState<number | null>(null);
|
||||
const [showAll, setShowAll] = useState(false);
|
||||
//获得分类
|
||||
const {
|
||||
data: courseCategoriesData,
|
||||
isLoading,
|
||||
|
@ -21,27 +17,8 @@ const CategorySection = () => {
|
|||
slug: TaxonomySlug.CATEGORY,
|
||||
},
|
||||
},
|
||||
include: {
|
||||
children: true,
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: "desc", // 按创建时间降序排列
|
||||
},
|
||||
take: 8,
|
||||
});
|
||||
// 分类展示
|
||||
const [displayedCategories, setDisplayedCategories] = useState<TermDto[]>(
|
||||
[]
|
||||
);
|
||||
useEffect(() => {
|
||||
if (!isLoading) {
|
||||
if (showAll) {
|
||||
setDisplayedCategories(courseCategoriesData);
|
||||
} else {
|
||||
setDisplayedCategories(courseCategoriesData.slice(0, 8));
|
||||
}
|
||||
}
|
||||
}, [courseCategoriesData, showAll]);
|
||||
const handleMouseEnter = useCallback((index: number) => {
|
||||
setHoveredIndex(index);
|
||||
}, []);
|
||||
|
@ -49,9 +26,6 @@ const CategorySection = () => {
|
|||
const handleMouseLeave = useCallback(() => {
|
||||
setHoveredIndex(null);
|
||||
}, []);
|
||||
|
||||
const navigate = useNavigate();
|
||||
|
||||
return (
|
||||
<section className="py-32 relative overflow-hidden">
|
||||
<div className="max-w-screen-2xl mx-auto px-4 relative">
|
||||
|
@ -69,7 +43,7 @@ const CategorySection = () => {
|
|||
{isLoading ? (
|
||||
<Skeleton></Skeleton>
|
||||
) : (
|
||||
displayedCategories.map((category, index) => {
|
||||
courseCategoriesData.map((category, index) => {
|
||||
const categoryColor = stringToColor(category.name);
|
||||
const isHovered = hoveredIndex === index;
|
||||
|
||||
|
|
Loading…
Reference in New Issue