From 6fba3c7fdaaed12d94dee359f520591e55cb76d8 Mon Sep 17 00:00:00 2001
From: brynnchernosky <56202540+brynnchernosky@users.noreply.github.com>
Date: Tue, 31 Jan 2023 12:42:45 -0500
Subject: convert from functional to class components
---
src/client/views/nodes/PhysicsSimulationApp.tsx | 6 +-
src/client/views/nodes/PhysicsSimulationWall.tsx | 26 +++---
src/client/views/nodes/PhysicsSimulationWedge.tsx | 96 ++++++++++++++---------
3 files changed, 74 insertions(+), 54 deletions(-)
(limited to 'src')
diff --git a/src/client/views/nodes/PhysicsSimulationApp.tsx b/src/client/views/nodes/PhysicsSimulationApp.tsx
index 2a314a723..414d61809 100644
--- a/src/client/views/nodes/PhysicsSimulationApp.tsx
+++ b/src/client/views/nodes/PhysicsSimulationApp.tsx
@@ -329,9 +329,7 @@ export default class App extends React.Component<{}, IState> {
render () {
return (
-
- );
- }
+ Hello world!
//
+ );
+ }
}
diff --git a/src/client/views/nodes/PhysicsSimulationWall.tsx b/src/client/views/nodes/PhysicsSimulationWall.tsx
index c2d3567f1..a31704d2f 100644
--- a/src/client/views/nodes/PhysicsSimulationWall.tsx
+++ b/src/client/views/nodes/PhysicsSimulationWall.tsx
@@ -1,3 +1,4 @@
+import React from "react";
import { useState, useEffect } from "react";
export interface Force {
@@ -11,24 +12,25 @@ export interface IWallProps {
angleInDegrees: number;
}
-export const Wall = (props: IWallProps) => {
- const { length, xPos, yPos, angleInDegrees } = props;
+export default class App extends React.Component {
- let wallStyle = {
- width: length + "%",
- height: 0.5 + "vw",
+ constructor(props: any) {
+ super(props)
+ }
+
+ wallStyle = {
+ width: this.props.angleInDegrees == 0 ? this.props.length + "%" : 0.5 + "vw",
+ height: this.props.angleInDegrees == 0 ? 0.5 + "vw" : this.props.length + "%",
position: "absolute" as "absolute",
- left: xPos + "%",
- top: yPos + "%",
+ left: this.props.xPos + "%",
+ top: this.props.yPos + "%",
backgroundColor: "#6c7b8b",
zIndex: -1000,
margin: 0,
padding: 0,
};
- if (angleInDegrees != 0) {
- wallStyle.width = 0.5 + "vw";
- wallStyle.height = length + "%";
- }
- return ;
+ render () {
+ return ();
+ }
};
diff --git a/src/client/views/nodes/PhysicsSimulationWedge.tsx b/src/client/views/nodes/PhysicsSimulationWedge.tsx
index 0dc7751f3..bf0cadce2 100644
--- a/src/client/views/nodes/PhysicsSimulationWedge.tsx
+++ b/src/client/views/nodes/PhysicsSimulationWedge.tsx
@@ -1,3 +1,4 @@
+import React from "react";
import { useState, useEffect, useCallback } from "react";
import "./PhysicsSimulationBox.scss";
@@ -7,58 +8,75 @@ export interface IWedgeProps {
startLeft: number;
}
-export const Wedge = (props: IWedgeProps) => {
- const { startHeight, startWidth, startLeft } = props;
+interface IState {
+ angleInRadians: number,
+ left: number,
+ coordinates: string,
+}
+
+export default class Wedge extends React.Component {
- const [angleInRadians, setAngleInRadians] = useState(
- Math.atan(startHeight / startWidth)
- );
- const [left, setLeft] = useState(startLeft);
- const [coordinates, setCoordinates] = useState("");
+ constructor(props: any) {
+ super(props)
+ this.state = {
+ angleInRadians: Math.atan(this.props.startHeight / this.props.startWidth),
+ left: this.props.startLeft,
+ coordinates: "",
+ }
+ }
- const color = "#deb887";
+ color = "#deb887";
- useEffect(() => {
+ updateCoordinates() {
const coordinatePair1 =
- Math.round(left) + "," + Math.round(window.innerHeight * 0.8) + " ";
+ Math.round(this.state.left) + "," + Math.round(window.innerHeight * 0.8) + " ";
const coordinatePair2 =
- Math.round(left + startWidth) +
+ Math.round(this.state.left + this.props.startWidth) +
"," +
Math.round(window.innerHeight * 0.8) +
" ";
const coordinatePair3 =
- Math.round(left) +
+ Math.round(this.state.left) +
"," +
- Math.round(window.innerHeight * 0.8 - startHeight);
+ Math.round(window.innerHeight * 0.8 - this.props.startHeight);
const coord = coordinatePair1 + coordinatePair2 + coordinatePair3;
- setCoordinates(coord);
- }, [left, startWidth, startHeight]);
+ this.setState({coordinates: coord});
+ }
- useEffect(() => {
- setAngleInRadians(Math.atan(startHeight / startWidth));
- }, [startWidth, startHeight]);
+ componentDidMount() {
+ this.updateCoordinates()
+ }
- return (
-
-
-
- );
+ );
+ }
};
--
cgit v1.2.3-70-g09d2