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

Feat: trip connect wish #244

Merged
merged 2 commits into from
Jan 28, 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
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {Button} from '@chakra-ui/react';
import {useLocation, useNavigate} from 'react-router-dom';
import {useRecoilValue} from 'recoil';
import {useRecoilValue, useSetRecoilState} from 'recoil';

import {selectedPlaceState} from '@/recoil/vote/selectPlace';
import {usePostPlaces} from '@/hooks/Spaces/space';

import {selectedPlaceState, selectedTripPlaceState} from '@/recoil/vote/selectPlace';

//prop이나 params로 trip or vote 판별, onClick에 삼항연산자로 함수 넣기
const AddToCandidateButton = () => {
const selectedPlaces = useRecoilValue(selectedPlaceState);
const counts = selectedPlaces.length;
const location = useLocation();
const queryParams = new URLSearchParams(location.search);
const spaceId = queryParams.get('placeID');
Expand All @@ -16,10 +16,28 @@ const AddToCandidateButton = () => {
const voteIdArray = tripDateParam?.split(' ') as string[]; // 띄어쓰기를 기준으로 문자열 분할
const isInVote = voteIdArray[0] === 'vote';
const voteId = voteIdArray[1];
const selectedPlaces = useRecoilValue(selectedPlaceState);
const selectedTripPlaces = useRecoilValue(selectedTripPlaceState);
const setTripRecoil = useSetRecoilState(selectedTripPlaceState);
const counts = isInVote ? selectedPlaces.length : selectedTripPlaces.length;
const postPlaces = usePostPlaces();

const addPlaces = async () => {
await postPlaces.mutateAsync({
spaceId: Number(spaceId),
journeyId: Number(voteId),
placeIds: selectedTripPlaces,
});
navigate(`/trip/${spaceId}`, {state: {id: spaceId}});
setTripRecoil([]);
};

const handleAddCandidates = () => {
// 경로 추후 수정
if (isInVote) {
navigate(`/trip/${spaceId}/votes/${voteId}/votememo`, {replace: true});
} else {
addPlaces();
}
};
return (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {useEffect, useState} from 'react';
import {useRecoilValue} from 'recoil';
import {useRecoilValue, useSetRecoilState} from 'recoil';

import styles from './SelectButton.module.scss';

import useGetSelectedArray from '@/hooks/useGetSelectedArray';

import {selectedPlaceState} from '@/recoil/vote/selectPlace';
import {selectedPlaceState, selectedTripPlaceState} from '@/recoil/vote/selectPlace';

import {SearchItemType} from '@/types/home';

Expand All @@ -15,22 +15,41 @@ interface Propstype {

const SelectButton = ({data}: Propstype) => {
const [isClicked, setIsClicked] = useState(false);
const queryParams = new URLSearchParams(location.search);
const tripDateParam = queryParams.get('tripDate');
const voteIdArray = tripDateParam?.split(' ') as string[]; // 띄어쓰기를 기준으로 문자열 분할
const isInVote = voteIdArray[0] === 'vote';
const selectedPlaces = useRecoilValue(selectedPlaceState);

const selectedTripPlaces = useRecoilValue(selectedTripPlaceState);
const setRecoil = useSetRecoilState(selectedTripPlaceState);
const {toggleItemInNewArray} = useGetSelectedArray(selectedPlaceState);

const handleClick = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>) => {
console.log(selectedTripPlaces);

e.preventDefault();
setIsClicked((prev) => !prev);
toggleItemInNewArray(data);
if (isInVote) {
toggleItemInNewArray(data);
} else {
setRecoil((prev) => [...prev, data.id]);
}
};

useEffect(() => {
selectedPlaces.map((selectData) => {
if (selectData.id === data.id) {
setIsClicked(true);
}
});
if (isInVote) {
selectedPlaces.map((selectData) => {
if (selectData.id === data.id) {
setIsClicked(true);
}
});
} else {
selectedTripPlaces.map((selectData) => {
if (selectData === data.id) {
setIsClicked(true);
}
});
}
}, [data]);

return (
Expand Down
9 changes: 5 additions & 4 deletions src/components/Home/TripSpaceAtHome/TripSpaceAtHome.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useEffect, useState} from 'react';
import {Cookies} from 'react-cookie';

import styles from './TripSpaceAtHome.module.scss';

Expand All @@ -17,13 +18,13 @@ function TripSpaceAtHome() {
const [data, setData] = useState<TripSpaceData[]>();
const [slideLocation, setSlideLocation] = useState<number>(0);
const [componentRef, size] = useComponentSize();
const cookie = new Cookies().get('isLogin');

useEffect(() => {
getHomeTripSpace(setData);
if (cookie) {
getHomeTripSpace(setData);
}
}, []);
useEffect(() => {
console.log(data);
}, [data]);

return (
<div className={styles.container}>
Expand Down
6 changes: 4 additions & 2 deletions src/components/Home/VoteAtHome/VoteAtHome.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {useEffect, useState} from 'react';
import {Cookies} from 'react-cookie';

import styles from './VoteAtHome.module.scss';

Expand All @@ -13,13 +14,14 @@ import {Vote} from '@/types/home';

function VoteAtHome() {
const [data, setData] = useState<Vote>();
const cookie = new Cookies().get('isLogin');
const userData = useGetMyInfo(true).data?.data.nickname;

useEffect(() => {
if (userData) {
if (cookie) {
getHomeVote(setData);
}
}, [userData]);
}, []);

return (
<div className={styles.container}>
Expand Down
10 changes: 8 additions & 2 deletions src/components/Route/AddPlace/AddPlace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ function AddPlace({journeyId, day}: AddPlaceProps) {
<button
onClick={() => {
navigate(
`/search?keyword=없음&category=0&map=false&location=전국&sort=등록순&hot=false&placeID=여기에넣어줘요&tripDate=여기에넣어줘요`,
`/search?keyword=없음&category=0&map=false&location=전국&sort=등록순&hot=false&placeID=${spaceId}&tripDate=trip ${journeyId}`,
);
}}
>
Expand All @@ -29,7 +29,13 @@ function AddPlace({journeyId, day}: AddPlaceProps) {
<p>장소 검색</p>
</div>
<div className={styles.buttonContainer}>
<button>
<button
onClick={() => {
navigate(
`/wishes/bring?category=0&location=전국&sort=등록순&placeID=${spaceId}&tripDate=trip ${journeyId}`,
);
}}
>
<WishIcon color='#FF85B1' size='2.4rem' />
</button>
<p>찜 목록 검색</p>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,20 @@
.container {
position: relative;

height: 2.4rem;

display: flex;
align-items: center;
@include typography(button);
.button {
height: 2.4rem;

padding: 4px 8px;
display: flex;
align-items: center;

cursor: pointer;
padding: 4px 8px;

@include typography(button);

.icon {
width: 2.4rem;
height: 2.4rem;
cursor: pointer;
.icon {
width: 2.4rem;
height: 2.4rem;
}
}

.modal {
Expand All @@ -30,8 +30,6 @@
flex-direction: column;
justify-content: space-between;

padding: 20px 32px;

border-radius: 16px;

background-color: $neutral0;
Expand All @@ -42,6 +40,10 @@

overflow: hidden;

transition: 0.5s all;
box-sizing: border-box;

transition:
0.5s opacity,
0.5s height;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,15 @@ function DateFilter({forSearch = undefined, wishesFilter = undefined}: PropsType
}, [forSearch?.sort]);

return (
<div className={styles.container} onClick={handleModal}>
<BsFilterLeft className={styles.icon} />
<span style={{userSelect: 'none', whiteSpace: 'none'}}>{sort}</span>
<div className={styles.modal} style={{height: click ? '136px' : 0, opacity: click ? 1 : 0}}>
<div className={styles.container}>
<p className={styles.button} onClick={handleModal}>
<BsFilterLeft className={styles.icon} />
<span style={{userSelect: 'none', whiteSpace: 'none'}}>{sort}</span>
</p>
<div
className={styles.modal}
style={{height: click ? '136px' : 0, opacity: click ? 1 : 0, padding: click ? '20px 32px' : 0}}
>
{filterData.map((data) => (
<span
style={{opacity: click ? 1 : 0, whiteSpace: 'none'}}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
gap: 12px;

.itemBox {
flex: 1;

max-height: 70px;

display: flex;
Expand All @@ -29,6 +31,8 @@
}

.text {
flex: 1;

display: flex;
flex-direction: column;
gap: 2px;
Expand All @@ -38,6 +42,7 @@
transition: 0.3s all linear;

.title {
max-width: calc(100% - 30px);
height: 24px;

text-overflow: ellipsis;
Expand Down
2 changes: 0 additions & 2 deletions src/components/SearchFromHome/SearchList/SearchList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ function SearchList({forSearch}: PropsType) {
}, [inView]);

useEffect(() => {
console.log(data);

if (data) {
if (forSearch.category !== 0) {
const filterData: SearchItemType[][] = [];
Expand Down
4 changes: 3 additions & 1 deletion src/components/VoteMemo/MemoItem/MemoItem.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@ import {useDebounce} from '@/hooks/useDebounce';
import useGetSelectedArray from '@/hooks/useGetSelectedArray';

import {selectedTaglineState} from '@/recoil/vote/voteMemo';
import titleCaseChange from '@/utils/titleCaseChange';

import {MemoItemProps} from '@/types/vote';

const MemoItem = ({place, existingTagline}: MemoItemProps) => {
const [text, setText] = useState('');
const {toggleItemInNewArray, setMemoArray} = useGetSelectedArray(selectedTaglineState);
const debouncedText = useDebounce(text, 500);
const title = titleCaseChange(place.title);

useEffect(() => {
if (existingTagline) {
Expand Down Expand Up @@ -57,7 +59,7 @@ const MemoItem = ({place, existingTagline}: MemoItemProps) => {
<img src={place.thumbnail} alt={place.title} />
</div>
<div className={styles.candidateBox__text}>
<p className={styles.candidateBox__text__name}>{place.title}</p>
<p className={styles.candidateBox__text__name}>{title}</p>
<span className={styles.candidateBox__text__category}>
{place.contentTypeId}
{'ꞏ'}
Expand Down
6 changes: 6 additions & 0 deletions src/recoil/vote/selectPlace.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,9 @@ export const selectedPlaceState = atom<SearchItemType[]>({
default: [],
effects_UNSTABLE: [persistAtom],
});

export const selectedTripPlaceState = atom<number[]>({
key: 'selectedTripPlaceState',
default: [],
effects_UNSTABLE: [persistAtom],
});
Loading