diff --git a/src/components/group/MyGroupBox.tsx b/src/components/group/MyGroupBox.tsx index 986f7f68..d291879f 100644 --- a/src/components/group/MyGroupBox.tsx +++ b/src/components/group/MyGroupBox.tsx @@ -95,23 +95,6 @@ export function MyGroupBox({ onMyGroupsClick }: MyGroupProps) { document.body.style.userSelect = ''; }; - let touchStartX = 0; - let touchScrollLeft = 0; - const handleTouchStart = (e: React.TouchEvent) => { - isDragging = true; - touchStartX = e.touches[0].pageX - (scrollRef.current?.offsetLeft ?? 0); - touchScrollLeft = scrollRef.current?.scrollLeft ?? 0; - }; - const handleTouchMove = (e: React.TouchEvent) => { - if (!isDragging || !scrollRef.current) return; - const x = e.touches[0].pageX - scrollRef.current.offsetLeft; - const walk = x - touchStartX; - scrollRef.current.scrollLeft = touchScrollLeft - walk; - }; - const handleTouchEnd = () => { - isDragging = false; - }; - const handlePrevClick = () => { if (scrollRef.current) { const container = scrollRef.current; @@ -171,9 +154,6 @@ export function MyGroupBox({ onMyGroupsClick }: MyGroupProps) { onMouseMove={handleMouseMove} onMouseUp={handleMouseUp} onMouseLeave={handleMouseUp} - onTouchStart={handleTouchStart} - onTouchMove={handleTouchMove} - onTouchEnd={handleTouchEnd} > {infiniteGroups.map((g, i) => ( ) => { - isDragging = true; - touchStartX = e.touches[0].pageX - (scrollRef.current?.offsetLeft ?? 0); - touchScrollLeft = scrollRef.current?.scrollLeft ?? 0; - }; - const handleTouchMove = (e: React.TouchEvent) => { - if (!isDragging || !scrollRef.current) return; - const x = e.touches[0].pageX - scrollRef.current.offsetLeft; - const walk = x - touchStartX; - scrollRef.current.scrollLeft = touchScrollLeft - walk; - }; - const handleTouchEnd = () => { - isDragging = false; - }; - const handlePrevClick = () => { if (scrollRef.current) { const container = scrollRef.current; @@ -93,9 +76,6 @@ export function RecruitingGroupCarousel({ sections }: Props) { onMouseMove={handleMouseMove} onMouseUp={handleMouseUp} onMouseLeave={handleMouseUp} - onTouchStart={handleTouchStart} - onTouchMove={handleTouchMove} - onTouchEnd={handleTouchEnd} > {infiniteGroups.map((g, i) => ( { - const card = cardRefs.current[middleIndex]; - if (!card) return; - const center = container.offsetWidth / 2; - const left = card.offsetLeft + card.offsetWidth / 2 - center; - container.style.scrollBehavior = 'auto'; - container.scrollLeft = left; - container.style.scrollBehavior = ''; - handleScroll(); + if (rafId !== null) { + cancelAnimationFrame(rafId); + } + rafId = requestAnimationFrame(() => { + const card = cardRefs.current[middleIndex]; + if (!card) return; + const center = container.offsetWidth / 2; + const left = card.offsetLeft + card.offsetWidth / 2 - center; + container.style.scrollBehavior = 'auto'; + container.scrollLeft = left; + container.style.scrollBehavior = ''; + handleScroll(); + rafId = null; + }); }; - const timer = setTimeout(initializeScroll, 100); + const timer = window.setTimeout(initializeScroll, 100); + let resizeTimer: number | null = null; const handleResize = () => { - setTimeout(initializeScroll, 50); + if (resizeTimer !== null) { + window.clearTimeout(resizeTimer); + } + resizeTimer = window.setTimeout(() => { + initializeScroll(); + }, 150); }; container.addEventListener('scroll', handleScroll, { passive: true }); window.addEventListener('resize', handleResize); return () => { - clearTimeout(timer); + window.clearTimeout(timer); container.removeEventListener('scroll', handleScroll); window.removeEventListener('resize', handleResize); + if (resizeTimer !== null) { + window.clearTimeout(resizeTimer); + } + if (rafId !== null) { + cancelAnimationFrame(rafId); + } }; }, [infiniteGroups.length, handleScroll, middleIndex]); diff --git a/src/pages/groupSearch/GroupSearch.tsx b/src/pages/groupSearch/GroupSearch.tsx index ce8199a2..511c1e11 100644 --- a/src/pages/groupSearch/GroupSearch.tsx +++ b/src/pages/groupSearch/GroupSearch.tsx @@ -221,13 +221,14 @@ const GroupSearch = () => { }, [searchTerm, searchStatus, selectedFilter]); const loadMore = useCallback(async () => { - if (!searchTerm.trim() || !nextCursor || isLast || isLoadingMore) return; + const trimmedTerm = searchTerm.trim(); + const isAllCategory = !trimmedTerm && category === ''; + if ((!isAllCategory && !trimmedTerm) || !nextCursor || isLast || isLoadingMore) return; try { setIsLoadingMore(true); const isFinalized = searchStatus === 'searched'; - const isAllCategory = !searchTerm.trim() && category === ''; const res = await getSearchRooms( - searchTerm.trim(), + trimmedTerm, toSortKey(selectedFilter), nextCursor, isFinalized,