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
20 changes: 0 additions & 20 deletions src/components/group/MyGroupBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -95,23 +95,6 @@ export function MyGroupBox({ onMyGroupsClick }: MyGroupProps) {
document.body.style.userSelect = '';
};

let touchStartX = 0;
let touchScrollLeft = 0;
const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
isDragging = true;
touchStartX = e.touches[0].pageX - (scrollRef.current?.offsetLeft ?? 0);
touchScrollLeft = scrollRef.current?.scrollLeft ?? 0;
};
const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
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;
Expand Down Expand Up @@ -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) => (
<MyGroupCard
Expand Down
1 change: 1 addition & 0 deletions src/components/group/MyGroupCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const Card = styled.div`
box-sizing: border-box;
transition: transform 0.35s ease-out;
will-change: transform;
transform: translateZ(0);
`;

const Thumbnail = styled.img`
Expand Down
24 changes: 3 additions & 21 deletions src/components/group/RecruitingGroupCarousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -46,23 +46,6 @@ export function RecruitingGroupCarousel({ sections }: Props) {
document.body.style.userSelect = '';
};

let touchStartX = 0;
let touchScrollLeft = 0;
const handleTouchStart = (e: React.TouchEvent<HTMLDivElement>) => {
isDragging = true;
touchStartX = e.touches[0].pageX - (scrollRef.current?.offsetLeft ?? 0);
touchScrollLeft = scrollRef.current?.scrollLeft ?? 0;
};
const handleTouchMove = (e: React.TouchEvent<HTMLDivElement>) => {
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;
Expand Down Expand Up @@ -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) => (
<Item
Expand Down Expand Up @@ -175,7 +155,9 @@ const Item = styled.div`
max-width: 640px;
min-width: 280px;
scroll-snap-align: center;
transition: transform 0.2s;
transition: transform 0.3s ease-out;
will-change: transform;
transform: translateZ(0);

@media (max-width: 480px) {
flex: 0 0 85%;
Expand Down
41 changes: 30 additions & 11 deletions src/hooks/useInfiniteCarousel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,30 +57,49 @@ export function useInfiniteCarousel(groups: Group[], options?: { scaleAmount?: n
const container = scrollRef.current;
if (!container || infiniteGroups.length === 0) return;

let rafId: number | null = null;
const initializeScroll = () => {
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]);

Expand Down
7 changes: 4 additions & 3 deletions src/pages/groupSearch/GroupSearch.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down