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
25 changes: 15 additions & 10 deletions src/hooks/useChart.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useChart = () => {
const [idols, setIdols] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(null);
const [visibleCount, setVisibleCount] = useState(ITEMS_PER_PAGE);
const [visibleCount, setVisibleCount] = useState(ITEMS_PER_PAGE); // ✅ useState 유지

useEffect(() => {
const fetchIdols = async () => {
Expand All @@ -32,18 +32,22 @@ export const useChart = () => {
fetchIdols();
}, []);

// ✅ 오직 최초 1회만 visibleCount 초기화
useEffect(() => {
const handleResize = () => {
Copy link
Collaborator

Choose a reason for hiding this comment

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

resize 이슈였군요~ 빠른 수정 멋집니다~!

if (getIsMobile()) setVisibleCount(MOBILE_ITEMS_PER_PAGE);
else if (getIsTablet()) setVisibleCount(TABLET_ITEMS_PER_PAGE);
else setVisibleCount(ITEMS_PER_PAGE);
};

handleResize();
window.addEventListener("resize", handleResize);
return () => window.removeEventListener("resize", handleResize);
if (getIsMobile()) setVisibleCount(MOBILE_ITEMS_PER_PAGE);
else if (getIsTablet()) setVisibleCount(TABLET_ITEMS_PER_PAGE);
else setVisibleCount(ITEMS_PER_PAGE);
}, []);

// ✅ 더보기 버튼 로직
const handleMore = () => {
if (getIsMobile() || getIsTablet()) {
setVisibleCount((prev) => prev + 5);
} else {
setVisibleCount((prev) => prev + 10);
}
};

const femaleIdols = useMemo(() => {
return idols
.filter((i) => i.gender === "female")
Expand All @@ -65,5 +69,6 @@ export const useChart = () => {
setIdols,
visibleCount,
setVisibleCount,
handleMore, // ✅ Chart.jsx에서 사용
};
};
13 changes: 1 addition & 12 deletions src/pages/List/Chart/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ const Chart = () => {
setIdols,
visibleCount,
setVisibleCount,
handleMore, // ✅ useChart에서 내려받음
} = useChart();

const openModal = () => setIsModalOpen(true);
Expand All @@ -55,18 +56,6 @@ const Chart = () => {
visibleCount,
);

const handleMore = () => {
if (window.matchMedia("(max-width: 425px)").matches) {
setVisibleCount((prev) => prev + 5);
} else if (
window.matchMedia("(min-width: 426px) and (max-width: 768px)").matches
) {
setVisibleCount((prev) => prev + 5);
} else {
setVisibleCount((prev) => prev + 10);
}
};

const handleIdolClick = (idol) => {
const mockData = idolProfiles[idol.name];
if (mockData) {
Expand Down