Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
2594bd7
Created WeatherComponent.jsx; imported and linked to component in App…
jonathaningersoll Oct 26, 2020
ede0f24
ashton-10/26
ashtonsprunger Oct 26, 2020
c8973bc
Merge pull request #2 from ashtonsprunger/ashton
ashtonsprunger Oct 26, 2020
537b92d
Merge branch 'develop' into jonathan
ashtonsprunger Oct 26, 2020
d23f73a
Merge pull request #3 from ashtonsprunger/jonathan
ashtonsprunger Oct 26, 2020
d0681a6
fix .jsx
afrankowork Oct 26, 2020
c013d39
addy 10/26
Oct 27, 2020
03710e9
Merge pull request #7 from ashtonsprunger/adam
ashtonsprunger Oct 27, 2020
7003103
Merge pull request #8 from ashtonsprunger/addy
ashtonsprunger Oct 27, 2020
c906fc0
Adding Fetch stuff and useState variables to weather component
jonathaningersoll Oct 27, 2020
493664a
Merge pull request #9 from ashtonsprunger/jonathan
ashtonsprunger Oct 27, 2020
103af1e
Weather GET Fetch cleaned up
jonathaningersoll Oct 27, 2020
a9add24
added layout
afrankowork Oct 27, 2020
c85cbf9
added layout
afrankowork Oct 27, 2020
726b6ed
Merge pull request #11 from ashtonsprunger/adam
ashtonsprunger Oct 27, 2020
c4f02a4
Merge pull request #12 from ashtonsprunger/jonathan
ashtonsprunger Oct 27, 2020
6ceab55
random-stuff
ashtonsprunger Oct 27, 2020
118ec48
Addy Food 10/26
Oct 27, 2020
baf0b77
Merge branch 'develop' into ashtonz
ashtonsprunger Oct 27, 2020
9f24777
Merge pull request #13 from ashtonsprunger/ashtonz
ashtonsprunger Oct 27, 2020
ebdded3
Merge pull request #14 from ashtonsprunger/addy
ashtonsprunger Oct 27, 2020
d9f0ba5
equations for weather component
jonathaningersoll Oct 27, 2020
83e4ce4
Merge pull request #15 from ashtonsprunger/jonathan
ashtonsprunger Oct 27, 2020
22aade5
Addy 10/26
Oct 27, 2020
8dfa74f
Merge pull request #16 from ashtonsprunger/addy
ashtonsprunger Oct 27, 2020
e05facb
a-working-app
ashtonsprunger Oct 27, 2020
33b5090
app.jsx-2
ashtonsprunger Oct 27, 2020
35d6957
Merge pull request #17 from ashtonsprunger/ashton
ashtonsprunger Oct 27, 2020
cbbf8f6
finalizing weather component and toggle button
jonathaningersoll Oct 27, 2020
911b4cd
ashton-10/27
ashtonsprunger Oct 27, 2020
3ced3df
Cleaned up comments
jonathaningersoll Oct 27, 2020
9e26cd6
Cleaned up some more code
jonathaningersoll Oct 27, 2020
6bbeec5
Made code pretty
jonathaningersoll Oct 27, 2020
0b18867
Merge pull request #18 from ashtonsprunger/jonathan
ashtonsprunger Oct 27, 2020
f1de1d3
Merge branch 'develop' into ashton
ashtonsprunger Oct 27, 2020
04d9be2
Merge pull request #19 from ashtonsprunger/ashton
ashtonsprunger Oct 27, 2020
1b6d514
Food FETCH
Oct 27, 2020
e202307
Merge pull request #20 from ashtonsprunger/addy
ashtonsprunger Oct 27, 2020
05e16ba
final?
ashtonsprunger Oct 27, 2020
f521124
Merge pull request #21 from ashtonsprunger/ashton
ashtonsprunger Oct 27, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
.env.development.local
.env.test.local
.env.production.local
*.env

npm-debug.log*
yarn-debug.log*
Expand Down
76 changes: 76 additions & 0 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,79 @@
transform: rotate(360deg);
}
}

.switch {
position: relative;
display: inline-block;
width: 60px;
height: 34px;
}

/* Hide default HTML checkbox */
.switch input {
opacity: 0;
width: 0;
height: 0;
}

/* The slider */
.slider {
position: absolute;
cursor: pointer;
top: 0;
left: 0;
right: 0;
bottom: 0;
background-color: #ccc;
-webkit-transition: 0.4s;
transition: 0.4s;
}

.slider:before {
position: absolute;
content: "";
height: 26px;
width: 26px;
left: 4px;
bottom: 4px;
background-color: white;
-webkit-transition: 0.4s;
transition: 0.4s;
}

input:checked + .slider {
background-color: #2196f3;
}

input:focus + .slider {
box-shadow: 0 0 1px #2196f3;
}

input:checked + .slider:before {
-webkit-transform: translateX(26px);
-ms-transform: translateX(26px);
transform: translateX(26px);
}

/* Rounded sliders */
.slider.round {
border-radius: 34px;
}

.slider.round:before {
border-radius: 50%;
}

#head-row {
background-color: lightblue;
padding: 10px;
}

#weather {
padding: 15px;
text-align: center;
}

.weather-row {
text-align: center;
}
67 changes: 50 additions & 17 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,56 @@
import logo from './logo.svg';
import './App.css';
import "./App.css";
import "bootstrap/dist/css/bootstrap.css";
import React, { useState, useEffect } from "react";
import { Row, Col } from "reactstrap";
import NasaComponent from "./Components/NasaComponent";
import FoodComponent from "./Components/FoodComponent";
import WeatherComponent from "./Components/WeatherComponent";

function App() {
const [lat, setLatitude] = useState("");
const [lon, setLongitude] = useState("");

useEffect(() => {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
}
}, []);

const showPosition = (position) => {
setLatitude(position.coords.latitude);
setLongitude(position.coords.longitude);
};

return (
<div className="App">
<header className="App-header">
<img src={logo} className="App-logo" alt="logo" />
<p>
Edit <code>src/App.js</code> and save to reload.
</p>
<a
className="App-link"
href="https://reactjs.org"
target="_blank"
rel="noopener noreferrer"
>
Learn React
</a>
</header>
<div style={{ padding: "1em" }} className="App">
<Row>
<Col>
<h1>Welcome to ajaa</h1>
</Col>
</Row>
<Row>
<Col xs="6">
<h2>Lat: {lat}</h2>
</Col>
<Col xs="6">
<h2>Lon: {lon}</h2>
</Col>
</Row>
<Row>
{lat && lon ? (
<>
<Col xs="4">
<NasaComponent lat={lat} lon={lon} />
</Col>
<Col id="weather" xs="4">
<WeatherComponent lat={lat} lon={lon} />
</Col>
<Col xs="4">
<FoodComponent lat={lat} lon={lon} />
</Col>
</>
) : null}
</Row>
</div>
);
}
Expand Down
53 changes: 53 additions & 0 deletions src/Components/FoodComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import React, { useState, useEffect } from "react";
import { Table } from "reactstrap";

const FoodComponent = (props) => {
let apiKey = "61e3f579285d6f2b7d90dac41a2fdfd9";
let lat = props.lat;
let lon = props.lon;
const [restNames, setRestNames] = useState([]);

useEffect(() => {
fetch(
`https://developers.zomato.com/api/v2.1/geocode?lat=${lat}&lon=${lon}`,
{ headers: { "user-key": apiKey, Accept: "application/json" } }
)
.then((response) => {
return response.json();
})
.then((json) => {
console.log(json);
json.nearby_restaurants.forEach((restaurant) => {
setRestNames((restNames) => [...restNames, restaurant.restaurant]);
});
});
}, []);
const restMapper = () => {
return restNames.map((restaurant, index) => {
return (
<tbody>
<tr key={index}>
<th scope="row">{index + 1}</th>
<td>{restaurant.name}</td>
<td>{restaurant.cuisines}</td>
</tr>
</tbody>
);
});
};
return (
<div>
<h3>Restuarants Near You!</h3>
<Table dark>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
</tr>
</thead>
<tbody>{restMapper()}</tbody>
</Table>
</div>
);
};
export default FoodComponent;
41 changes: 41 additions & 0 deletions src/Components/NasaComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React, { useEffect, useState } from "react";
import { Button } from "reactstrap";

const NasaComponent = (props) => {
const [imageUrl, setImageUrl] = useState(
"https://media.giphy.com/media/3oEjI6SIIHBdRxXI40/giphy.gif"
);
// const [latitude, setLatitude] = useState(props.latitude);
// const [longitude, setLongitude] = useState(props.longitude);
const apiKey = "Wy1wADvYUr6cNdNhe7aFJzcWT9Zk9J5hyEbIPuR4";
const baseUrl = "https://api.nasa.gov/planetary/earth/imagery";

let url = `${baseUrl}?lon=${props.lon}&lat=${
props.lat
}&api_key=${apiKey}&dim=${0.03}`;

const getImage = () => {
console.log("lat:", props.lat);
console.log("lon:", props.lon);
console.log("url:", url);
fetch(url).then((response) => {
setImageUrl(response.url);
console.log("response:", response);
});
};

useEffect(getImage, []);

return (
<div style={{ width: "100%" }}>
<h3>You are here!</h3>
<img
style={{ width: "inherit", borderRadius: "50px" }}
src={imageUrl}
alt="location image"
/>
</div>
);
};

export default NasaComponent;
87 changes: 87 additions & 0 deletions src/Components/WeatherComponent.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import React, { useState, useEffect } from "react";
import { Button, Col, Row } from "reactstrap";

const Weather = (props) => {
console.log(props.lat, props.lon);

const [description, setDescription] = useState("");
const [temperature, setTemperature] = useState("");
const [pressure, setPressure] = useState("");
const [humidity, setHumidity] = useState("");
const [windSpeed, setWindSpeed] = useState("");
const [units, setUnits] = useState("units=imperial");
const [butText, setButText] = useState("Switch to Metric");

const key = "70d415361464c75295b5f22c9849e8c3";
let url = `https://api.openweathermap.org/data/2.5/weather?lat=${props.lat}&lon=${props.lon}&appid=${key}&${units}`;

const getWeather = () => {
fetch(url)
.then((res) => res.json())
.then((data) => {
setDescription(data.weather[0].description);
setTemperature(data.main.temp);
setPressure(data.main.pressure);
setHumidity(data.main.humidity);
setWindSpeed(data.wind.speed);
});
};

useEffect(getWeather, [units]);

const changeUnits = (e) => {
if (units == "units=metric") {
setUnits("units=imperial");
setButText("Switch to Metric");
} else {
setUnits("units=metric");
setButText("Switch to Imperial");
}
};

return (
<>
<h3>Current Weather</h3>
<Row id="head-row">
<Col>Set Imperial (default) or Metric:</Col>
<Col>
<div>
<Button onClick={(e) => changeUnits(e)}>{butText}</Button>
</div>
</Col>
</Row>
<Row className="weather-row">
<span>
<strong>Current weather: </strong>
{description}
</span>
</Row>
<Row>
<span>
<strong>Temperature: </strong>
{temperature}
</span>
</Row>
<Row>
<span>
<strong>Air pressure: </strong>
{pressure}
</span>
</Row>
<Row>
<span>
<strong>Humidity: </strong>
{humidity}%
</span>
</Row>
<Row>
<span>
<strong>Wind speed: </strong>
{windSpeed}
</span>
</Row>
</>
);
};

export default Weather;
12 changes: 6 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';
import React from "react";
import ReactDOM from "react-dom";
import "./index.css";
import App from "./App";
import reportWebVitals from "./reportWebVitals";

ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
document.getElementById("root")
);

// If you want to start measuring performance in your app, pass a function
Expand Down