add. Li
This commit is contained in:
parent
d6edf9b856
commit
668a3a015b
|
@ -69,10 +69,10 @@ export default function FilterSection({
|
|||
|
||||
return (
|
||||
<div className="bg-white p-6 rounded-lg shadow-sm space-y-6">
|
||||
<Form>
|
||||
{/* <Form>
|
||||
|
||||
</Form>
|
||||
{taxonomies.map((tax) => {
|
||||
</Form> */}
|
||||
{taxonomies?.map((tax) => {
|
||||
return (
|
||||
<>
|
||||
<div>
|
||||
|
|
|
@ -69,6 +69,8 @@ const CategorySection = () => {
|
|||
const [displayedCategories,setDisplayedCategories] = useState<TermDto[]>([])
|
||||
useEffect(() => {
|
||||
console.log(courseCategoriesData);
|
||||
// 如果 showAll 为 true,则显示所有分类数据,
|
||||
// 如果 showAll 为 false,则只显示前 8 个分类数据,
|
||||
if(!isLoading){
|
||||
if(showAll){
|
||||
setDisplayedCategories(courseCategoriesData)
|
||||
|
|
|
@ -54,7 +54,10 @@ function useFetchCoursesByCategory(category: string) {
|
|||
include: {
|
||||
terms: true,
|
||||
depts:true
|
||||
}
|
||||
},
|
||||
orderBy: {
|
||||
createdAt: 'desc', // 按创建时间降序排列
|
||||
},
|
||||
});
|
||||
|
||||
return { data, isLoading };
|
||||
|
@ -97,38 +100,21 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
})
|
||||
|
||||
const { data, isLoading: isDataLoading } = useFetchCoursesByCategory(selectedCategory);
|
||||
// useEffect(() => {
|
||||
// console.log('data:', data)
|
||||
// })
|
||||
|
||||
useEffect(() => {
|
||||
console.log('dept data:', data)
|
||||
})
|
||||
const handleClick = (course: CourseDto) => {
|
||||
navigate(`/course/${course.id}/detail`);
|
||||
}
|
||||
|
||||
useEffect(() => {
|
||||
console.log('data:', data)
|
||||
})
|
||||
|
||||
// const { data: depts, isLoading: isDeptLoading }: { data: CourseDto[], isLoading: boolean } = api.post.findMany.useQuery({
|
||||
// where: {},
|
||||
// include: {
|
||||
// depts: true,
|
||||
// },
|
||||
// orderBy: {
|
||||
// createdAt: 'desc' // 按创建时间降序排列
|
||||
// },
|
||||
// take: 8 // 只获取前8个课程
|
||||
// });
|
||||
|
||||
|
||||
|
||||
const filteredCourses = useMemo(() => {
|
||||
return selectedCategory === '全部'
|
||||
? data
|
||||
: data?.filter(c => c.terms.some(t => t.name === selectedCategory));
|
||||
}, [selectedCategory, data]);
|
||||
|
||||
const displayedCourses = isDataLoading ? [] : filteredCourses?.slice(0, visibleCourses);
|
||||
|
||||
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">
|
||||
|
@ -164,7 +150,7 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
color={selectedCategory === category ? 'blue' : 'default'}
|
||||
onClick={() => {
|
||||
setSelectedCategory(category)
|
||||
console.log(category)
|
||||
// console.log(category)
|
||||
}}
|
||||
className={`px-6 py-2 text-base cursor-pointer rounded-full transition-all duration-300 ${selectedCategory === category
|
||||
? 'bg-blue-600 text-white shadow-lg'
|
||||
|
@ -269,7 +255,10 @@ const CoursesSection: React.FC<CoursesSectionProps> = ({
|
|||
<div className="flex justify-end">
|
||||
<Button
|
||||
type="link"
|
||||
onClick={() => navigate('/courses')}
|
||||
onClick={() => {
|
||||
navigate('/courses')
|
||||
window.scrollTo({ top: 0, behavior: 'smooth' })
|
||||
}}
|
||||
className="flex items-center gap-2 text-gray-600 hover:text-blue-600 font-medium transition-colors duration-300"
|
||||
>
|
||||
查看更多
|
||||
|
|
Loading…
Reference in New Issue