Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/pages/listPage/ListPage.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ function ListPage() {
onCreditShortageClick={() => openModal('creditNotEnough')}
credits={credits}
/>
<DonationsList onDonationClick={(item) => openModal('donation', item)} />
<DonationsList
onDonationClick={(item) => openModal('donation', item)}
credits={credits}
/>
<MonthlyChartSection
onClickVote={() => {
openModal('vote');
Expand Down
22 changes: 21 additions & 1 deletion src/pages/listPage/donation/DonationsList.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,15 @@ import nextIcon from '@/assets/icons/nextIcon.svg';

const MAXIMUL_VIEW_DONATIONS = 4;

function DonationsList({ onDonationClick }) {
function DonationsList({ onDonationClick, credits }) {
const [items, setItems] = useState([]);
const [cursor, setCursor] = useState(0);
const [cursorArr, setCursorArr] = useState([0]);
const [isLoading, setIsLoading] = useState(false);
const [isError, setIsError] = useState(false);
const [isPC, setIsPC] = useState(window.innerWidth >= 1200);
const observerRef = useRef(null);
const prevCreditsRef = useRef(credits);

const handleLoad = async (query) => {
setIsLoading(true);
Expand Down Expand Up @@ -76,6 +77,25 @@ function DonationsList({ onDonationClick }) {
return () => observer.disconnect();
}, [cursor, isPC]);

// 크레딧 값이 감소했을 시 GET Request
useEffect(() => {
setTimeout(() => {
prevCreditsRef.current = credits;
}, 0);
}, [credits]);

useEffect(() => {
console.log(prevCreditsRef.current > credits);
if (prevCreditsRef.current > credits) {
if (isPC) {
handleLoad({ cursor: cursorArr[cursorArr.length - 1] });
} else {
setItems([]);
handleLoad({ cursor: 0 });
}
}
}, [credits]);

return (
<div className="flex flex-col gap-4 tablet:gap-6 pc:gap-8 font-pretendard text-softWhite">
<div className="w-full tablet:max-w-[1200px] mx-auto">
Expand Down