Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
single cell
Browse files Browse the repository at this point in the history
-_-
  • Loading branch information
mirmirmirr committed Dec 3, 2024
1 parent fe0156d commit a385588
Showing 1 changed file with 12 additions and 13 deletions.
25 changes: 12 additions & 13 deletions src/pages/Availability.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ export default function Availability() {

const { isDarkMode, toggleTheme } = useTheme();

const [isTouchDevice, setIsTouchDevice] = useState(false);
const [isDragging, setIsDragging] = useState(false);
const [dragStart, setDragStart] = useState(null);
const [dragEnd, setDragEnd] = useState(null);
Expand Down Expand Up @@ -83,14 +84,20 @@ export default function Availability() {
};
}, [isDragging]);

useEffect(() => {
const checkTouchDevice = () => {
setIsTouchDevice('ontouchstart' in window || navigator.maxTouchPoints > 0);
};
checkTouchDevice();
}, []);

const handleTouchStart = (e) => {
const touch = e.touches[0];
const targetCell = document.elementFromPoint(touch.clientX, touch.clientY);

if (targetCell && targetCell.tagName === 'TD') {
const day = targetCell.getAttribute('data-day');
const hour = targetCell.getAttribute('data-hour');
console.log('hover: ', currentPage * daysPerPage + hour);
setIsDragging(true);
setDragStart({
day: Number(day),
Expand Down Expand Up @@ -120,9 +127,6 @@ export default function Availability() {
};

const handleTouchEnd = () => {
setIsDragging(false);
setDragStart(null);
setDragEnd(null);
handleMouseUp();
};

Expand Down Expand Up @@ -697,18 +701,13 @@ export default function Availability() {
: 'transparent',
userSelect: 'none',
}}
onMouseDown={() =>
handleMouseDown(row, currentPage * daysPerPage + column)
}
onMouseEnter={() =>
handleMouseEnter(
row,
currentPage * daysPerPage + column
)
}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
{...(!isTouchDevice && {
onMouseDown: (e) => handleMouseDown(row, currentPage * daysPerPage + column),
onMouseEnter: (e) => handleMouseEnter(row, currentPage * daysPerPage + column),
})}
></td>
))}
</tr>
Expand Down

0 comments on commit a385588

Please sign in to comment.