Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#162] Add fallback for no reviews in review list #322

Merged
merged 1 commit into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions ui/src/components/review/server/no-review.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { XCircleIcon } from '@heroicons/react/24/outline';

import Text from '@/components/common/server/text';

export function NoReview() {
return (
<div className="flex flex-col p-6 items-center gap-8">
<XCircleIcon className="w-6 h-6 text-gray-500" />

<Text>해당하는 리뷰가 없습니다.</Text>
</div>
);
}
8 changes: 5 additions & 3 deletions ui/src/components/review/server/review-cards-list.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Pagination from '@/components/common/client/pagination';
import { ReviewCard } from '@/components/review/client/review-card';
import { NoReview } from '@/components/review/server/no-review';

import { listReviews } from '@/lib/apis/review/server';
import type { ListReviewsQuery } from '@/lib/definitions/review';
Expand All @@ -10,9 +11,10 @@ export async function ReviewCardsList({ query }: { query: ListReviewsQuery }) {
return (
<div className="flex w-full flex-col items-center space-y-6">
<div className="w-full">
{reviews.map((review) => (
<ReviewCard key={review.id} review={review} />
))}
{reviews.length > 0 &&
reviews.map((review) => <ReviewCard key={review.id} review={review} />)}

{reviews.length === 0 && <NoReview />}
</div>

<Pagination totalPages={pagination.totalPageCount} />
Expand Down
6 changes: 6 additions & 0 deletions ui/src/hooks/common/use-pagination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export function usePagination(totalPages: number) {
const searchParams = useSearchParams();
const currentPage = Number(searchParams.get('page')) || 1;

// when there are no pages, set totalPages to 1
// to show fallback on 1st page
if (totalPages === 0) {
totalPages = 1;
}

if (currentPage < 1 || currentPage > totalPages) {
redirect(`${pathname}?page=1`);
// TODO: handle properly - move this to page.tsx before fetch and redirect to notfound ?
Expand Down