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

Tigers- Lindsey B. & Masha #81

Open
wants to merge 14 commits 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
Binary file added favicon.ico
Binary file not shown.
59 changes: 59 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,70 @@
<html lang="en">
<head>
<meta charset="UTF-8">
<link href="styles/index.css" rel="stylesheet">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
</head>
<body>

<div class="container">
<header class="header">
Weather Report <span>for the lovely city of
<span id="headerCityName">
Seattle

Choose a reason for hiding this comment

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

This is totally fine but remember that you could keep this empty and then load the default state when you begin!

</span>
</span>
</header>
<div class="white-boxes">
<div class="white" id="temperature_box">
<h2>Temperature</h2>
<div class="temperature_content">
<div class="change_temperature">
<span id="increaseTemp">⬆️</span>
<span id="temp">70</span>

Choose a reason for hiding this comment

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

Same thing as above! This could be loaded in from the default state!

<span id="decreaseTemp">⬇️</span>
</div>
<button id="getTemp">Get Realtime Temperature</button>
<section id="tempContainer"></section>
<!-- new code added in, grouping element to help with styling -->
</div>
</div>
<div class="white" id="sky_box">
<h2>Sky</h2>
<select id="selectSky">
<option>Sunny</option>
<option>Cloudy</option>
<option>Rainy</option>
<option>Snowy</option>
</select>
</div>
<div class="white" id="city_name">
<h2>City name</h2>
<input type="text" id="cityNameInput" value="Seattle" />
<button id="resetCity" class="resetButton">Reset</button>
</div>
</div>
<div class="content">
<div class = "garden_name">Weather Garden</div>
<div class="garden" id="weatherBox">
<div id="sky"></div>
<div id="garden"></div>
</div>
</div>
<footer> Lindsey & Masha's Weather Report © 2022 </footer>


<!-- <div class="box">

</div> -->






<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="/src/index.js"></script>

Choose a reason for hiding this comment

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

Overall, your html looks really good here! Well done!

</body>
</html>
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"dependencies": {
"axios": "^0.27.2"
"axios": "^1.2.1"
}
}
167 changes: 167 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
'use strict';

console.log('testing');

const BASE_URL = 'http://localhost:5000';

const state = {
city: 'Seattle',
temp: 70,
lat: 47.6062,
lon: -122.3321,
};

Choose a reason for hiding this comment

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

Good job creating a default state here!

const increaseTemperature = (event) => {
console.log('in increaseTemp:', event);
state.temp += 1;
changeColorAndGarden();
};

const decreaseTemperature = (event) => {
console.log('in decreaseTemp:', event);
state.temp -= 1;
changeColorAndGarden();
};

Choose a reason for hiding this comment

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

Good use of helper functions!

const changeColorAndGarden = () => {
let temp = state.temp;
let color = 'red';
let garden = '🦜🦜__😎_ 🌞__⛱⛱_ ';

if (temp >= 80) {
color = 'red';
garden = '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂';
} else if (temp >= 70) {
color = 'orange';
garden = '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷';
// garden = '🦜🦜__😎_ 🌞__⛱⛱_ ';
} else if (temp >= 60) {
color = 'yellow';
garden = '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃';
} else if (temp >= 50) {
color = 'green';
garden = '❄️🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲️';
} else {
color = 'teal';
garden = '❄️❄️❄️❄️❄️⛄️⛄️⛄️⛄️⛄️⛄️❄️❄️❄️❄️❄️';
}

const newgarden = document.getElementById('garden');
newgarden.textContent = garden;
const temperature = document.getElementById('temp');
// temperature.className = color;
temperature.style.color = color;
// temperature.textContent = String(state.temp);
temperature.textContent = state.temp;
};

const modifySky = (event) => {
console.log('in Modify Sky name:', event);
let sky = document.getElementById('selectSky');
let color = 'lightblue';

let sky_visual = '😎😎😎😎😎🌞🌞🌞🌞🌞';
if (sky.value === 'Sunny') {
sky_visual = '😎😎😎😎😎🌞🌞🌞🌞🌞';
color = 'lightyellow';
} else if (sky.value === 'Cloudy') {
sky_visual = '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️';
color = 'lightgray';
} else if (sky.value === 'Rainy') {
sky_visual = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧';
color = 'darkblue';
} else if (sky.value === 'Snowy') {
sky_visual = '❄️❄️❄️❄️🌨🌨🌨🌨❄️❄️❄️❄️';
color = 'white';
}

const skyInWeatherBox = document.getElementById('sky');
skyInWeatherBox.textContent = sky_visual;
const weatherBox = document.getElementById('weatherBox');
weatherBox.style.backgroundColor = color;
};

const modifyCityName = (event) => {
console.log('in Modify City name:', event);
const cityInput = document.getElementById('cityNameInput').value;
const headerCityName = document.getElementById('headerCityName');
state.city = cityInput;
headerCityName.textContent = state.city;
};

const resetCityName = (event) => {
console.log('in Reset City name:', event);
const cityInput = document.getElementById('cityNameInput');
cityNameInput.value = 'Seattle';
modifyCityName();
};

Choose a reason for hiding this comment

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

More helper functions! Well done!


const getLatAndLon = async () => {
try {
const response = await axios.get('http://localhost:5000/location', {
params: { q: state.city },
});
state.lat = response.data[0].lat;
state.lon = response.data[0].lon;
console.log(state);
} catch (error) {
console.log('Error in get Lat & Lon');
}
};

const getWeather = async () => {
await getLatAndLon();
// changeColorAndGarden();
axios
.get('http://127.0.0.1:5000/weather', {
params: {
lat: state.lat,
lon: state.lon,
units: 'imperial',
},
})

.then((response) => {
const temp = response.data.main.temp;
console.log(response.data.main.temp);
// document.getElementById('temp') = temp;
state.temp = Math.round((temp - 273.15) * 1.8 + 32);
const newTemp = document.getElementById('temp');
newTemp.textContent = state.temp;
changeColorAndGarden();
})

.catch((error) => {
console.log('Error calling OpenWeather');
});
};

Choose a reason for hiding this comment

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

Great job with these axios functions. The move to make them async functions was a really smart choice!


const registerEventHandlers = (event) => {
console.log('in registerEventHandlers:', event);

changeColorAndGarden();
getLatAndLon();

const increaseTemp = document.getElementById('increaseTemp');
increaseTemp.addEventListener('click', increaseTemperature);

const decreaseTemp = document.getElementById('decreaseTemp');
decreaseTemp.addEventListener('click', decreaseTemperature);

// modifyCityName();
const cityNameInput = document.getElementById('cityNameInput');
cityNameInput.addEventListener('input', modifyCityName);

const cityResetButton = document.getElementById('resetCity');
cityResetButton.addEventListener('click', resetCityName);

modifySky();
const selectNewSky = document.getElementById('selectSky');
selectNewSky.addEventListener('change', modifySky);

getWeather();
const getTemp = document.getElementById('getTemp');
getTemp.addEventListener('click', getWeather);

Choose a reason for hiding this comment

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

These all look great!

};

document.addEventListener('DOMContentLoaded', registerEventHandlers);
84 changes: 84 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

body {
background-color: rgb(17, 129, 241);
font-family: "Montserrat", sans-serif;
font-weight: 400;
}


.container {
width: 80%;
height: 60%;
margin: auto;
/* background-color: lightblue; */

display: grid;
grid-template: 15% auto 5% /30% 70%;
}
/* grid-template-columns: 100px 100px; */

.header {
grid-column: auto / span 2;
color: white;
font-size: 40px;
}

.white-boxes {

display: flex;
flex-direction: column;
justify-content: space-around;


/* grid-row: auto; */
}

.white {
background-color: white;
border-radius: 10px;
margin: 15px;
padding: 5% 5%;


}

.content {

/* grid-row: auto; */
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;

}

#temp {
color: orange
}

.garden_name {
width: 50%;
border-radius: 10px;
margin: 10px;
padding: 5px 22px;
font-size: large;
color: white;
text-align: center;
}

.garden {
background-color: white;
width: 50%;
border-radius: 10px;
margin: 10px;
padding: 55px 22px;
text-align: center;


}

footer {
grid-column: auto / span 2;
font-size: large;
color: white;
}