Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

block clicks when no position #38

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/components/GravitySimulator/GravitySimulator.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import { SaveScenarioModal } from "../SaveScenarioModal/SaveScenarioModal";
import { createShareableLink } from "../../utils/compression";
import { Particle, ParticleMechanics, TrailPoint } from "../../types/particle";
import { Position } from "@yhattav/react-component-cursor";

const generatePastelColor = () => {
const r = Math.floor(Math.random() * 75 + 180);
Expand All @@ -43,7 +44,7 @@

export interface GravitySimulatorProps {
gravityRef: React.RefObject<HTMLDivElement>;
pointerPosRef: React.RefObject<Point2D>;
pointerPosRef: React.RefObject<Position>;
onDebugData?: (data: DebugData) => void;
className?: string;
removeOverlay?: boolean;
Expand Down Expand Up @@ -175,7 +176,7 @@
document.removeEventListener("fullscreenchange", handleFullscreenChange);
}, []);

const handleDrag = useCallback(

Check warning on line 179 in src/components/GravitySimulator/GravitySimulator.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
throttle(() => {
if (blockInteractions) return;

Expand All @@ -186,7 +187,7 @@
[blockInteractions]
);

const handleReportNewPosition = useCallback(

Check warning on line 190 in src/components/GravitySimulator/GravitySimulator.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useCallback received a function whose dependencies are unknown. Pass an inline function instead
throttle((point: Point2D, index: number) => {
if (!offset) return;
setGravityPoints((points) =>
Expand Down Expand Up @@ -325,7 +326,12 @@

const handleContainerClick = useCallback(() => {
if (blockInteractions) return;

if (
!pointerPosRef.current ||
!pointerPosRef.current.x ||
!pointerPosRef.current.y
)
throw new Error("Pointer position is not defined");
if (isDragging || isDraggingNewStar) return;

if (!isSimulationStarted) {
Expand Down Expand Up @@ -567,7 +573,7 @@

onApiReady(api);
},
[

Check warning on line 576 in src/components/GravitySimulator/GravitySimulator.tsx

View workflow job for this annotation

GitHub Actions / build

React Hook useEffect has missing dependencies: 'createParticle', 'gravityPoints', 'gravityRef', 'handlePointDelete', 'handleSelectScenario', 'isFullscreen', 'isPaused', 'onApiReady', 'particles', 'physicsConfig', 'toggleFullscreen', and 'updateSettings'. Either include them or remove the dependency array. If 'onApiReady' changes too often, find the parent component that defines it and wrap that definition in useCallback
// Add all deps
]
);
Expand Down
7 changes: 2 additions & 5 deletions src/sections/GravitySection.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import React, { useRef, useCallback } from "react";
import { CustomCursor } from "@yhattav/react-component-cursor";
import { CustomCursor, Position } from "@yhattav/react-component-cursor";
import { Card } from "antd";
import { Point2D } from "../utils/types/physics";
//import { GravitySimulator } from "../components/GravitySimulator/GravitySimulator";
import { DebugData } from "../types/Debug";
import { GravitySimulatorWithSettings } from "../components/GravitySimulatorWithSettings/GravitySimulatorWithSettings";
//import { Scenario } from "../types/scenario";

interface GravitySectionProps {
onDebugData?: (data: DebugData) => void;
Expand Down Expand Up @@ -77,7 +74,7 @@ export const GravitySection: React.FC<GravitySectionProps> = ({
onDebugData,
}) => {
const gravityRef = useRef<HTMLDivElement>(null);
const pointerPosRef = useRef<Point2D>({ x: 0, y: 0 });
const pointerPosRef = useRef<Position>({ x: null, y: null });

const handleCursorMove = useCallback(async (x: number, y: number) => {
await new Promise((resolve) => setTimeout(resolve, 0));
Expand Down
Loading