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

base complete #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
164 changes: 158 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"preview": "vite preview"
},
"dependencies": {
"axios": "^1.6.2",
"react": "^18.2.0",
"react-dom": "^18.2.0"
},
Expand Down
38 changes: 37 additions & 1 deletion src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,52 @@
import logo from "/logo.png";
import "./App.css";
import { useState } from "react";
import axios from "axios";

function App() {
const [cityInput, setCityInput] = useState("");
const [cityTemperature, setCityTemperature] = useState("");

const handleSubmit = (event) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Try to extract your key oout of the request. Either have a variable or use a .env file

event.preventDefault();
axios
.get(`http://api.openweathermap.org/geo/1.0/direct?q=${cityInput}&appid=08c1f2e68be9c8bcfc5d3d18c6b0f54e`)
.then((response) => response.data[0])
.then((cityGeoData) =>
axios.get(
`https://api.openweathermap.org/data/2.5/weather?lat=${cityGeoData.lat}&lon=${cityGeoData.lon}&appid=08c1f2e68be9c8bcfc5d3d18c6b0f54e&units=metric`
)
)
.then((response) => {
const { data: weatherData } = response;
console.log(weatherData);
setCityTemperature(weatherData.main.temp);
});
};

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great logic here

const weatherInfo = (
<div>
<p>Current City: {cityInput} </p>
<p>Temperature: {cityTemperature} </p>
</div>
);

return (
<>
<div>
<img src={logo} className="logo react" alt="Rocket logo" />
</div>
<h1>Weather App</h1>
<div className="card">
{/* Follow the weather app instructions on the gitbook to implement this exercise */}
<form onSubmit={handleSubmit}>
<input type="text" value={cityInput} onChange={(event) => setCityInput(event.target.value)} />
<br />
<button type="Submit">Submit</button>
</form>
</div>
{/* testing */}
{cityInput}
{weatherInfo}
</>
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ a {
text-decoration: inherit;
}
a:hover {
color: #535bf2;
color: #034c0d;
}

body {
Expand Down