fix: events back

This commit is contained in:
cha0s 2020-12-14 06:36:27 -06:00
parent c413f17e71
commit 7b853b4ecc
2 changed files with 47 additions and 0 deletions

View File

@ -0,0 +1,43 @@
/* eslint-disable no-param-reassign */
export default function AppCenterEvents(ref, paneWidth) {
let lastPress;
const abstract = {
down: ({pageX, target}) => {
if (ref.current) {
if (target.closest('.dismiss-side')) {
ref.current.style.left = `-${paneWidth}px`;
target.click();
return;
}
const left = parseInt(ref.current.style.left || -paneWidth, 10);
const windowWidth = window.innerWidth;
if (
(left === -(2 * paneWidth) && pageX < windowWidth - paneWidth)
|| (left === 0 && pageX > paneWidth)) {
lastPress = Date.now();
}
}
},
move: () => {},
up: () => {
if (Date.now() - lastPress < 300) {
ref.current.style.left = `-${paneWidth}px`;
}
lastPress = undefined;
},
};
return {
onMouseDown: abstract.down,
onMouseMove: abstract.move,
onMouseUp: abstract.up,
onTouchStart: (event) => {
abstract.down(event.touches[0]);
},
onTouchMove: (event) => {
abstract.move(event.touches[0]);
},
onTouchEnd: (event) => {
abstract.up(event.touches[0]);
},
};
}

View File

@ -18,6 +18,8 @@ import Right from 'components/right';
import useBreakpoints from 'hooks/useBreakpoints';
import usePaneWidth from 'hooks/usePaneWidth';
import AppCenterEvents from './app-center-events';
const App = () => {
const ref = useRef(null);
const {desktop} = useBreakpoints();
@ -67,6 +69,8 @@ const App = () => {
<div
className={classnames('app__center', {isAnonymous})}
ref={ref}
// eslint-disable-next-line react/jsx-props-no-spreading
{...AppCenterEvents(ref, paneWidth)}
>
{!isAnonymous && <Left />}
<div className="main">