Skip to content

Commit

Permalink
fix: MDS-1320 workaround working
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioGranada committed Sep 25, 2024
1 parent eaafca1 commit cf83cc8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 24 deletions.
18 changes: 5 additions & 13 deletions packages/core/src/carousel/Carousel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ const Reel = ({ children, className, ...rest }: SubcomponentProps) => {
handleMouseUp,
debounceMouseDown,
debounceMouseUp,
isDragging,
} = useCarouselContext("Carousel.Reel");
const arrayChildren = Children.toArray(children);
const revertChildren = arrayChildren.reverse();
Expand All @@ -138,28 +139,19 @@ const Reel = ({ children, className, ...rest }: SubcomponentProps) => {
className,
)}
onMouseEnter={() => {
console.log("in here oe on mouse enter");
handleMouseDown?.();
}}
onMouseLeave={() => {
console.log("in here oe on mouse leave");
handleMouseUp?.();
}}
onTouchStart={() => {
// handleMouseDown?.();
console.log("in here oe on touch start");
if (debouncedMouseDown) {
console.log("in here oe inside down");
debouncedMouseDown();
if (!isDragging) {
handleMouseDown?.();
}
}}
onTouchEnd={() => {
// handleMouseUp?.();
// debouncedMouseUp?.();
console.log("in here oe on touch end");
if (debouncedMouseUp) {
console.log("in here oe inside up");
debouncedMouseUp();
if (isDragging) {
debouncedMouseUp?.();
}
}}
ref={containerRef}
Expand Down
7 changes: 3 additions & 4 deletions packages/core/src/carousel/private/utils/useInterval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,15 @@ const useInterval = (
savedCallback.current?.();
}

console.log("in here oe test", { isDragging, intervalId, delay });

if (isDragging && intervalId) {
// clearInterval(intervalId);
clearInterval(intervalId);
setIntervalId(undefined);
return () => {
clearInterval(intervalId);
};
}

if (delay !== null) {
if (!isDragging && delay !== null) {
let id = setInterval(tick, delay);
setIntervalId(id);
return () => {
Expand Down
12 changes: 5 additions & 7 deletions packages/core/src/carousel/private/utils/withHorizontalScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ const findFirstVisibleIndex = (childRefs: any[]): any => {
return childRefs.findIndex((child) => child.getAttribute("visible"));
};

const scrollToIndex = (
const scrollToIndex = async (
itemRef: HTMLElement,
scrollIntoViewSmoothly: any,
containerRef?: any,
scrollStep?: number,
isNotSmooth?: boolean,
) => {
if (itemRef) {
scrollIntoViewSmoothly(itemRef, {
await scrollIntoViewSmoothly(itemRef, {
block: "nearest",
inline: scrollStep === 1 ? "center" : "nearest",
behavior: isNotSmooth ? undefined : "smooth",
Expand Down Expand Up @@ -234,18 +234,16 @@ export const withHorizontalScroll = (options: Options): any => {
}, []);

const handleMouseDown = () => {
setIsDragging(true);
console.log("in here oe mouse down");
setIsDragging((prevState) => !prevState);
};

const handleMouseUp = () => {
setIsDragging(false);
setIsDragging((prevState) => !prevState);
console.log("in here oe mouse up");
};

const debounce = (fallback: (...args: any) => void, delay: number) => {
let timer: number;

return (...args: any) => {
clearTimeout(timer);
timer = setTimeout(() => {
Expand All @@ -259,7 +257,7 @@ export const withHorizontalScroll = (options: Options): any => {
};

const debounceMouseUp = () => {
return debounce(handleMouseUp, 500);
return debounce(handleMouseUp, 3000);
};

return {
Expand Down

0 comments on commit cf83cc8

Please sign in to comment.