Skip to content

Commit

Permalink
Fix bugs in touch events yet again
Browse files Browse the repository at this point in the history
  • Loading branch information
developerfromjokela committed Oct 30, 2024
1 parent cde466e commit 27690f5
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions client/src/components/availabilities/MeetingGridBodyCells.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -397,6 +397,8 @@ const Cell = React.memo(function Cell({
);
}

const [isClick, setIsClick] = React.useState(false); // Track whether user is dragging

let onMouseEnter: React.MouseEventHandler | undefined;
let onMouseLeave: React.MouseEventHandler | undefined;
let onMouseDown: React.MouseEventHandler | undefined;
Expand All @@ -407,6 +409,7 @@ const Cell = React.memo(function Cell({
) {
if (mouseStateType === 'upNoCellsSelected') {
onTouchStart = (e) => {
setIsClick(true);
e.preventDefault(); // Prevents triggering mouse events on touch
dispatch(notifyMouseDown({ cell: { rowIdx, colIdx }, wasOriginallySelected: isSelected }));
};
Expand All @@ -415,6 +418,7 @@ const Cell = React.memo(function Cell({
onMouseEnter = () => dispatch(notifyMouseEnter({ cell: { rowIdx, colIdx } }));
onTouchMove = (e) => {
e.preventDefault();
setIsClick(false)
const touch = e.touches[0];
const targetElement = document.elementFromPoint(touch.clientX, touch.clientY);
if (targetElement) {
Expand All @@ -424,6 +428,10 @@ const Cell = React.memo(function Cell({
}
};
}
onTouchEnd = () => {
if (!isClick)
dispatch(notifyMouseUp());
};
} else if (selMode.type === 'selectedUser') {
onMouseDown = () => showToast({
msg: `Klikkaa 'Muokkaa sopiva ajankohta' painiketta`,
Expand Down

0 comments on commit 27690f5

Please sign in to comment.