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: create wishes api #179

Merged
merged 3 commits into from
Jan 25, 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
24 changes: 22 additions & 2 deletions src/api/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ export const getIsWish = async (id: number, setIsWish: React.Dispatch<React.SetS

setIsWish(response.data.data);

console.log(response.data);

return response.data;
};

Expand Down Expand Up @@ -75,12 +77,30 @@ export const getMySpaces = async (page: number, size: number, sort: string): Pro

// --------------------------- POST ---------------------------

export const PostWishes = async ({placeId, contentTypeId}: Wishes) => {
export const postWishes = async ({placeId, contentTypeId}: Wishes) => {
try {
const response = await axios.post('/api/wishes', {placeId, contentTypeId});
const response = await axios.post(
'/api/wishes',
{placeId, contentTypeId},
{
withCredentials: true,
},
);
console.log('axios 포스트 성공', response);
return response.data;
} catch (error) {
console.error(error);
}
};

// --------------------------- DELETE ---------------------------

export const deleteWishes = async (id: number) => {
try {
const response = await axios.delete(`/api/wishes/${id}`);
console.log('axios delete success', response);
return response.data;
} catch (error) {
console.error(error);
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ interface BasicInformationProps {
openTime: string;
title: string;
thumbnail: string;
id: number;
contentTypeId: number;
}

function BasicInformation({location, openTime, title, thumbnail, contentTypeId}: BasicInformationProps) {
function BasicInformation({location, openTime, title, thumbnail, id, contentTypeId}: BasicInformationProps) {
return (
<div className={styles.container}>
<div className={styles.container__title}>기본정보</div>
Expand All @@ -33,6 +34,7 @@ function BasicInformation({location, openTime, title, thumbnail, contentTypeId}:
lng={location.longitude}
title={title}
thumbnail={thumbnail}
id={id}
contentTypeId={contentTypeId}
areaCode={location.areaCode}
/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,13 @@ interface MapInDetailProps {
lng: number;
title: string;
thumbnail: string;
id: number;
contentTypeId: number;
areaCode: number;
}

// 장소 정보에 따라 마커 다르게 표시
function MapInDetail({lat, lng, title, thumbnail, contentTypeId, areaCode}: MapInDetailProps) {
function MapInDetail({lat, lng, title, thumbnail, id, contentTypeId, areaCode}: MapInDetailProps) {
const {isOpen, onOpen, onClose} = useDisclosure();

// useEffect(() => {
Expand Down Expand Up @@ -63,6 +64,7 @@ function MapInDetail({lat, lng, title, thumbnail, contentTypeId, areaCode}: MapI
thumbnail={thumbnail}
contentTypeId={contentTypeId}
areaCode={areaCode}
id={id}
/>
</>
);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {Drawer, DrawerBody, DrawerContent, DrawerFooter, DrawerHeader} from '@chakra-ui/react';
import {AiOutlineLeft} from 'react-icons/ai';
import {FaRegHeart} from 'react-icons/fa';
import {CustomOverlayMap, Map} from 'react-kakao-maps-sdk';

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

import BigHomeMarker from '@/assets/homeIcons/map/house_big.svg?react';
import WishBtn from '@/components/WishBtn/WishBtn';

interface MapModalProps {
isOpen: boolean;
Expand All @@ -14,11 +14,12 @@ interface MapModalProps {
lng: number;
title: string;
thumbnail: string;
id: number;
contentTypeId: number;
areaCode: number;
}

function MapModal({isOpen, onClose, lat, lng, title, thumbnail, contentTypeId, areaCode}: MapModalProps) {
function MapModal({isOpen, onClose, lat, lng, title, thumbnail, id, contentTypeId, areaCode}: MapModalProps) {
return (
<Drawer
isOpen={isOpen}
Expand Down Expand Up @@ -51,12 +52,7 @@ function MapModal({isOpen, onClose, lat, lng, title, thumbnail, contentTypeId, a
{contentTypeId} {areaCode}
</p>
</div>
<FaRegHeart
fontSize='2.4rem'
cursor='pointer'
className={styles.footer__card__icon}
// onClick={handleHeartClick}
/>
<WishBtn placeId={id} contentTypeId={contentTypeId} size={'2.4rem'} className={styles.footer__card__icon} />
</div>
</DrawerFooter>
</DrawerContent>
Expand Down
1 change: 1 addition & 0 deletions src/components/Detail/Contents/Information/Information.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ function Information({data, onOpen, reviewsRating, reviews}: InformationProps) {
openTime={data.openTime}
title={data.title}
thumbnail={data.thumbnail}
id={data.id}
contentTypeId={data.contentTypeId}
/>
<ShortReviews onOpen={onOpen} reviewsRating={reviewsRating} reviews={reviews} />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { useDisclosure } from "@chakra-ui/react";
import { useState } from "react";
import {useDisclosure} from '@chakra-ui/react';
import {useState} from 'react';

import styles from "./ReviewImageSlider.module.scss";
import styles from './ReviewImageSlider.module.scss';

import useComponentSize from "@/hooks/useComponetSize";
import useComponentSize from '@/hooks/useComponetSize';

import SlideModal from "@/components/Detail/Main/SlideModal/SlideModal";
import SlideButton from "@/components/SlideButton/SlideButton";
import SlideModal from '@/components/Detail/Main/SlideModal/SlideModal';
import SlideButton from '@/components/SlideButton/SlideButton';

function ReviewImageSlider({ images }: { images: string[] }) {
function ReviewImageSlider({images}: {images: string[]}) {
const [slideLocation, setSlideLocation] = useState<number>(0);
const [componentRef, size] = useComponentSize();

const [imageIndex, setImageIndex] = useState<number>(0);
const { isOpen, onOpen, onClose } = useDisclosure();
const {isOpen, onOpen, onClose} = useDisclosure();

const handleIsOpen = (index: number) => {
setImageIndex(index);
Expand All @@ -36,14 +36,15 @@ function ReviewImageSlider({ images }: { images: string[] }) {
itemNumber={images.length}
// 목록 전체 넓이
slideSize={size}
buttonSize={24}
/>
)}
<div
className={styles.container__imgWrapper}
ref={componentRef}
style={{
overflow: window.innerWidth < 450 ? "scroll" : "visible",
left: slideLocation + "px",
overflow: window.innerWidth < 450 ? 'scroll' : 'visible',
left: slideLocation + 'px',
}}
>
{images.map((data, i) => (
Expand Down
2 changes: 1 addition & 1 deletion src/components/Detail/Main/ImageSwiper/Swiper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ function ImageSwiper({images}: ImageSwiperProps) {
}}
>
{images.map((data) => (
<SwiperSlide className={styles.container__swiperSlide} onClick={onOpen}>
<SwiperSlide className={styles.container__swiperSlide} onClick={onOpen} key={`imageSwiper_${data}`}>
<img src={data} alt='#' />
</SwiperSlide>
))}
Expand Down
12 changes: 2 additions & 10 deletions src/components/Detail/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,15 @@ interface MainProps {
contentTypeId: number;
images: string[];
title: string;
category: string;
rating: number;
reviewsCount: number;
}

function Main({id, contentTypeId, images, title, category, rating, reviewsCount}: MainProps) {
function Main({id, contentTypeId, images, title, rating, reviewsCount}: MainProps) {
return (
<div className={styles.container}>
<ImageSwiper images={images} />
<Title
id={id}
contentTypeId={contentTypeId}
title={title}
category={category}
rating={rating}
reviewsCount={reviewsCount}
/>
<Title id={id} contentTypeId={contentTypeId} title={title} rating={rating} reviewsCount={reviewsCount} />
</div>
);
}
Expand Down
54 changes: 6 additions & 48 deletions src/components/Detail/Main/Title/Title.tsx
Original file line number Diff line number Diff line change
@@ -1,79 +1,37 @@
import {FaRegHeart} from 'react-icons/fa';
import {FaHeart} from 'react-icons/fa';
import {GoStarFill} from 'react-icons/go';
import {IoShareSocialOutline} from 'react-icons/io5';
import {useRecoilState, useRecoilValue, useSetRecoilState} from 'recoil';

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

import CustomToast from '@/components/CustomToast/CustomToast';

import {IsHeartValued, IsLoginState} from '@/recoil/detail/detail';
import {isModalOpenState, modalContentState} from '@/recoil/vote/alertModal';
import {useGetIsWish, usePostWishes} from '@/hooks/Detail/useWish';
import WishBtn from '@/components/WishBtn/WishBtn';
import {translateCategoryToStr} from '@/hooks/Search/useSearch';

interface TitleProps {
id: number;
contentTypeId: number;
title: string;
category: string;
rating: number;
reviewsCount: number;
}

function Title({id, contentTypeId, title, category, rating, reviewsCount}: TitleProps) {
const [isWish, setIsWish] = useRecoilState(IsHeartValued);
const setIsModalOpen = useSetRecoilState(isModalOpenState);
const setModalContent = useSetRecoilState(modalContentState);

useGetIsWish(id, setIsWish);
const postWishes = usePostWishes();

const isLogin = useRecoilValue(IsLoginState);

const notLoginContent = {
title: '로그인이 필요한 기능입니다.',
subText: '로그인하고 모든 서비스를 이용해 보세요! ',
cancelText: '닫기',
actionButton: '로그인하기',
isSmallSize: true,
};

const showNotLoginModal = () => {
setIsModalOpen(true);
setModalContent({...notLoginContent});
};

function Title({id, contentTypeId, title, rating, reviewsCount}: TitleProps) {
const showToast = CustomToast();

const handleHeartClick = () => {
if (isLogin) {
if (!isWish) {
showToast('찜 목록에 저장되었습니다.');
postWishes.mutate({placeId: id, contentTypeId: contentTypeId});
}
setIsWish(!isWish);
} else {
showNotLoginModal();
}
};
const categoryStr = translateCategoryToStr(contentTypeId);

return (
<div className={styles.container}>
<h2 className={styles.container__header}>{title}</h2>
<p className={styles.container__category}>{category}</p>
<p className={styles.container__category}>{categoryStr}</p>
<div className={styles.container__alignCenter}>
<GoStarFill className={styles.container__alignCenter__star} />
<span className={styles.container__alignCenter__point}>{rating}</span>
<span className={styles.container__alignCenter__reviewsCount}>{`(${reviewsCount})`}</span>
</div>
<div className={styles.container__positionAbsoluteIcons}>
{isWish ? (
<FaHeart fontSize='2.4rem' cursor='pointer' color='#E23774' onClick={handleHeartClick} />
) : (
<FaRegHeart fontSize='2.4rem' cursor='pointer' onClick={handleHeartClick} />
)}

<WishBtn placeId={id} contentTypeId={contentTypeId} size={'2.4rem'} />
<IoShareSocialOutline
fontSize='2.4rem'
cursor='pointer'
Expand Down
Loading
Loading