onClick(idol.id) : undefined}
>
{children}
@@ -53,7 +29,7 @@ const CheckedIdolCard = ({
/>
- {localIsSelected && isSelectable && (
+ {isSelected && isSelectable && (
<>
![]()
{
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;
@@ -55,9 +40,9 @@ const MyPage = () => {
useEffect(() => {
const storedFavorites = localStorage.getItem(storageKey);
if (storedFavorites) {
- setFavoriteIdols(storedFavorites.split(','));
+ setFavoriteIdols(storedFavorites.split(',').map(Number));
}
- }, []); // `favoriteIdols` 변경될 때마다 실행
+ }, []);
const handleToggle = (idolId) => {
setSelectedIdols((prev) =>
@@ -67,9 +52,21 @@ const MyPage = () => {
);
};
+ const handleAddToFavorites = () => {
+ if (selectedIdols.length === 0) return;
+
+ 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());
+ const updatedFavorites = prev.filter((id) => id !== idolId);
localStorage.setItem(storageKey, updatedFavorites.join(','));
return updatedFavorites;
});
@@ -89,54 +86,52 @@ const MyPage = () => {
- {/* 관심있는 아이돌 섹션 */}
+ {/* 관심 있는 아이돌 섹션 */}
내가 관심있는 아이돌
-
- {favoriteIdolsArr.map((idol) => (
-
-
- {/* 닫기 버튼 */}
- {/* X 버튼 (항상 테두리 상단에 고정) */}
-
- {/* 회색 구분선 */}
-
-
- {/* 아이돌 추가하기 섹션 */}
관심 있는 아이돌을 추가해보세요.
- {/* 버튼이 그리드 크기에 따라 자동으로 좌우 맞춤 */}
+ {/* 이전 버튼 */}
- {/* 이전 버튼 */}
-
{
>
- {/* 이후 버튼 */}
-
= idols.length}
- className="absolute right-[1%] tablet:right-[-6%] pc:right-[-4%] top-1/2 transform -translate-y-1/2
- w-[29px] h-[135px] rounded-[4px]
- bg-[rgba(27,27,27,0.8)]
- hover:bg-[rgba(27,27,27,1)] transition-all
- flex items-center justify-center"
- >
-
-
- {/* 아이돌 리스트 */}
-
+
+ {/* 아이돌 리스트 */}
+
{idols
.slice(
currentPage * itemsPerPage,
@@ -173,18 +157,28 @@ const MyPage = () => {
/>
))}
+
+ {/* 다음 버튼 (반응형 위치 조정) */}
+
= idols.length}
+ className="absolute right-[1%] md:right-[-6%] lg:right-[-4%] top-1/2 transform -translate-y-1/2
+ w-[29px] h-[135px] rounded-[4px]
+ bg-[rgba(27,27,27,0.8)]
+ hover:bg-[rgba(27,27,27,1)] transition-all
+ flex items-center justify-center"
+ >
+
+
- {/* 추가하기 버튼 */}
-
+
+ + 추가하기
+
);
};