From f9ddbd2e310f7fa33a2b8759cd91222c024308b4 Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Tue, 30 Jul 2024 12:04:57 +0600 Subject: [PATCH] feat: rating feedback pagination --- .../CustomRoadmapRatingsModal.tsx | 30 ++-------- .../CustomRoadmap/ListRoadmapRatings.tsx | 59 +++++++++++++++---- src/components/Rating/Rating.tsx | 16 +++-- 3 files changed, 62 insertions(+), 43 deletions(-) diff --git a/src/components/CustomRoadmap/CustomRoadmapRatingsModal.tsx b/src/components/CustomRoadmap/CustomRoadmapRatingsModal.tsx index 9424ec268..8a764aca9 100644 --- a/src/components/CustomRoadmap/CustomRoadmapRatingsModal.tsx +++ b/src/components/CustomRoadmap/CustomRoadmapRatingsModal.tsx @@ -37,30 +37,12 @@ export function CustomRoadmapRatingsModal( ]; return ( - - {/*{canManage && (*/} - {/*
*/} - {/* {tabs.map((tab) => {*/} - {/* const isActive = tab.id === activeTab;*/} - - {/* return (*/} - {/* {*/} - {/* setActiveTab(tab.id);*/} - {/* }}*/} - {/* className={cn('rounded-md bg-white px-3 py-2 text-sm', {*/} - {/* 'bg-gray-100 font-medium text-black': isActive,*/} - {/* 'text-gray-500 hover:text-gray-700': !isActive,*/} - {/* })}*/} - {/* >*/} - {/* {tab.label}*/} - {/* */} - {/* );*/} - {/* })}*/} - {/*
*/} - {/*)}*/} - + {activeTab === 'ratings' && ( ([]); + const [ratingsResponse, setRatingsResponse] = + useState(null); + + const listRoadmapRatings = async (currPage: number = 1) => { + setIsLoading(true); - const listRoadmapRatings = async () => { const { response, error } = await httpGet( `${import.meta.env.PUBLIC_API_URL}/v1-list-roadmap-ratings/${roadmapSlug}`, + { + currPage, + perPage: 1, + }, ); if (!response || error) { @@ -54,7 +68,7 @@ export function ListRoadmapRatings(props: ListRoadmapRatingsProps) { return; } - setRatings(response); + setRatingsResponse(response); setError(''); setIsLoading(false); }; @@ -76,8 +90,10 @@ export function ListRoadmapRatings(props: ListRoadmapRatingsProps) { ); } + const ratings = ratingsResponse?.data || []; + return ( -
+
{isLoading && (
@@ -85,14 +101,20 @@ export function ListRoadmapRatings(props: ListRoadmapRatingsProps) { )} {!isLoading && ratings.length > 0 && ( -
-
- Rated {averageRating.toFixed(1)} +
+
+ + Rated{' '} + {averageRating.toFixed(1)} + - by {totalWhoRated} user{totalWhoRated > 1 && 's'} + by{' '} + + {totalWhoRated} user{totalWhoRated > 1 && 's'} +
-
+
{ratings.map((rating) => { const userAvatar = rating?.avatar ? `${import.meta.env.PUBLIC_AVATAR_BASE_URL}/${rating.avatar}` @@ -135,6 +157,17 @@ export function ListRoadmapRatings(props: ListRoadmapRatingsProps) { ); })}
+ + { + listRoadmapRatings(page).then(); + }} + />
)} diff --git a/src/components/Rating/Rating.tsx b/src/components/Rating/Rating.tsx index c04f07281..8c5b38c0e 100644 --- a/src/components/Rating/Rating.tsx +++ b/src/components/Rating/Rating.tsx @@ -37,6 +37,10 @@ export function Rating(props: RatingProps) { isActive ? 100 : hasDecimal ? decimalWidthPercentage : 0 } onClick={() => { + if (readOnly) { + return; + } + setStars(counter); onRatingChange?.(counter); }} @@ -64,15 +68,15 @@ function RatingStar(props: RatingStarProps) { const { onClick, widthPercentage = 100, starSize = 20, readOnly } = props; return ( - +
); }