diff --git a/src/components/IdolCard.jsx b/src/components/IdolCard.jsx index d63a8fc..2870a4a 100644 --- a/src/components/IdolCard.jsx +++ b/src/components/IdolCard.jsx @@ -51,11 +51,6 @@ const IdolCard = ({ )} - -
-

{idol.name}

-

{idol.group || '그룹 없음'}

-
); }; diff --git a/src/components/Modal.jsx b/src/components/Modal.jsx index 6ec390b..412f4b9 100644 --- a/src/components/Modal.jsx +++ b/src/components/Modal.jsx @@ -25,7 +25,8 @@ function Modal({ title, onClose, children }) { if (title.includes('아이돌') && isMobile) { return ( -
+ // z-[9999] : 모달창이 열렸을 때 리스트 페이지에 있는 아이돌 이미지 보더가 같이 보이는 현상 해결을 위해 작성 +
leftTopGradient +
{idols.map((idol, idx) => (
setSelectedIdol(idol.id)}> - +
{ +const MonthlyChartVoteModal = ({ + gender, + closeModal, + setModalStep, + setVoteTrigger, +}) => { const [cursor, setCursor] = useState(0); const [idolData, setIdolData] = useState([]); const [loading, setLoading] = useState(false); @@ -32,18 +37,20 @@ const MonthlyChartVoteModal = ({ gender, onClickVoteCredit, closeModal }) => { const handleVoteClick = async () => { const result = spendCredits(1000); if (result === 'NOT-ENOUGH') { - alert('앗! 투표하기 위한 크레딧이 부족해요'); - } else { - try { - const voteResult = await postVotes(selectedIdol); - alert('투표 완료!'); + setModalStep('creditNotEnough'); + return; + } - if (onClickVoteCredit) onClickVoteCredit(); - closeModal(); - } catch (error) { - console.error(error); - alert('투표에 실패했습니다. 다시 시도해 주세요.'); - } + try { + await postVotes(selectedIdol); + alert('투표 완료!'); + setVoteTrigger((prev) => !prev); + + closeModal(); + } catch (error) { + alert('투표에 실패했습니다. 다시 시도해 주세요.'); + rechargeCredits(1000); + return; } }; @@ -68,7 +75,9 @@ const MonthlyChartVoteModal = ({ gender, onClickVoteCredit, closeModal }) => { const observer = new IntersectionObserver( (entries) => { - if (entries[0].isIntersecting) loadIdolData(); + if (entries[0].isIntersecting) { + loadIdolData(); + } }, { threshold: 0.2 } ); @@ -78,25 +87,28 @@ const MonthlyChartVoteModal = ({ gender, onClickVoteCredit, closeModal }) => { return (
{loading ? (
로딩 중입니다...
) : ( - -
-
+ +
+
+
)}
{ setCredits(getCredits()); - }, []); + }, [modalStep]); const openModal = (step, item = null) => { setModalStep(step); @@ -81,6 +82,8 @@ function ListPage() { }} gender={gender} setGender={setGender} + voteTrigger={voteTrigger} + setVoteTrigger={setVoteTrigger} /> {isModalOpen && ( @@ -115,7 +118,12 @@ function ListPage() { )} {modalStep === 'vote' && ( - + )} )} diff --git a/src/pages/listPage/monthlyChart/MonthlyChartItem.jsx b/src/pages/listPage/monthlyChart/MonthlyChartItem.jsx index 7f95d36..7b3a437 100644 --- a/src/pages/listPage/monthlyChart/MonthlyChartItem.jsx +++ b/src/pages/listPage/monthlyChart/MonthlyChartItem.jsx @@ -1,20 +1,25 @@ -const MonthlyChartItem = ({ idol, rank, layout = 'default', children }) => { - const { profilePicture, name, group, totalVotes } = idol; +import IdolCard from '@/components/IdolCard'; +import checkIcon from '@/assets/images/check.png'; + +const MonthlyChartItem = ({ + idol, + rank, + layout = 'default', + children, + selectedIdol, +}) => { + const { name, group, totalVotes } = idol; return (
{layout === 'default' ? (
-
-
- {name} -
-
+

{rank}

@@ -29,14 +34,23 @@ const MonthlyChartItem = ({ idol, rank, layout = 'default', children }) => { ) : (

-
-
- {name} -
+
+ + {selectedIdol === idol.id && ( +
+
+ check +
+ )}

{rank}

diff --git a/src/pages/listPage/monthlyChart/MonthlyChartSection.jsx b/src/pages/listPage/monthlyChart/MonthlyChartSection.jsx index 9a7e463..7d03840 100644 --- a/src/pages/listPage/monthlyChart/MonthlyChartSection.jsx +++ b/src/pages/listPage/monthlyChart/MonthlyChartSection.jsx @@ -4,7 +4,13 @@ import { getLists } from '@/apis/monthlyChartApi'; import PrimaryButton from '@/components/PrimaryButton'; import MonthlyChartList from '@/pages/listPage/monthlyChart/MonthlyChartList'; -const MonthlyChartSection = ({ onClickVote, gender, setGender }) => { +const MonthlyChartSection = ({ + onClickVote, + gender, + setGender, + voteTrigger, + setVoteTrigger, +}) => { const [cursor, setCursor] = useState(0); const [idolData, setIdolData] = useState([]); const [loading, setLoading] = useState(false); @@ -27,8 +33,10 @@ const MonthlyChartSection = ({ onClickVote, gender, setGender }) => { const loadIdolData = async () => { setLoading(true); + console.log('loadIdolData:', gender, voteTrigger, cursor); + const cursorValue = voteTrigger ? 0 : cursor; try { - const response = await getLists(gender, cursor, pageSize); + const response = await getLists(gender, cursorValue, pageSize); if (cursor !== 0) { setIdolData((prev) => [...prev, ...response.idols]); } else { @@ -39,6 +47,7 @@ const MonthlyChartSection = ({ onClickVote, gender, setGender }) => { console.error(error); } finally { setLoading(false); + setVoteTrigger(false); } }; @@ -56,6 +65,13 @@ const MonthlyChartSection = ({ onClickVote, gender, setGender }) => { loadIdolData(); }, [gender, pageSize]); + useEffect(() => { + if (voteTrigger) { + setIdolData([]); + loadIdolData(); + } + }, [voteTrigger]); + useEffect(() => { window.addEventListener('resize', updateChartSize);