From ab981b8c88e4ed9ef1da3da7845fd3965f79c9e6 Mon Sep 17 00:00:00 2001 From: Kamran Ahmed Date: Thu, 10 Apr 2025 19:45:03 +0100 Subject: [PATCH] Improve pagination --- .../AITutor/AIExploreCourseListing.tsx | 81 ++++++++++--------- .../GenerateCourse/UserCoursesList.tsx | 2 +- src/queries/ai-course.ts | 2 +- 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/src/components/AITutor/AIExploreCourseListing.tsx b/src/components/AITutor/AIExploreCourseListing.tsx index 93ea36f46..c8b25f560 100644 --- a/src/components/AITutor/AIExploreCourseListing.tsx +++ b/src/components/AITutor/AIExploreCourseListing.tsx @@ -2,9 +2,13 @@ import { useListExploreAiCourses } from '../../queries/ai-course'; import { useEffect, useState } from 'react'; import { AlertCircle, Loader2 } from 'lucide-react'; import { AICourseCard } from '../GenerateCourse/AICourseCard'; +import { AILoadingState } from './AILoadingState'; +import { AITutorHeader } from './AITutorHeader'; +import { UpgradeAccountModal } from '../Billing/UpgradeAccountModal'; export function AIExploreCourseListing() { const [isInitialLoading, setIsInitialLoading] = useState(true); + const [showUpgradePopup, setShowUpgradePopup] = useState(false); const { data, @@ -23,50 +27,51 @@ export function AIExploreCourseListing() { const courses = data?.pages.flatMap((page) => page.data) ?? []; - return ( - <> -
-
-

Explore Courses

-
+ if (isInitialLoading || isExploreAiCoursesLoading) { + return ( + + ); + } + + if (error) { + return ( +
+ +

+ {error?.message ?? 'Error loading courses.'} +

+ ); + } - {(isExploreAiCoursesLoading || isInitialLoading) && ( -
- -

Loading...

-
+ return ( + <> + {showUpgradePopup && ( + setShowUpgradePopup(false)} /> )} - {error && !isExploreAiCoursesLoading && !isInitialLoading && ( -
- -

- {error?.message ?? 'Error loading courses.'} -

+ setShowUpgradePopup(true)} + /> + + {courses && courses.length > 0 && ( +
+ {courses.map((course) => ( + + ))}
)} - {!isExploreAiCoursesLoading && - courses && - courses.length > 0 && - !error && ( -
- {courses.map((course) => ( - - ))} -
- )} - - {hasNextPage && !isFetchingNextPage && !error && ( + {hasNextPage && !isFetchingNextPage && (
)} - {isFetchingNextPage && !error && ( + {isFetchingNextPage && (
({ - perPage: '10', + perPage: '21', currPage: '1', query: '', }); diff --git a/src/queries/ai-course.ts b/src/queries/ai-course.ts index 4f90e2081..8b269124f 100644 --- a/src/queries/ai-course.ts +++ b/src/queries/ai-course.ts @@ -154,7 +154,7 @@ export function useListExploreAiCourses() { return httpGet( `/v1-list-explore-ai-courses`, { - perPage: '20', + perPage: '21', currPage: String(pageParam), }, );