From 26fb32a69a570831c33183da8bbad45b07ad5c0e Mon Sep 17 00:00:00 2001 From: Rao <1227431568@qq.com> Date: Mon, 24 Feb 2025 21:43:05 +0800 Subject: [PATCH] rht02242142 --- apps/web/src/app/main/courses/page.tsx | 13 +++++++++---- .../app/main/home/components/CategorySection.tsx | 8 ++++++-- apps/web/src/app/main/layout/MainHeader.tsx | 6 ++++-- 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/apps/web/src/app/main/courses/page.tsx b/apps/web/src/app/main/courses/page.tsx index c860a82..a411d60 100755 --- a/apps/web/src/app/main/courses/page.tsx +++ b/apps/web/src/app/main/courses/page.tsx @@ -12,7 +12,7 @@ export default function CoursesPage() { const [currentPage, setCurrentPage] = useState(1); const [selectedCategory, setSelectedCategory] = useState(""); const [selectedLevel, setSelectedLevel] = useState(""); - const pageSize = 12; + const pageSize = 9; const [isAll,setIsAll] = useState(true) const [searchParams, setSearchParams] = useSearchParams(); let coursesData = [] @@ -55,8 +55,11 @@ export default function CoursesPage() { isCourseLoading = isLoading } useEffect(() => { - console.log(coursesData) - }, [coursesData]); + if(searchParams.get('searchValue')==''){ + setSelectedCategory(''); + setSelectedLevel('') + } + }, [searchParams.get('searchValue')]); const filteredCourses = useMemo(() => { return isCourseLoading ? [] : coursesData; }, [isCourseLoading, coursesData, selectedCategory, selectedLevel]); @@ -70,7 +73,9 @@ export default function CoursesPage() { setCurrentPage(page); window.scrollTo({ top: 0, behavior: "smooth" }); }; - + useEffect(()=>{ + setCurrentPage(1) + },[]) return ( diff --git a/apps/web/src/app/main/home/components/CategorySection.tsx b/apps/web/src/app/main/home/components/CategorySection.tsx index 967336f..c2eff20 100755 --- a/apps/web/src/app/main/home/components/CategorySection.tsx +++ b/apps/web/src/app/main/home/components/CategorySection.tsx @@ -63,7 +63,7 @@ const CategorySection = () => { orderBy: { createdAt: 'desc', // 按创建时间降序排列 }, - take:10 + take:8 }) // 分类展示 const [displayedCategories,setDisplayedCategories] = useState([]) @@ -194,7 +194,11 @@ const CategorySection = () => { type="default" size="large" className="px-8 h-12 text-base font-medium hover:shadow-md transition-all duration-300" - onClick={() => setShowAll(!showAll)} + onClick={() => { + //setShowAll(!showAll) + navigate("/courses") + window.scrollTo({ top: 0, behavior: 'smooth' }) + }} > {showAll ? '收起' : '查看更多分类'} diff --git a/apps/web/src/app/main/layout/MainHeader.tsx b/apps/web/src/app/main/layout/MainHeader.tsx index cc2325d..c8e0d2a 100755 --- a/apps/web/src/app/main/layout/MainHeader.tsx +++ b/apps/web/src/app/main/layout/MainHeader.tsx @@ -35,9 +35,11 @@ export function MainHeader() { className="w-72 rounded-full" value={searchValue} onChange={(e) => setSearchValue(e.target.value)} - onPressEnter={()=>{ - //console.log(searchValue) + onPressEnter={(e)=>{ + //console.log(e) + setSearchValue('') navigate(`/courses/?searchValue=${searchValue}`) + window.scrollTo({ top: 0, behavior: "smooth" }); }} />