Skip to content

Commit

Permalink
Merge pull request #207 from bsideproject/feature/user
Browse files Browse the repository at this point in the history
[feat] 최초 조회 시 좋아요 한 Room 표시될 수 있도록 우선 커밋...
  • Loading branch information
KinDDoGGang authored Nov 1, 2023
2 parents 60ab40e + 26d9480 commit 98ad250
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion components/RoomCard/RoomCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,15 @@ const UserInfo = ({ userInfo }: UserInfoProps) => {
const age = formatAge(userInfo.birthDate);

const handleUserClick = () => {
/*
router.push(
{
pathname: '/userInfo',
query: { data: JSON.stringify(userInfo) },
},
'/userInfo'
);
*/
};

return (
Expand Down Expand Up @@ -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);
Expand Down
18 changes: 17 additions & 1 deletion pages/index.tsx
Original file line number Diff line number Diff line change
@@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -41,8 +43,10 @@ function Home() {
const [page, setPage] = useState(0);
const [totalElements, setTotalElements] = useState(0);
const [searchParams, setSearchParams] = useState<Record<string, string>>({});
const [likedRoom, setLikedRoom] = useState([]);
// TODO: 전체 페이지보다 크면 페이징 처리 안되도록 수정
// TODO : ModalLayer 로 로그인한 사용자의 Context 생성 필요
// eslint-disable-next-line consistent-return
const selectRooms = async () => {
try {
const data = await getRooms({
Expand All @@ -51,6 +55,8 @@ function Home() {
});
setRooms(data?.content || []);
setTotalElements(data?.totalElements || 0);

return data?.content;
} catch (error) {
console.error(error);
}
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 98ad250

Please sign in to comment.