diff --git a/components/favorite/favorite-places.tsx b/components/favorite/favoritePlaceBox.tsx similarity index 51% rename from components/favorite/favorite-places.tsx rename to components/favorite/favoritePlaceBox.tsx index 048fef2..6fb4fd9 100644 --- a/components/favorite/favorite-places.tsx +++ b/components/favorite/favoritePlaceBox.tsx @@ -2,41 +2,21 @@ import React, { useEffect, useState } from 'react'; import { PoPoAxios } from '@/lib/axios.instance'; import styled from 'styled-components'; -import { IFavoritePlace } from '@/types/favorite.interface'; import { IPlace } from '@/types/reservation.interface'; -const FavoriteBoxes = ({ userId }: { userId: string }) => { - const [placeIds, setPlaceIds] = useState([]); +const FavoriteBox = ({ placeIds }: { placeIds: string[] }) => { const [placeInfos, setPlaceInfos] = useState([] as IPlace[]); useEffect(() => { - const fetchFavoritePlaces = async () => { - try { - const response = await PoPoAxios.get( - `/favorite-place/user_id/${userId}`, - ); - console.log('user_id:', userId); - console.log('response.data:', response.data); - const placeIds = response.data.map( - (place: IFavoritePlace) => place.place_id, - ); - setPlaceIds(placeIds); - } catch (error) { - console.error('Error fetching favorite places:', error); - } - }; - const fetchPlaceInfos = async (placeId: string) => { try { const response = await PoPoAxios.get(`/place/${placeId}`); - setPlaceInfos([...placeInfos, response.data]); + setPlaceInfos((prevPlaceInfos) => [...prevPlaceInfos, response.data]); } catch (error) { console.error('Error fetching place info:', error); } }; - - fetchFavoritePlaces(); placeIds.forEach((placeId: string) => fetchPlaceInfos(placeId)); - }, [userId]); + }, []); return (