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