Skip to content

Commit

Permalink
Merge pull request #176 from KNU-HAEDAL/Feat/issue-#175
Browse files Browse the repository at this point in the history
최근 챌린지 리뷰
  • Loading branch information
Dobbymin authored Sep 30, 2024
2 parents 667d79f + 709e3c0 commit 4f7104d
Show file tree
Hide file tree
Showing 3 changed files with 136 additions and 41 deletions.
27 changes: 27 additions & 0 deletions src/apis/recently-review/getRecentlyReview.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { RecentlyReviewResponse } from './getRecentlyReview.response';
import { axiosClient } from '@/apis/AxiosClient';
import { useQuery } from '@tanstack/react-query';

const getRecentlyReviewPath = () => '/api/challengeGroups/shorts';

const recentlyReviewQueryKey = [getRecentlyReviewPath()];

const getRecentlyReview = async (
page: number,
size: number
): Promise<RecentlyReviewResponse> => {
const response = await axiosClient.get(getRecentlyReviewPath(), {
params: {
page,
size,
},
});
return response.data;
};

export const useGetRecentlyReview = (page: number, size: number) => {
return useQuery<RecentlyReviewResponse, Error>({
queryKey: [recentlyReviewQueryKey, page, size],
queryFn: () => getRecentlyReview(page, size),
});
};
24 changes: 24 additions & 0 deletions src/apis/recently-review/getRecentlyReview.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import ApiResponse from '@/apis/ApiResponse';

export type RecentlyReviewResponse = {
totalPage: number;
hasNext: boolean;
data: {
challengeId: number;
challengeTitle: string;
user: {
id: number;
nickname: string;
profileImageUrl: string;
tierInfo: {
tier: string;
totalExp: number;
currentExp: number;
};
};
content: string;
rating: number;
}[];
};

export type ChallengeListResponse = ApiResponse<RecentlyReviewResponse>;
126 changes: 85 additions & 41 deletions src/pages/main/components/review/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
import { useGetRecentlyReview } from '@/apis/recently-review/getRecentlyReview.api';
import StarIcon from '@/assets/main/Star-Icon.svg';
import ProfileIcon from '@/assets/main/ZZAN-Profile.png';
import { Box, Image, Text } from '@chakra-ui/react';
import { Box, Image, Text, Spinner } from '@chakra-ui/react';
import styled from '@emotion/styled';

const Review = () => {
const { data, isLoading } = useGetRecentlyReview(0, 10);

if (isLoading) {
return (
<Box
display='flex'
justifyContent='center'
alignItems='center'
height='100vh'
>
<Spinner size='xl' />
</Box>
);
}

return (
<>
<Text
Expand All @@ -16,46 +32,56 @@ const Review = () => {
최근 챌린지 리뷰
</Text>
<ReviewLayout>
<ChallengeLayout>
{!data || data?.data.length === 0 ? (
<Text
fontSize='1.25rem'
marginTop='0.5rem'
marginBottom='0.5rem'
marginLeft='0.5rem'
fontWeight={700}
color='var(--color-green-07)'
textAlign='center'
>
쓰레기 줍기 챌린지
최근 챌린지 리뷰가 존재하지 않아요..
</Text>
<Box display='flex' margin='0.5rem' gap='0.2rem'>
<StarImg src={StarIcon} />
<StarImg src={StarIcon} />
<StarImg src={StarIcon} />
</Box>
<ReviewProfileContainer>
<Image src={ProfileIcon} />
<Text
fontWeight='700'
fontSize='1rem'
color='#fff'
textAlign='left'
fontStyle='normal'
lineHeight='normal'
>
짠돌이
</Text>
</ReviewProfileContainer>
<Box width='100%'>
<Text
fontWeight='700'
fontSize='1rem'
color='#fff'
textAlign='left'
fontStyle='normal'
lineHeight='normal'
>
세상이 깨끗해지는 기분이에요! 포인트도 많이줘서 등급 올리기 ...
</Text>
</Box>
</ChallengeLayout>
) : (
data?.data.map((review) => (
<ChallengeLayout key={review.challengeId}>
<Text
fontSize='1.4rem'
fontWeight={700}
color='var(--color-green-07)'
marginTop='0.5rem'
marginBottom='0.5rem'
marginLeft='0.5rem'
>
{review.challengeTitle}
</Text>
<Box display='flex' ml={1} gap='0.2rem'>
{Array.from({ length: review.rating }, (_, index) => (
<StarImg key={index} src={StarIcon} />
))}
</Box>
<ReviewProfileContainer>
<ImageBox
src={review.user.profileImageUrl || ProfileIcon} // 프로필 이미지가 없으면 기본 이미지 사용
/>
<Text fontWeight='700' fontSize='1rem' color='#fff'>
{review.user.nickname}
</Text>
</ReviewProfileContainer>
<Box width='100%'>
<Text
fontWeight='700'
fontSize='1rem'
color='#fff'
textAlign='left'
fontStyle='normal'
lineHeight='normal'
>
{review.content}
</Text>
</Box>
</ChallengeLayout>
))
)}
</ReviewLayout>
</>
);
Expand All @@ -69,19 +95,29 @@ const Container = styled(Box)`
`;

const ReviewLayout = styled(Container)`
height: 15.5625rem;
padding: 0.9375rem 4.8125rem 0.9375rem 0.8125rem;
display: flex;
overflow-x: scroll;
height: 15.5rem;
padding: 0.9375rem 0.8125rem;
margin: 1rem;
border-radius: 1.25rem;
background: var(--green--06, rgba(240, 244, 243, 0.75));
background: var(--color-green-06);
box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
&::-webkit-scrollbar {
display: none;
}
`;

const ChallengeLayout = styled.div`
flex-shrink: 0;
display: flex;
flex-direction: column;
width: 18rem;
height: 13.7rem;
padding: 1rem;
margin-right: 1rem;
border-radius: 1.25rem;
background-color: var(--color-green-01);
box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
Expand All @@ -99,5 +135,13 @@ const ReviewProfileContainer = styled(Container)`
flex-direction: row;
justify-content: space-between;
width: 5.5rem;
gap: 0.25rem;
`;

const ImageBox = styled(Image)`
display: flex;
width: 2rem;
justify-content: center;
align-items: center;
border-radius: 50%;
box-shadow: 0px 4px 4px 0px rgba(0, 0, 0, 0.25);
`;

0 comments on commit 4f7104d

Please sign in to comment.