Skip to content

lambda change for random number #83

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

Open
wants to merge 35 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
09b254a
Update App.js
JamFactory Feb 18, 2023
63a4e6b
Update hello.js
JamFactory Feb 18, 2023
1acc188
Add constant to myMsg
JamFactory Feb 19, 2023
322c189
Update hello.js
JamFactory Feb 20, 2023
d2d1e26
TrainSimulator added
JamFactory Feb 20, 2023
251e9ff
Commented Ot Start Stop functions
JamFactory Feb 20, 2023
b9b45c6
Added Button
JamFactory Feb 20, 2023
6ee1f3b
added function to get values..
JamFactory Feb 20, 2023
edda6ce
move stoped Simulation out of function
JamFactory Feb 20, 2023
0a7d32a
nm
JamFactory Feb 20, 2023
4cb2995
nm2
JamFactory Feb 20, 2023
381efef
Code Change
JamFactory Feb 20, 2023
cb5d67a
updated scope
JamFactory Feb 20, 2023
e750bb6
added StartSimulation to sliders
JamFactory Feb 20, 2023
2d32a4c
added StartSimulation to sliders
JamFactory Feb 20, 2023
cb9bd24
added ReasctuseEffect
JamFactory Feb 20, 2023
ef2a30e
changed to functions
JamFactory Feb 20, 2023
5f11799
added slidervalues
JamFactory Feb 20, 2023
0e82920
hh
JamFactory Feb 20, 2023
3fb012d
add slider nmp
JamFactory Feb 20, 2023
3c2bf19
add react range input to package.json
JamFactory Feb 20, 2023
2e989e2
mm
JamFactory Feb 20, 2023
77f1e8f
newstart
JamFactory Feb 20, 2023
dcaf4cb
handle change
JamFactory Feb 20, 2023
2f991f3
kl
JamFactory Feb 20, 2023
29b49d7
jj
JamFactory Feb 20, 2023
386aa05
jjh
JamFactory Feb 20, 2023
63091f6
...
JamFactory Feb 20, 2023
ac24b11
useEffect
JamFactory Feb 20, 2023
4a9bcb9
change to tenth second
JamFactory Feb 20, 2023
5d8b667
Added Div insetad of console
JamFactory Feb 21, 2023
5113bc4
new
JamFactory Feb 21, 2023
f626d59
changed to object
JamFactory Feb 21, 2023
a1accf7
auto scroll to bottom
JamFactory Feb 21, 2023
1440fd0
logRef scrollable
JamFactory Feb 21, 2023
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
4 changes: 3 additions & 1 deletion src/App.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React, { Component } from "react"
import logo from "./logo.svg"
import "./App.css"
import TrainSimulator from './TrainSimulator';

class LambdaDemo extends Component {
constructor(props) {
Expand Down Expand Up @@ -38,9 +39,10 @@ class App extends Component {
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
Hi Neil Edit <code>src/App.js</code> and save to reload.
</p>
<LambdaDemo />
<TrainSimulator/>
</header>
</div>
)
Expand Down
111 changes: 111 additions & 0 deletions src/TrainSimulator.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
import React, { useState, useEffect, useRef } from 'react';

function TrainSimulator() {
const [speed, setSpeed] = useState(0);
const [throttle, setThrottle] = useState(0);
const [pressure, setPressure] = useState(0);
const [isRunning, setIsRunning] = useState(false);
const intervalRef = useRef(null);
const logRef = useRef(null);

useEffect(() => {
if (isRunning) {
intervalRef.current = setInterval(() => {
//console.log({ speed, throttle, pressure });
const logElement = document.createElement('div');
logElement.innerText = JSON.stringify({ speed, throttle, pressure });
logRef.current.appendChild(logElement);
if (logRef.current) {
logRef.current.scrollTop = logRef.current.scrollHeight;
}

}, 1000);
} else {
clearInterval(intervalRef.current);
}




return () => {
clearInterval(intervalRef.current);
};
}, [isRunning, speed, throttle, pressure]);

const startSimulation = () => {
setIsRunning(true);
};

const stopSimulation = () => {
setIsRunning(false);
};

const handleSpeedChange = (event) => {
setSpeed(event.target.value);
};

const handleThrottleChange = (event) => {
setThrottle(event.target.value);
};

const handlePressureChange = (event) => {
setPressure(event.target.value);
};


return (
<div>
<div style={{ maxHeight: '200px', overflowY: 'auto', marginTop: '20px' }} ref={logRef} />

<div>
<label htmlFor="speed">Speed:</label>
<input
type="range"
id="speed"
name="speed"
min="0"
max="100"
value={speed}
onChange={handleSpeedChange}
/>
<span>{speed}</span>
</div>
<div>
<label htmlFor="throttle">Throttle:</label>
<input
type="range"
id="throttle"
name="throttle"
min="0"
max="100"
value={throttle}
onChange={handleThrottleChange}
/>
<span>{throttle}</span>
</div>
<div>
<label htmlFor="pressure">Pressure:</label>
<input
type="range"
id="pressure"
name="pressure"
min="0"
max="100"
value={pressure}
onChange={handlePressureChange}
/>
<span>{pressure}</span>
</div>
<div>
{isRunning ? (
<button onClick={stopSimulation}>Stop</button>
) : (
<button onClick={startSimulation}>Start</button>
)}
</div>
</div>
);
}


export default TrainSimulator;
4 changes: 3 additions & 1 deletion src/lambda/hello.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// this uses the callback syntax, however, we encourage you to try the async/await syntax shown in async-dadjoke.js
export function handler(event, context, callback) {
console.log('queryStringParameters', event.queryStringParameters)
let x = (Math.random(1,100) *100);
const myMsg = 'Hello Cris, Your number is ' + x;
callback(null, {
statusCode: 200,
body: JSON.stringify({ msg: 'Hello, World!' }),
body: JSON.stringify({ msg: myMsg }),
})
}