Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 5 additions & 29 deletions src/pages/myPage/CheckedIdolCard.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState, useEffect } from 'react';
import React from 'react';
import checkIcon from '@/assets/images/check.png';

const CheckedIdolCard = ({
Expand All @@ -7,40 +7,16 @@ const CheckedIdolCard = ({
isSelectable = true,
isSelected = false,
sizeClass = 'w-[98px] h-[98px] tablet:w-[128px] tablet:h-[128px]',
onClick,
}) => {
const defaultImage = 'https://link24.kr/9iFIhh0';
const storageKey = 'favoriteIdols';
const [localIsSelected, setLocalIsSelected] = useState(isSelected);

useEffect(() => {
if (isSelectable) {
const savedFavorites = localStorage.getItem(storageKey) || '';
setLocalIsSelected(savedFavorites.split(',').includes(String(idol.id)));
}
}, [idol.id, isSelectable]);

const toggleFavorite = () => {
if (!isSelectable) return;

let savedFavorites = localStorage.getItem(storageKey) || '';
let favoriteArray = savedFavorites ? savedFavorites.split(',') : [];

if (favoriteArray.includes(String(idol.id))) {
favoriteArray = favoriteArray.filter((id) => id !== String(idol.id));
} else {
favoriteArray.push(String(idol.id));
}

localStorage.setItem(storageKey, favoriteArray.join(','));
setLocalIsSelected(!localIsSelected);
};

return (
<div className="p-1 flex flex-col items-center relative ">
<div className="p-1 flex flex-col items-center relative">
<div
className={`relative ${sizeClass} p-[2px] flex items-center justify-center rounded-full
${isSelectable ? 'cursor-pointer' : 'cursor-default'} transition-all`}
onClick={isSelectable ? toggleFavorite : undefined}
onClick={isSelectable ? () => onClick(idol.id) : undefined}
>
{children}
<div className="absolute inset-0 rounded-full border-[1.3px] border-coralRed z-10"></div>
Expand All @@ -53,7 +29,7 @@ const CheckedIdolCard = ({
/>
</div>

{localIsSelected && isSelectable && (
{isSelected && isSelectable && (
<>
<div className="absolute inset-0 rounded-full bg-gradient-to-r from-coralRed to-pinkPunch opacity-50 z-20" />
<img
Expand Down
136 changes: 65 additions & 71 deletions src/pages/myPage/MyPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,6 @@ const MyPage = () => {
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;
Expand All @@ -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) =>
Expand All @@ -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;
});
Expand All @@ -89,75 +86,62 @@ const MyPage = () => {
<div className="w-full min-h-screen bg-midnightBlack flex flex-col items-center font-pretendard">
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tablet, Mobile 화면에서 요소들이 너무 화면 좌우에 딱 붙어있는 것 같습니다. 피그마를 확인해보면 padding이 24px씩 되어있네요.
image
여기에 px-[24px] 해주면 어떨까 싶습니다.

<Header />

{/* 관심있는 아이돌 섹션 */}
{/* 관심 있는 아이돌 섹션 */}
<div className="w-full max-w-[1200px] flex flex-col items-center py-6 mobile:py-10">
<h1 className="text-white text-[16px] tablet:text-[20px] pc:text-[24px] font-pretendard font-bold self-start">
내가 관심있는 아이돌
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이 부분 피그마에는 '관심있는'으로 되어있는데 '관심 있는'으로 수정하면 좋을 것 같습니다!

</h1>

<div className="w-full overflow-x-auto whitespace-nowrap scrollbar-hide">
<div className=" flex gap-5 mt-4 mx-auto min-h-[150px]">
{favoriteIdolsArr.map((idol) => (
<div key={idol.id} className="relative">
<CheckedIdolCard
className="relative"
idol={idol}
isSelectable={false}
sizeClass="w-[100px] h-[100px]"
>
{/* 닫기 버튼 */}
{/* X 버튼 (항상 테두리 상단에 고정) */}
<button
onClick={() => handleRemoveFavorite(idol.id)}
className="absolute top-0 right-0
flex items-center justify-center bg-transparent
transition-opacity z-30 "
<div className="flex gap-5 mt-4 mx-auto min-h-[150px]">
{favoriteIdols.map((idolId) => {
const idol = idols.find((i) => i.id === idolId);
if (!idol) return null;

return (
<div key={idol.id} className="relative">
<CheckedIdolCard
idol={idol}
isSelectable={false}
sizeClass="w-[100px] h-[100px]"
>
<img src={xButton} alt="Remove" className="w-full h-full" />
</button>
</CheckedIdolCard>
</div>
))}
<button
onClick={() => handleRemoveFavorite(idol.id)}
className="absolute -top-2 -right-2 w-6 h-6 z-50 flex items-center justify-center bg-transparent transition-opacity"
>
<img
src={xButton}
alt="Remove"
className="w-full h-full"
/>
</button>
</CheckedIdolCard>
</div>
);
})}
</div>
</div>

{/* 회색 구분선 */}
<div className="relative w-full max-w-[1200px] mt-4 border-t border-gray-900" />

{/* 아이돌 추가하기 섹션 */}
<h2 className="text-white text-[16px] tablet:text-[20px] pc:text-[24px] font-pretendard font-bold self-start mt-6">
관심 있는 아이돌을 추가해보세요.
</h2>

{/* 버튼이 그리드 크기에 따라 자동으로 좌우 맞춤 */}
{/* 이전 버튼 */}
<div className="relative w-full max-w-[1200px] mt-[20px]">
{/* 이전 버튼 */}

<button
onClick={prevPage}
disabled={currentPage === 0}
className="absolute left-[1%] tablet:left-[-6%] pc:left-[-4%] top-1/2 transform -translate-y-1/2
className="absolute left-[1%] md:left-[-6%] lg:left-[-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"
>
<img src={prevIcon} alt="Previous" className="w-4 h-4" />
</button>
{/* 이후 버튼 */}
<button
onClick={nextPage}
disabled={(currentPage + 1) * itemsPerPage >= 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"
>
<img src={nextIcon} alt="Next" className="w-4 h-4" />
</button>
{/* 아이돌 리스트 */}
<div className="grid grid-cols-3 tablet:grid-cols-4 pc:grid-cols-8 gap-3 mt-4 mx-auto min-h-[300px]">

{/* 아이돌 리스트 */}
<div className="grid grid-cols-3 md:grid-cols-4 lg:grid-cols-8 gap-3 mt-4 mx-auto min-h-[300px]">
{idols
.slice(
currentPage * itemsPerPage,
Expand All @@ -173,18 +157,28 @@ const MyPage = () => {
/>
))}
</div>

{/* 다음 버튼 (반응형 위치 조정) */}
<button
onClick={nextPage}
disabled={(currentPage + 1) * itemsPerPage >= 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"
>
<img src={nextIcon} alt="Next" className="w-4 h-4" />
</button>
</div>
</div>

{/* 추가하기 버튼 */}
<div className="flex justify-center w-full">
<PrimaryButton
onClickFunc={handleAddToFavorites}
className="w-[255px] h-[48px] mt-10 text-white rounded-full font-pretendard font-bold text-[16px]"
>
+ 추가하기
</PrimaryButton>
</div>
<PrimaryButton
onClickFunc={handleAddToFavorites}
className="w-[255px] h-[48px] mt-10 text-white rounded-full font-pretendard font-bold text-[16px]"
>
+ 추가하기
</PrimaryButton>
</div>
);
};
Expand Down