+
-
{idol.name}
+
{idol.name}
{idol.group || '그룹 없음'}
diff --git a/src/pages/myPage/MyPage.jsx b/src/pages/myPage/MyPage.jsx
index f366d98..b5c3ca4 100644
--- a/src/pages/myPage/MyPage.jsx
+++ b/src/pages/myPage/MyPage.jsx
@@ -5,6 +5,7 @@ import nextIcon from '@/assets/icons/nextIcon.svg';
import prevIcon from '@/assets/icons/prevIcon.svg';
import { fetchIdols } from '@/apis/myPageApi.js';
import PrimaryButton from '@/components/PrimaryButton';
+import xButton from '@/assets/icons/xButton.svg';
const storageKey = 'favoriteIdols';
@@ -14,19 +15,28 @@ const MyPage = () => {
const [favoriteIdols, setFavoriteIdols] = useState([]);
const [currentPage, setCurrentPage] = useState(0);
const [itemsPerPage, setItemsPerPage] = useState(16);
+
const favoriteIdSet = new Set(favoriteIdols.map(Number)); // 숫자로 변환한 Set 생성
const favoriteIdolsArr = idols.filter((idol) => favoriteIdSet.has(idol.id));
+ const handleAddToFavorites = () => {
+ if (selectedIdols.length === 0) return;
+
+ setFavoriteIdols((prev) => {
+ const updatedFavorites = [...new Set([...prev, ...selectedIdols])];
+ localStorage.setItem(storageKey, updatedFavorites.join(',')); // localStorage 업데이트
+ return updatedFavorites;
+ });
+
+ setSelectedIdols([]); // 선택된 아이돌 초기화
+ };
+
useEffect(() => {
const updateItemsPerPage = () => {
const width = window.innerWidth;
- if (width >= 1200) {
- setItemsPerPage(16);
- } else if (width >= 768) {
- setItemsPerPage(8);
- } else {
- setItemsPerPage(6);
- }
+ if (width >= 1200) setItemsPerPage(16);
+ else if (width >= 768) setItemsPerPage(8);
+ else setItemsPerPage(6);
};
updateItemsPerPage();
@@ -36,7 +46,7 @@ const MyPage = () => {
useEffect(() => {
const loadIdols = async () => {
- const data = await fetchIdols(30);
+ const data = await fetchIdols(32);
setIdols(data);
};
loadIdols();
@@ -47,36 +57,26 @@ const MyPage = () => {
if (storedFavorites) {
setFavoriteIdols(storedFavorites.split(','));
}
- }, []);
+ }, []); // `favoriteIdols` 변경될 때마다 실행
const handleToggle = (idolId) => {
- setSelectedIdols((prev) => {
- const index = prev.indexOf(idolId);
- if (index !== -1) {
- // 이미 선택된 경우, 해당 인덱스의 항목만 제거
- return [...prev.slice(0, index), ...prev.slice(index + 1)];
- } else {
- // 선택되지 않은 경우, 배열에 추가
- return [...prev, idolId];
- }
- });
+ setSelectedIdols((prev) =>
+ prev.includes(idolId)
+ ? prev.filter((id) => id !== idolId)
+ : [...prev, idolId]
+ );
};
- const handleAddToFavorites = () => {
- if (selectedIdols.length === 0) return;
- else {
- setFavoriteIdols((prev) => {
- const updatedFavorites = [...new Set([...prev, ...selectedIdols])];
- localStorage.setItem(storageKey, updatedFavorites.join(','));
- return updatedFavorites;
- });
- }
- setSelectedIdols([]);
+
+ const handleRemoveFavorite = (idolId) => {
+ setFavoriteIdols((prev) => {
+ const updatedFavorites = prev.filter((id) => id !== idolId.toString());
+ localStorage.setItem(storageKey, updatedFavorites.join(','));
+ return updatedFavorites;
+ });
};
const prevPage = () => {
- if (currentPage > 0) {
- setCurrentPage((prev) => prev - 1);
- }
+ if (currentPage > 0) setCurrentPage((prev) => prev - 1);
};
const nextPage = () => {
@@ -86,57 +86,57 @@ const MyPage = () => {
};
return (
-
-
+
{/* 관심있는 아이돌 섹션 */}
-
-
+
+
내가 관심있는 아이돌
- {/*스크롤시 배경 전체유지 */}
-
-
-
- {favoriteIdolsArr.map((idol) => {
- return (
+
+
+
+ {favoriteIdolsArr.map((idol) => (
+
- );
- })}
+ sizeClass="w-[100px] h-[100px]"
+ >
+ {/* 닫기 버튼 */}
+ {/* X 버튼 (항상 테두리 상단에 고정) */}
+
+
+
+ ))}
- {/* 회색 구분선 */}
+ {/* 회색 구분선 */}
{/* 아이돌 추가하기 섹션 */}
-
+
관심 있는 아이돌을 추가해보세요.
- {/* 버튼이 그리드 크기에 따라 자동으로 좌우 맞춤 */}
+ {/* 버튼이 그리드 크기에 따라 자동으로 좌우 맞춤 */}
- {/* 이전 버튼 (반응형 위치 조정) */}
+ {/* 이전 버튼 */}
+
-
- {/* 아이돌 리스트 */}
-
+ {/* 이후 버튼 */}
+
+ {/* 아이돌 리스트 */}
+
{idols
.slice(
currentPage * itemsPerPage,
@@ -162,32 +173,17 @@ const MyPage = () => {
/>
))}
-
- {/* 다음 버튼 (반응형 위치 조정) */}
-
+
- {/* 추가하기 버튼 중앙 정렬 */}
-
+ {/* 추가하기 버튼 */}
+
);