Skip to content

Commit

Permalink
Merge pull request #159 from FinalDoubleTen/FE-85--feat/OurTripPrefer
Browse files Browse the repository at this point in the history
Fe 85  feat/our trip prefer
  • Loading branch information
seungjun222 authored Jan 13, 2024
2 parents 1f13c30 + 0768d3e commit 038a9e0
Show file tree
Hide file tree
Showing 9 changed files with 240 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/components/Review/ReviewComments.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ export default function ReviewComments() {
}
})}
</div>
<div className="h-[70px]"></div>
</InfiniteScroll>
</div>
<Modal isOpen={isModalOpen} closeModal={closeModal}>
Expand Down
208 changes: 208 additions & 0 deletions src/components/Trip/TripPreference.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
import React, { useState, useEffect } from 'react';
import { getTripsSurvey } from '@api/trips';
import { useQuery } from '@tanstack/react-query';
import { useParams } from 'react-router-dom';
import { MoreIcon } from '@components/common/icons/Icons';
import { RightIcon } from '@components/common/icons/Icons';
import {
calculatePercentage,
calculatePercentageRemain,
} from '@utils/calculatePercentage';

interface RatioBarParams {
value: number;
total: number;
color: string;
label1: string;
label2: string;
}

interface PercentageParams {
value: number;
total: number;
color: string;
}

const TripPreferenceButton: React.FC = () => {
return (
<button className="mb-[17.5px] mt-[20px] flex w-[335px] items-center rounded-full bg-white px-6 py-4 text-sm">
<div className="text-gray6">내 여행 취향 설정하러 가기</div>
<div className="ml-auto">
<RightIcon fill="#5E5E5E" />
</div>
</button>
);
};

const RatioBar = ({ value, total, color, label1, label2 }: RatioBarParams) => {
const width =
value >= total - value
? Math.round((175 * value) / total)
: Math.round((175 * (total - value)) / total);
return (
<div className="mb-1 flex items-center text-sm">
{value >= total - value ? (
<>
<div className={`w-[65px] font-bold text-${color}`}>{label1}</div>
<div className="flex h-[10px] w-[175px] rounded-full bg-gray2">
<div style={{ width }} className={`rounded-full bg-${color}`}></div>
</div>
<div className="ml-auto text-gray6">{label2}</div>
</>
) : (
<>
<div className={`w-[65px] text-gray6`}>{label1}</div>
<div className="flex h-[10px] w-[175px] rounded-full bg-gray2">
<div
style={{ width }}
className={`ml-auto rounded-full bg-${color}`}></div>
</div>
<div className={`text-${color} ml-auto font-bold`}>{label2}</div>
</>
)}
</div>
);
};

const Percentage = ({ value, total, color }: PercentageParams) => (
<div className="flex justify-between text-gray6">
{value >= total - value ? (
<>
<div className={`font-bold text-${color}`}>
{calculatePercentage(value, total)}%
</div>
<div className="text-gray6">
{calculatePercentageRemain(value, total)}%
</div>
</>
) : (
<>
<div className="text-gray6">{calculatePercentage(value, total)}%</div>
<div className={`font-bold text-${color}`}>
{calculatePercentageRemain(value, total)}%
</div>
</>
)}
</div>
);

const TripPreference: React.FC = () => {
const params = useParams();
const tripId = Number(params.id);
const [A, setA] = useState<[number, number]>([0, 0]);
const [B, setB] = useState<[number, number]>([0, 0]);
const [C, setC] = useState<[number, number]>([0, 0]);
const [D, setD] = useState<[number, number]>([0, 0]);
const [E, setE] = useState<[number, number]>([0, 0]);

const { data: tripPreference, isLoading } = useQuery({
queryKey: ['tripPreference', tripId],
queryFn: () => getTripsSurvey(tripId),
});

useEffect(() => {
if (tripPreference) {
setA([
tripPreference?.data?.data?.planningCount,
tripPreference?.data?.data?.planningTotalCount,
]);
setB([
tripPreference?.data?.data?.activeHoursCount,
tripPreference?.data?.data?.activeHoursTotalCount,
]);
setC([
tripPreference?.data?.data?.accommodationCount,
tripPreference?.data?.data?.accommodationTotalCount,
]);
setD([
tripPreference?.data?.data?.foodCount,
tripPreference?.data?.data?.foodTotalCount,
]);
setE([
tripPreference?.data?.data?.tripStyleCount,
tripPreference?.data?.data?.tripStyleTotalCount,
]);
}
}, [tripPreference]);

if (isLoading) {
return <div>Loading...</div>;
}

return (
<div className=" mb-[-20px] ml-[-40px] mr-[-40px] mt-[-20px] flex flex-col items-center bg-gray1 ">
<TripPreferenceButton />
<div className="mb-[20px] ml-auto mr-[40px] flex items-center text-sm ">
<div>n명 참여</div>
<div className="mt-0.5">
<MoreIcon size={20} color="none" fill="#888888" />
</div>
</div>
{tripPreference?.data?.data && (
<div>
<div className="mb-4 h-[104px] w-[335px] rounded-xl bg-white px-4 py-4">
<div className="text-md mb-3 font-bold">계획성</div>
<RatioBar
value={A[0]}
total={A[1]}
color="sub2"
label1="철저하게"
label2="여유롭게"
/>
<Percentage value={A[0]} total={A[1]} color="sub2" />
</div>

<div className="mb-4 h-[104px] w-[335px] rounded-xl bg-white px-4 py-4">
<div className="text-md mb-3 font-bold">활동시간</div>
<RatioBar
value={B[0]}
total={B[1]}
color="main2"
label1="아침형"
label2="저녁형"
/>
<Percentage value={B[0]} total={B[1]} color="main2" />
</div>

<div className="mb-4 h-[104px] w-[335px] rounded-xl bg-white px-4 py-4">
<div className="text-md mb-3 font-bold">숙소</div>
<RatioBar
value={C[0]}
total={C[1]}
color="purple"
label1="분위기"
label2="가격"
/>
<Percentage value={C[0]} total={C[1]} color="purple" />
</div>

<div className="mb-4 h-[104px] w-[335px] rounded-xl bg-white px-4 py-4">
<div className="text-md mb-3 font-bold">음식</div>
<RatioBar
value={D[0]}
total={D[1]}
color="orange"
label1="노포"
label2="인테리어"
/>
<Percentage value={D[0]} total={D[1]} color="orange" />
</div>

<div className="mb-4 h-[104px] w-[335px] rounded-xl bg-white px-4 py-4">
<div className="text-md mb-3 font-bold">관광지</div>
<RatioBar
value={E[0]}
total={E[1]}
color="green"
label1="액티비티"
label2="휴양"
/>
<Percentage value={E[0]} total={E[1]} color="green" />
</div>
</div>
)}
</div>
);
};

export default TripPreference;
3 changes: 2 additions & 1 deletion src/components/Trip/TripSectionTop.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Tab from '@components/common/tab/Tab';
import TripPreference from './TripPreference';
import TripInfo from './TripInfo';
import { BackBox } from '@components/common';
import { useNavigate } from 'react-router-dom';
Expand All @@ -20,7 +21,7 @@ const TripSectionTop = () => {
<PlanTripButton />
<Tab
lists={['우리의 여행취향', '우리의 관심목록']}
contents={[<div>우리의 여행취향</div>, <div>우리의 관심목록</div>]}
contents={[<TripPreference />, <div>우리의 관심목록</div>]}
/>
</div>
);
Expand Down
3 changes: 3 additions & 0 deletions src/components/common/modal/children/EditDelete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
targetCommentIdState,
targetReviewIdState,
tourItemIdState,
// inputFocusState,
} from '@recoil/review';
import React from 'react';
import { useNavigate } from 'react-router-dom';
Expand All @@ -39,6 +40,7 @@ const EditDelete: React.FC = () => {
const setModalChildren = useSetRecoilState(modalChildrenState);
const setComment = useSetRecoilState(commentState);
const setAlertType = useSetRecoilState(alertTypeState);
// const setInputFocus = useSetRecoilState(inputFocusState);
const queryClient = useQueryClient();

const handleEdit = () => {
Expand All @@ -58,6 +60,7 @@ const EditDelete: React.FC = () => {
} else if (title == '내 댓글') {
setIsModifyingComment(true);
setIsModalOpen(false);
// setInputFocus(true);
}
};

Expand Down
13 changes: 11 additions & 2 deletions src/components/common/nav/InputComment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import { useParams } from 'react-router-dom';
import { commentState } from '@recoil/review';
import { useRecoilState, useRecoilValue, useSetRecoilState } from 'recoil';
import { putComments } from '@api/comments';
import { isModifyingCommentState, targetCommentIdState } from '@recoil/review';
import {
isModifyingCommentState,
targetCommentIdState,
// inputFocusState,
} from '@recoil/review';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { getItem } from '@utils/localStorageFun';
import {
Expand Down Expand Up @@ -35,6 +39,8 @@ export const InputComment: React.FC<InputCommentProps> = () => {
isModifyingCommentState,
);
const targetCommentId = useRecoilValue(targetCommentIdState);
// const [inputFocus, setInputFocus] = useRecoilState(inputFocusState);
// const inputRef = useRef<HTMLInputElement>(null);
const queryClient = useQueryClient();
const setIsModalOpen = useSetRecoilState(isModalOpenState);
const setModalChildren = useSetRecoilState(modalChildrenState);
Expand Down Expand Up @@ -78,6 +84,7 @@ export const InputComment: React.FC<InputCommentProps> = () => {
if (isModifyingComment) {
await editReviewMutate({ comment, targetCommentId });
setIsModifyingComment(false);
// setInputFocus(false);
} else {
await postReviewMutate({ comment, reviewId });
}
Expand All @@ -93,12 +100,14 @@ export const InputComment: React.FC<InputCommentProps> = () => {
handleSubmit();
}
};

return (
<div className="sticky bottom-0 mt-auto flex flex h-[64px] w-full items-center justify-center border border-solid border-[#EDEDED] bg-white ">
<div className="fixed bottom-0 mt-auto flex flex h-[64px] w-full items-center justify-center border border-solid border-[#EDEDED] bg-white ">
<div className="ml-4 mr-4 flex h-[40px] w-full items-center rounded-md border border-solid border-[#EDEDED]">
<div className="pl-1 pr-0.5 text-sm font-bold text-[#29ddf6]"></div>
<div className="flex w-full ">
<input
// ref={inputRef}
type="text"
placeholder="댓글을 입력하세요"
className=" w-full max-w-full text-sm placeholder-[#d7d7d7] outline-none"
Expand Down
5 changes: 5 additions & 0 deletions src/recoil/review.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ export const toastPopUpState = atom({
verb: '',
},
});

export const inputFocusState = atom({
key: 'inputFocusState',
default: false,
});
1 change: 1 addition & 0 deletions src/router/routerLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const MainLayout = () => {
'/myPageReview',
'/info',
'/survey',
'/trip',
];
const showNav = !hideNavPaths.some((path) =>
location.pathname.includes(path),
Expand Down
6 changes: 6 additions & 0 deletions src/utils/calculatePercentage.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// utils.ts
export const calculatePercentage = (count: number, totalCount: number) =>
((count / totalCount) * 100).toFixed(0);

export const calculatePercentageRemain = (count: number, totalCount: number) =>
(((totalCount - count) / totalCount) * 100).toFixed(0);
3 changes: 3 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ export default {
gray6: '#38393C',
gray7: '#1E1E1E',
red: '#FF0F00',
purple: '#7932FF',
orange: '#FFAC16',
green: '#16E7A9',
},
},
},
Expand Down

0 comments on commit 038a9e0

Please sign in to comment.