Skip to content

Commit

Permalink
Merge pull request #163 from KNU-HAEDAL/develop
Browse files Browse the repository at this point in the history
개발 진행상황 합치기
  • Loading branch information
Dobbymin authored Sep 28, 2024
2 parents 6788867 + 58844b1 commit 91feded
Show file tree
Hide file tree
Showing 37 changed files with 1,271 additions and 762 deletions.
26 changes: 26 additions & 0 deletions .github/workflow/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: ESLint test

on:
pull_request:
branches:
- main
- develop
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- name: Checkout Code
uses: actions/checkout@v4

- name: Install Pnpm package manager
run: |
npm install -g pnpm
- name: Install Dependencies
run: pnpm install

- name: Lint Code
run: pnpm lint
27 changes: 27 additions & 0 deletions src/apis/challenge-list/getChallengeList.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { ChallengeListResponse } from './getChallengeList.response';
import { axiosClient } from '@/apis/AxiosClient';
import { useQuery } from '@tanstack/react-query';

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

const challengeListQueryKey = [getChallengeListPath()];

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

export const useGetChallengeList = (page: number, size: number) => {
return useQuery<ChallengeListResponse, Error>({
queryKey: [challengeListQueryKey, page, size],
queryFn: () => getChallengeList(page, size),
});
};
17 changes: 17 additions & 0 deletions src/apis/challenge-list/getChallengeList.response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import ApiResponse from '@/apis/ApiResponse';

export type ChallengeListData = {
totalPage: number;
hasNext: boolean;
data: {
id: number;
title: string;
content: string;
participantCount: number;
startDate: string;
endDate: string;
category: 'HEALTH' | 'ECHO' | 'SHARE' | 'VOLUNTEER' | 'ETC';
}[];
};

export type ChallengeListResponse = ApiResponse<ChallengeListData>;
24 changes: 11 additions & 13 deletions src/apis/review/review.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { AxiosError } from 'axios';
import { axiosClient } from '../AxiosClient';
import type {
GetReviewResponse,
PostReviewData,
ChallengeAvgScoreData,
} from './review.response';

Expand Down Expand Up @@ -65,31 +64,30 @@ type PostReviewParams = {
challengeId: number;
content: string;
rating: number;
difficulty: number | undefined;
achievement: number | undefined;
};

export async function postReview({
challengeId,
content,
rating,
}: PostReviewParams): Promise<PostReviewData> {
const body = { content, rating };
// console.log('json : ', JSON.stringify(body));
difficulty,
achievement,
}: PostReviewParams): Promise<void> {
const requestBody = { content, rating, difficulty, achievement };

try {
const response = await axiosClient.post(
`/api/challenges/${challengeId}/reviews`,
body
requestBody
);
console.log('postReview response: ', response.data);

return response.data.data;
} catch (error) {
if (error instanceof AxiosError) {
throw new Error(
`postReview error: ${error.response?.data.message || error.message}`
);
} else {
throw new Error('postReview error: unexpected');
if (error instanceof AxiosError && error.response) {
throw error.response.data;
}
// AxiosError가 아닌 경우 일반적인 예외 처리
throw new Error('postReview error: unexpected');
}
}
8 changes: 6 additions & 2 deletions src/apis/review/review.response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ export type ReviewData = {
user: User;
content: string;
rating: number;
difficulty: number;
achievement: number;
createdAt: string;
};

export const DummyReviewList: ReviewData[] = [
Expand All @@ -40,6 +43,9 @@ export const DummyReviewList: ReviewData[] = [
content:
'매일 매일 꾸준히 했더니 습관이 형성되었어요. 습관도 만들고 포인트도 얻고 좋아요 굿',
rating: 4,
difficulty: 1,
achievement: 1,
createdAt: '2024-09-26T21:16:18',
},
];

Expand All @@ -53,5 +59,3 @@ export type ChallengeAvgScoreData = {
};

//

export type PostReviewData = number;
14 changes: 14 additions & 0 deletions src/components/common/chip/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import styled from '@emotion/styled';

export const Chip = styled.div<{ margin?: string; color?: string }>`
padding: 4px 12px;
border-radius: 50px;
border: ${({ color }) =>
color ? `${color} 0.5px solid` : `var(--color-green-01) 0.5px solid`};
background-color: var(--color-white);
color: ${({ color }) => (color ? color : `var(--color-green-01)`)};
font-size: var(--font-size-xs);
font-weight: 600;
text-align: center;
margin: ${({ margin }) => (margin ? `${margin}` : null)};
`;
14 changes: 14 additions & 0 deletions src/components/common/profile-image/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import UserImage from '@/assets/UserImage.svg';
import styled from '@emotion/styled';

export const ProfileImage = styled.div<{ size?: number; src?: string }>`
width: ${({ size }) => (size ? `${size}rem` : '3rem')};
height: ${({ size }) => (size ? `${size}rem` : '3rem')};
aspect-ratio: 1 / 1;
border-radius: 50%;
background-image: url(${({ src }) => src || UserImage});
background-size: cover;
background-position: center;
background-repeat: no-repeat;
`;
44 changes: 31 additions & 13 deletions src/components/common/star-rating/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,51 +5,69 @@ import styled from '@emotion/styled';
interface StarRatingProps {
rating: number;
size?: number;
onClick?: (rating: number) => void;
}

export const StarRating = ({ rating, size = 24 }: StarRatingProps) => {
// rating(별점)을 백분율로 변환
const [ratingToPercent, setRatingToPercent] = useState<string>(`0%`);
export const StarRating = ({ rating, size = 24, onClick }: StarRatingProps) => {
const [ratingToPercent, setRatingToPercent] = useState<number>(0);

useEffect(() => {
if (rating !== undefined) {
setRatingToPercent(`${(rating / 5) * 100}%`);
setRatingToPercent((rating / 5) * 100);
}
}, [rating]);

const handleClick = (rating: number) => {
if (onClick) {
onClick(rating + 1); // 클릭한 별점 값 전달 (1부터 시작)
}
};

return (
<Wrapper size={size}>
<StarFill style={{ width: ratingToPercent }}>
<FilledStars ratingToPercent={ratingToPercent}>
{[...Array(5)].map((_, index) => (
<span key={`fill-${index}`}></span>
<Star key={`fill-${index}`} onClick={() => handleClick(index)}>
</Star>
))}
</StarFill>
<StarBase>
</FilledStars>
<BaseStars>
{[...Array(5)].map((_, index) => (
<span key={`base-${index}`}></span>
<Star key={`base-${index}`} onClick={() => handleClick(index)}>
</Star>
))}
</StarBase>
</BaseStars>
</Wrapper>
);
};

const Wrapper = styled.div<{ size: number }>`
const Wrapper = styled.div<{ size: number; cursor?: string }>`
position: relative;
unicode-bidi: bidi-override;
width: max-content;
-webkit-text-fill-color: transparent;
-webkit-text-stroke-width: 0.8px;
-webkit-text-stroke-color: var(--color-green-01);
font-size: ${({ size }) => `${size}px`};
cursor: ${({ cursor }) => cursor && 'pointer'};
`;

const StarFill = styled.div`
const FilledStars = styled.div<{ ratingToPercent: number }>`
position: absolute;
display: flex;
top: 0;
left: 0;
width: ${({ ratingToPercent }) => `${ratingToPercent}%`};
overflow: hidden;
-webkit-text-fill-color: var(--color-green-01);
`;

const StarBase = styled.div``;
const BaseStars = styled.div`
display: flex;
`;

const Star = styled.button`
outline: none;
`;
78 changes: 0 additions & 78 deletions src/components/common/tab/index.tsx

This file was deleted.

Loading

0 comments on commit 91feded

Please sign in to comment.