Skip to content
Merged
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
23 changes: 21 additions & 2 deletions src/components/mobile/BottomSheet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use client';

import React, { useState, useEffect } from 'react';
import React, { useState, useEffect, useRef, useCallback } from 'react';
import IconClose from 'public/assets/icons/bottom-sheet/icon-close.svg';
import IconHomeIndicator from 'public/assets/icons/bottom-sheet/icon-home-indicator.svg';
import Image from 'next/image';
Expand All @@ -16,6 +16,11 @@ interface BottomSheetProps {
item: Item | null;
}

function useReRenderer() {
const [, setState] = useState({});
return useCallback(() => setState({}), []);
}

export default function BottomSheet({
isOpen,
onCloseAction,
Expand All @@ -40,6 +45,10 @@ export default function BottomSheet({
alertMessage: '',
});

// 버튼 중복 클릭 방지
const isLoadingRef = useRef(false);
const reRender = useReRenderer();

// 현재 시간 가져오기 (현재 시간 이후로만 입력 가능하도록 하기 위함)
const now = new Date();
const currentHour = now.getHours();
Expand Down Expand Up @@ -141,6 +150,13 @@ export default function BottomSheet({
return;
}

if (isLoadingRef.current) {
return; // 이미 로딩 중이면 무시
}

isLoadingRef.current = true;
reRender(); // 렌더링을 강제로 트리거

try {
await requestItems({
itemId: item.itemId,
Expand Down Expand Up @@ -196,6 +212,9 @@ export default function BottomSheet({
});
}, 300);
}
} finally {
isLoadingRef.current = false;
reRender(); // 렌더링을 다시 트리거
}
};

Expand Down Expand Up @@ -324,7 +343,7 @@ export default function BottomSheet({
quantity === '' ||
hour === '' ||
minute === ''
)
) || isLoadingRef.current // 로딩 중일 때도 비활성화
}
>
대여하기
Expand Down