feat: emit mousedown only if !getText
This commit is contained in:
@@ -2,6 +2,7 @@ import React, { useCallback, useEffect, useRef } from 'react';
|
|||||||
import { useSocketStore } from '../../context/socket';
|
import { useSocketStore } from '../../context/socket';
|
||||||
import { getMappedCoordinates } from "../../helpers/inputHelpers";
|
import { getMappedCoordinates } from "../../helpers/inputHelpers";
|
||||||
import { useGlobalInfoStore } from "../../context/globalInfo";
|
import { useGlobalInfoStore } from "../../context/globalInfo";
|
||||||
|
import { useActionContext } from '../../context/browserActions';
|
||||||
|
|
||||||
interface CreateRefCallback {
|
interface CreateRefCallback {
|
||||||
(ref: React.RefObject<HTMLCanvasElement>): void;
|
(ref: React.RefObject<HTMLCanvasElement>): void;
|
||||||
@@ -26,6 +27,7 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
const canvasRef = useRef<HTMLCanvasElement>(null);
|
const canvasRef = useRef<HTMLCanvasElement>(null);
|
||||||
const { socket } = useSocketStore();
|
const { socket } = useSocketStore();
|
||||||
const { setLastAction, lastAction } = useGlobalInfoStore();
|
const { setLastAction, lastAction } = useGlobalInfoStore();
|
||||||
|
const { getText, getScreenshot } = useActionContext();
|
||||||
|
|
||||||
const notifyLastAction = (action: string) => {
|
const notifyLastAction = (action: string) => {
|
||||||
if (lastAction !== action) {
|
if (lastAction !== action) {
|
||||||
@@ -45,8 +47,11 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case 'mousedown':
|
case 'mousedown':
|
||||||
const clickCoordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
const clickCoordinates = getMappedCoordinates(event, canvasRef.current, width, height);
|
||||||
// needed for navigation
|
if (getText === true) {
|
||||||
socket.emit('input:mousedown', clickCoordinates);
|
console.log('get text')
|
||||||
|
} else {
|
||||||
|
socket.emit('input:mousedown', clickCoordinates);
|
||||||
|
}
|
||||||
notifyLastAction('click');
|
notifyLastAction('click');
|
||||||
break;
|
break;
|
||||||
case 'mousemove':
|
case 'mousemove':
|
||||||
@@ -78,7 +83,7 @@ const Canvas = ({ width, height, onCreateRef }: CanvasProps) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [socket]);
|
}, [socket, getText]);
|
||||||
|
|
||||||
const onKeyboardEvent = useCallback((event: KeyboardEvent) => {
|
const onKeyboardEvent = useCallback((event: KeyboardEvent) => {
|
||||||
if (socket) {
|
if (socket) {
|
||||||
|
|||||||
Reference in New Issue
Block a user