From 26d9480695025939261f390396760c2de96f2f8f Mon Sep 17 00:00:00 2001 From: JAEMOON Date: Wed, 1 Nov 2023 21:57:35 +0900 Subject: [PATCH] =?UTF-8?q?[feat]=20=EC=B5=9C=EC=B4=88=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C=20=EC=8B=9C=20=EC=A2=8B=EC=95=84=EC=9A=94=20=ED=95=9C?= =?UTF-8?q?=20Room=20=ED=91=9C=EC=8B=9C=EB=90=A0=20=EC=88=98=20=EC=9E=88?= =?UTF-8?q?=EB=8F=84=EB=A1=9D=20=EC=9A=B0=EC=84=A0=20=EC=BB=A4=EB=B0=8B...?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- components/RoomCard/RoomCard.tsx | 5 ++++- pages/index.tsx | 18 +++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/components/RoomCard/RoomCard.tsx b/components/RoomCard/RoomCard.tsx index 9d229a0..03e6cad 100644 --- a/components/RoomCard/RoomCard.tsx +++ b/components/RoomCard/RoomCard.tsx @@ -33,6 +33,7 @@ const UserInfo = ({ userInfo }: UserInfoProps) => { const age = formatAge(userInfo.birthDate); const handleUserClick = () => { + /* router.push( { pathname: '/userInfo', @@ -40,6 +41,7 @@ const UserInfo = ({ userInfo }: UserInfoProps) => { }, '/userInfo' ); + */ }; return ( @@ -88,7 +90,8 @@ const Footer = ({ room, isLikedRooms }: CardProps) => { const [isLiked, setIsLiked] = useState(false || isLikedRooms); const handleLikeClick = async () => { try { - !isLiked ? await makeLikedRooms(room?.id) : await makeDisLikedRooms(room?.id); + // !isLiked ? await makeLikedRooms(room?.id) : await makeDisLikedRooms(room?.id); + await makeLikedRooms(room?.id); setIsLiked(!isLiked); } catch (error) { console.error('[ERROR] in Liked Clicked', error); diff --git a/pages/index.tsx b/pages/index.tsx index e6e1b7d..830b9ef 100644 --- a/pages/index.tsx +++ b/pages/index.tsx @@ -1,3 +1,4 @@ +/* eslint-disable no-restricted-syntax */ import React, { useEffect, useRef, useState } from 'react'; import 'tailwindcss/tailwind.css'; import RoomCard from '@/components/RoomCard/RoomCard'; @@ -11,6 +12,7 @@ import useModal from '@/hooks/useModal.ts'; import Filter from '@/components/Filter/Filter.tsx'; import { getRooms } from '@/api/room'; import isEmpty from 'lodash-es/isEmpty'; +import { getLikedRooms } from '@/api/userInfo'; type HomeProps = NextPage & { getLayout: (page: React.ReactElement, ctx: NextPageContext) => React.ReactNode; @@ -41,8 +43,10 @@ function Home() { const [page, setPage] = useState(0); const [totalElements, setTotalElements] = useState(0); const [searchParams, setSearchParams] = useState>({}); + const [likedRoom, setLikedRoom] = useState([]); // TODO: 전체 페이지보다 크면 페이징 처리 안되도록 수정 // TODO : ModalLayer 로 로그인한 사용자의 Context 생성 필요 + // eslint-disable-next-line consistent-return const selectRooms = async () => { try { const data = await getRooms({ @@ -51,6 +55,8 @@ function Home() { }); setRooms(data?.content || []); setTotalElements(data?.totalElements || 0); + + return data?.content; } catch (error) { console.error(error); } @@ -116,7 +122,17 @@ function Home() { // 최초 접근 시 Room 정보 조회 useEffect(() => { (async () => { - await selectRooms(); + const resultRooms = await selectRooms(); + const resultLikedRooms = (await getLikedRooms(page))?.content; + const roomIds = []; + if (resultRooms) { + for (const room of resultRooms) { + const roomId = room?.id; + if (resultLikedRooms && resultLikedRooms.some((likedRoom) => likedRoom?.id === roomId)) { + roomIds.push(roomId); + } + } + } // await selectProfile(); if (target?.current) { const observer = new IntersectionObserver(callback, options);