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

Commit

Permalink
Merge pull request #55 from mirmirmirr/mobile-fixes
Browse files Browse the repository at this point in the history
Mobile fixes
  • Loading branch information
jzgom067 authored Dec 3, 2024
2 parents 5d0a865 + 978b8eb commit 2b2c3bf
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 13 deletions.
35 changes: 22 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,22 @@ 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 +129,6 @@ export default function Availability() {
};

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

Expand Down Expand Up @@ -697,18 +703,21 @@ 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
2 changes: 2 additions & 0 deletions src/resources/TimeSelector.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default function TimeSelector({

const times = [
'12:00 AM',
'1:00 AM',
'2:00 AM',
'3:00 AM',
'4:00 AM',
Expand All @@ -27,6 +28,7 @@ export default function TimeSelector({
'10:00 AM',
'11:00 AM',
'12:00 PM',
'1:00 PM',
'2:00 PM',
'3:00 PM',
'4:00 PM',
Expand Down

0 comments on commit 2b2c3bf

Please sign in to comment.