Skip to content
Snippets Groups Projects
Commit e40412f2 authored by pjookim's avatar pjookim
Browse files

refactor: improve place filtering logic in AddPlace component

parent 67bddcab
No related branches found
No related tags found
No related merge requests found
...@@ -157,23 +157,26 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa ...@@ -157,23 +157,26 @@ const AddPlace = ({ tripId, day, onBack, onPlaceSelect, tripStartDate, tripEndDa
const currentState = tabStates[activeTab]; const currentState = tabStates[activeTab];
if (!currentState.places) return []; if (!currentState.places) return [];
// 검색어가 있을 때는 검색 결과만 반환
if (searchKeyword.trim()) {
return currentState.places;
}
// 검색어가 없을 때만 즐겨찾기와 일반 항목 표시
const currentTypeId = CONTENT_TYPE[activeTab]; const currentTypeId = CONTENT_TYPE[activeTab];
const currentAreaCode = getAreaCode(location); const currentAreaCode = getAreaCode(location);
// 현재 탭과 지역에 맞는 즐겨찾기 항목 필터링
const matchingFavorites = favoriteItems.filter(place => const matchingFavorites = favoriteItems.filter(place =>
String(place.type) === currentTypeId && String(place.type) === currentTypeId &&
place.areaCode === currentAreaCode place.areaCode === currentAreaCode
); );
// 즐겨찾기에 없는 일반 항목들만 필터링
const nonFavoriteItems = currentState.places.filter(place => const nonFavoriteItems = currentState.places.filter(place =>
!favorites.has(place.id) !favorites.has(place.id)
); );
// 즐겨찾기 항목을 먼저, 그 다음에 일반 항목들
return [...matchingFavorites, ...nonFavoriteItems]; return [...matchingFavorites, ...nonFavoriteItems];
}, [tabStates[activeTab].places, favoriteItems, activeTab, location, favorites]); }, [tabStates[activeTab].places, favoriteItems, activeTab, location, favorites, searchKeyword]);
const toggleFavorite = async (place) => { const toggleFavorite = async (place) => {
if (!user) { if (!user) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment