-
Notifications
You must be signed in to change notification settings - Fork 19
Feat: Weather, Speed, Battery, and Range implementation #339
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
David-Rodriguez-Barrios
wants to merge
3
commits into
master
Choose a base branch
from
David
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
21279d5
Feat: Weather, Speed, Battery, and Range implementation
HeliosTelemetry-Bot a9b05a5
FIX: Reduced the number of states and implemented changes to get rid …
HeliosTelemetry-Bot 782ff8c
FIX: Integrated a Reducer Hook for the weather,battery, and speed OnC…
HeliosTelemetry-Bot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 127 additions & 4 deletions
131
Recruit-Training/Advanced-Recruit-Training/Telemetry-Teaser/src/App.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,148 @@ | ||
| // import { parse } from "path"; | ||
| // import { stringify } from "querystring"; | ||
| import { useState } from "react"; | ||
| import { useReducer } from "react"; | ||
|
|
||
| import BatteryInput from "~/components/batteryInput"; | ||
| import Header from "~/components/header"; | ||
| import SpeedInput from "~/components/speedInput"; | ||
| import WeatherInput from "~/components/weatherInput"; | ||
|
|
||
| const App = () => { | ||
| const [visible, setVisible] = useState(false); | ||
| type InputState = { | ||
| speed: number | undefined; | ||
| battery: number | undefined; | ||
| weather: number; | ||
| }; | ||
| type Action = | ||
| | { type: "SET_BATTERY"; payload: number | undefined } | ||
| | { type: "SET_SPEED"; payload: number | undefined } | ||
| | { type: "SET_WEATHER"; payload: number }; | ||
|
|
||
| const initialState: InputState = { | ||
| speed: 0, | ||
| battery: 100, | ||
| weather: 50, | ||
| }; | ||
|
|
||
| const calculateRange = () => { | ||
| return; | ||
| event?.preventDefault(); | ||
| setVisible(true); | ||
| }; | ||
| function BatteryValid() { | ||
| const battery = inputs["battery"]; | ||
| if (battery !== undefined && battery <= 100 && battery >= 0) { | ||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| function SpeedValid() { | ||
| const speed = inputs["speed"]; | ||
| if (speed !== undefined && speed <= 90 && speed >= 0) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you try to simplify the if else statement to a single ternary? |
||
| return true; | ||
| } else { | ||
| return false; | ||
| } | ||
| } | ||
|
|
||
| const reducer = (state: InputState, action: Action) => { | ||
| setVisible(false); | ||
|
|
||
| switch (action.type) { | ||
| case "SET_BATTERY": | ||
| return { ...state, battery: action.payload }; | ||
| case "SET_SPEED": | ||
| return { ...state, speed: action.payload }; | ||
| case "SET_WEATHER": | ||
| return { ...state, weather: action.payload }; | ||
| default: | ||
| return state; | ||
| } | ||
| }; | ||
| const [inputs, dispatch] = useReducer(reducer, initialState); | ||
|
|
||
| return ( | ||
| <div className="h-screen w-screen bg-[#212121]"> | ||
| <div className="flex h-full flex-col items-center pt-36 text-white"> | ||
| <Header /> | ||
| <form name="simulator" className="flex w-full flex-col items-center"> | ||
| <div className="mb-4 flex w-full flex-col items-center gap-y-4"> | ||
| <SpeedInput /> | ||
| <BatteryInput /> | ||
| <SpeedInput | ||
| value={inputs["speed"]} | ||
| onChange={(e) => | ||
| dispatch({ | ||
| type: "SET_SPEED", | ||
| payload: parseInt(e.target.value), | ||
| }) | ||
| } | ||
| /> | ||
| {!SpeedValid() && ( | ||
| <p className="text-red-500"> | ||
| {" "} | ||
| The speed should be within the range of 0 to 90 | ||
| </p> | ||
| )} | ||
| {inputs["speed"] === undefined && ( | ||
| <p className="text-red-500">Speed is required</p> | ||
| )} | ||
| <BatteryInput | ||
| value={inputs["battery"]} | ||
| onChange={(e) => | ||
| dispatch({ | ||
| type: "SET_BATTERY", | ||
| payload: parseInt(e.target.value), | ||
| }) | ||
| } | ||
| /> | ||
| {!BatteryValid() && ( | ||
| <p className="text-red-500"> | ||
| The battery percentage should be with the range of 0 to 100 | ||
| </p> | ||
| )} | ||
| {inputs["battery"] === undefined && ( | ||
| <p className="text-red-500">Battery percentage is required</p> | ||
| )} | ||
| </div> | ||
| <div className="flex w-full flex-row justify-center gap-4"> | ||
| <WeatherInput /> | ||
| <WeatherInput | ||
| value={inputs["weather"]} | ||
| onChange={(value) => | ||
| dispatch({ | ||
| type: "SET_WEATHER", | ||
| payload: value, | ||
| }) | ||
| } | ||
| /> | ||
| </div> | ||
|
|
||
| <button | ||
| className="mt-10 h-10 w-60 rounded bg-blue-200 text-white" | ||
| type="submit" | ||
| onClick={() => calculateRange()} | ||
| > | ||
| Submit | ||
| </button> | ||
| {visible && | ||
| BatteryValid() && | ||
| SpeedValid() && | ||
| inputs["battery"] !== undefined && | ||
| inputs["speed"] !== undefined && ( | ||
| <p className="mt-10"> | ||
| The predicted range of the Eylsia is{" "} | ||
| {( | ||
| -( | ||
| (inputs["speed"] * inputs["speed"] * inputs["battery"]) / | ||
| 2500 | ||
| ) + | ||
| 4 * inputs["battery"] + | ||
| inputs["weather"] | ||
| ).toFixed(3)}{" "} | ||
| km | ||
| </p> | ||
| )} | ||
| </form> | ||
| </div> | ||
| </div> | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 32 additions & 4 deletions
36
...Training/Advanced-Recruit-Training/Telemetry-Teaser/src/components/weatherInput/index.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can you try to simplify the if else statement to a single ternary?