From b28eb5fecfa0236b5f6ba0c1136e3666ac8847c9 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Fri, 11 Apr 2025 12:50:01 +0100 Subject: [PATCH] AI explore page with search --- .../AITutor/AIExploreCourseListing.tsx | 72 +++++++++++-------- src/components/AITutor/AILoadingState.tsx | 2 +- src/components/AITutor/AITutorTallMessage.tsx | 2 +- src/queries/ai-course.ts | 6 +- 4 files changed, 48 insertions(+), 34 deletions(-) diff --git a/src/components/AITutor/AIExploreCourseListing.tsx b/src/components/AITutor/AIExploreCourseListing.tsx index 97ddd2f5b..8fbcc366f 100644 --- a/src/components/AITutor/AIExploreCourseListing.tsx +++ b/src/components/AITutor/AIExploreCourseListing.tsx @@ -1,6 +1,5 @@ import { useQuery } from '@tanstack/react-query'; import { useEffect, useState } from 'react'; -import { AlertCircle } from 'lucide-react'; import { AICourseCard } from '../GenerateCourse/AICourseCard'; import { AILoadingState } from './AILoadingState'; import { AITutorHeader } from './AITutorHeader'; @@ -12,6 +11,9 @@ import { import { queryClient } from '../../stores/query-client'; import { deleteUrlParam, getUrlParams, setUrlParams } from '../../lib/browser'; import { Pagination } from '../Pagination/Pagination'; +import { AICourseSearch } from '../GenerateCourse/AICourseSearch'; +import { AITutorTallMessage } from './AITutorTallMessage'; +import { BookOpen } from 'lucide-react'; export function AIExploreCourseListing() { const [isInitialLoading, setIsInitialLoading] = useState(true); @@ -20,10 +22,14 @@ export function AIExploreCourseListing() { const [pageState, setPageState] = useState({ perPage: '21', currPage: '1', + query: '', }); - const { data: exploreAiCourses, isFetching: isExploreAiCoursesLoading } = - useQuery(listExploreAiCoursesOptions(pageState), queryClient); + const { + data: exploreAiCourses, + isFetching: isExploreAiCoursesLoading, + isRefetching: isExploreAiCoursesRefetching, + } = useQuery(listExploreAiCoursesOptions(pageState), queryClient); useEffect(() => { setIsInitialLoading(false); @@ -49,26 +55,6 @@ export function AIExploreCourseListing() { } }, [pageState]); - if (isInitialLoading || isExploreAiCoursesLoading) { - return ( - - ); - } - - if (!exploreAiCourses?.data) { - return ( -
- -

- Error loading courses. -

-
- ); - } - return ( <> {showUpgradePopup && ( @@ -78,9 +64,27 @@ export function AIExploreCourseListing() { setShowUpgradePopup(true)} - /> + > + { + setPageState({ + ...pageState, + query: value, + currPage: '1', + }); + }} + /> + + + {(isInitialLoading || isExploreAiCoursesLoading) && ( + + )} - {courses && courses.length > 0 && ( + {!isExploreAiCoursesLoading && courses && courses.length > 0 && (
{courses.map((course) => ( @@ -106,11 +110,19 @@ export function AIExploreCourseListing() {
)} - {!isExploreAiCoursesLoading && courses.length === 0 && ( -
-

No courses found.

-
- )} + {!isInitialLoading && + !isExploreAiCoursesLoading && + courses.length === 0 && ( + { + window.location.href = '/ai'; + }} + /> + )} ); } diff --git a/src/components/AITutor/AILoadingState.tsx b/src/components/AITutor/AILoadingState.tsx index 66ed9de4e..cdaad1020 100644 --- a/src/components/AITutor/AILoadingState.tsx +++ b/src/components/AITutor/AILoadingState.tsx @@ -9,7 +9,7 @@ export function AILoadingState(props: AILoadingStateProps) { const { title, subtitle } = props; return ( -
+
diff --git a/src/components/AITutor/AITutorTallMessage.tsx b/src/components/AITutor/AITutorTallMessage.tsx index a0000a3ff..a990fe885 100644 --- a/src/components/AITutor/AITutorTallMessage.tsx +++ b/src/components/AITutor/AITutorTallMessage.tsx @@ -12,7 +12,7 @@ export function AITutorTallMessage(props: AITutorTallMessageProps) { const { title, subtitle, icon: Icon, buttonText, onButtonClick } = props; return ( -
+

{title}

diff --git a/src/queries/ai-course.ts b/src/queries/ai-course.ts index 846bdb63e..04ffa942c 100644 --- a/src/queries/ai-course.ts +++ b/src/queries/ai-course.ts @@ -83,7 +83,7 @@ type ListUserAiCoursesResponse = { export function listUserAiCoursesOptions( params: ListUserAiCoursesQuery = { - perPage: '10', + perPage: '21', currPage: '1', query: '', }, @@ -117,7 +117,7 @@ type ListFeaturedAiCoursesResponse = { export function listFeaturedAiCoursesOptions( params: ListFeaturedAiCoursesQuery = { - perPage: '10', + perPage: '21', currPage: '1', }, ) { @@ -137,6 +137,7 @@ type ListExploreAiCoursesParams = {}; export type ListExploreAiCoursesQuery = { perPage?: string; currPage?: string; + query?: string; }; type ListExploreAiCoursesResponse = { @@ -151,6 +152,7 @@ export function listExploreAiCoursesOptions( params: ListExploreAiCoursesQuery = { perPage: '21', currPage: '1', + query: '', }, ) { return {