Skip to content

Commit

Permalink
Merge pull request #97 from urdego/hotfix
Browse files Browse the repository at this point in the history
hotfix: useGetInfiniteLocationList의 로직 변경에 따라 addContents 로직도 변경했습니다.
  • Loading branch information
aaahyesu authored Jan 31, 2025
2 parents 44c1054 + 57bc6bc commit 91bd41d
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions components/Layout/AddContents/AddContents.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,22 +30,28 @@ const AddContents = ({ isVisible, setIsVisible, title }: AddContentsProps) => {
const [selectedLocations, setSelectedLocations] = useState<string[]>([]);
const contentRef = useRef<HTMLDivElement>(null);

// useGetInfiniteLocationList 훅 호출
const {
locationList: contents,
loadMore,
fetchLocationList,
isLoading,
isInitialLoad,
isLoadMore,
} = useGetInfiniteLocationList();

// 초기 로드 및 무한 스크롤 설정
const isInitialLoad = contents.length === 0;

useEffect(() => {
const currentRef = contentRef.current;

const handleScroll = () => {
if (currentRef) {
const { scrollTop, scrollHeight, clientHeight } = currentRef;
if (scrollHeight - scrollTop <= clientHeight + 1 && !isLoading) {
loadMore(); // 추가 데이터 로드
// 무한 스크롤 조건: 스크롤이 하단에 도달했으며, 로딩 중이 아니고, 추가 데이터가 있음
if (
scrollHeight - scrollTop <= clientHeight + 1 &&
!isLoading &&
isLoadMore
) {
fetchLocationList();
}
}
};
Expand All @@ -58,7 +64,7 @@ const AddContents = ({ isVisible, setIsVisible, title }: AddContentsProps) => {
currentRef.removeEventListener('scroll', handleScroll);
}
};
}, [isLoading, loadMore]);
}, [isLoading, isLoadMore, fetchLocationList]);

useEffect(() => {
if (!isVisible) {
Expand Down

0 comments on commit 91bd41d

Please sign in to comment.