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

Amethyst - Hannah & Phalesa #72

Open
wants to merge 43 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
8b0a401
change index html
Hannah1Watkins Jun 8, 2023
176f03d
Wireframe
PhePhe123 Jun 8, 2023
8c71b2c
use strict
Hannah1Watkins Jun 8, 2023
00da206
partially completed wave 2 - also added images for different seasons
Hannah1Watkins Jun 8, 2023
3f5f45c
not all my commits went through before- added pictures wave 2 complete
Hannah1Watkins Jun 8, 2023
421bd7f
parcially done w/ wave 3
Hannah1Watkins Jun 8, 2023
1b48e60
changed index.css visuals
Hannah1Watkins Jun 8, 2023
6f8a7ac
added winter emojis to html
Hannah1Watkins Jun 8, 2023
43a079a
changed css file, removed emojis from html
Hannah1Watkins Jun 9, 2023
27e35eb
Emoji and City Input box
PhePhe123 Jun 12, 2023
221024b
changed files to re-arragnge emojis
Hannah1Watkins Jun 13, 2023
93263c0
changed files to re-arragnge emojis
Hannah1Watkins Jun 13, 2023
cb8d964
commiting to accept incomming changes
Hannah1Watkins Jun 13, 2023
12aac09
changed background color, added picture to main page
Hannah1Watkins Jun 13, 2023
c8b99ff
Updated temp emoj-sky
PhePhe123 Jun 13, 2023
387f6a2
Updated temp emoj-sky2
PhePhe123 Jun 13, 2023
997f4fe
changed site visual
Hannah1Watkins Jun 13, 2023
ba0ba43
changed site visual
Hannah1Watkins Jun 13, 2023
14e2f74
changed site visual
Hannah1Watkins Jun 13, 2023
17084c3
Updated default view
PhePhe123 Jun 13, 2023
91acfdb
Updated default view
PhePhe123 Jun 13, 2023
02364bc
Resolved merge errors
PhePhe123 Jun 13, 2023
d6934b8
Testing Sky Emojis
PhePhe123 Jun 13, 2023
1b83c61
changes index.css
Hannah1Watkins Jun 13, 2023
d83b5f7
commiting so I can pull
Hannah1Watkins Jun 13, 2023
89cdf50
Sky Emojis updating with dropdown
PhePhe123 Jun 14, 2023
ce1b7e8
completed wave 6 reset button
Hannah1Watkins Jun 14, 2023
ade628c
Merge branch 'main' of https://github.com/Hannah1Watkins/weather-report
Hannah1Watkins Jun 14, 2023
9bcdb86
completed wave 6 reset button
Hannah1Watkins Jun 14, 2023
a073f1c
added changes for wave 6
Hannah1Watkins Jun 14, 2023
d373cc8
Return City Wave 3
PhePhe123 Jun 14, 2023
9731098
changed button spacing in css
Hannah1Watkins Jun 14, 2023
84b5c4f
changed text color to white in header
Hannah1Watkins Jun 14, 2023
0bc23da
created api requests for wave 4
Hannah1Watkins Jun 14, 2023
4d15522
Minor updates
PhePhe123 Jun 14, 2023
c7dd31d
Merge branch 'main' of https://github.com/Hannah1Watkins/weather-report
PhePhe123 Jun 14, 2023
8c95f50
Tryingto go back
PhePhe123 Jun 15, 2023
30510a9
changed index.js to get current temp, used state
Hannah1Watkins Jun 15, 2023
f7f3108
changed index.js to get current temp, used state
Hannah1Watkins Jun 15, 2023
f2e42ac
made change to correct button error
Hannah1Watkins Jun 15, 2023
67becf5
Updated API Calls
PhePhe123 Jun 15, 2023
cb88ad3
Updated API Calls2
PhePhe123 Jun 15, 2023
12f9284
All Waves Functioning
PhePhe123 Jun 16, 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
77 changes: 75 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,80 @@
<link rel="stylesheet" href="styles/index.css" />
</head>
<body>
<script src="./src/index.js"></script>
<header>
<nav>
<h1>Weather Report</h1>
<h2>For the city of : <p id="cityChoice"></p> </h2>
<!-- <h2>For the city of : <p id="cityTemp"></p> </h2> -->
</nav>
</header>

<div id="temperature-container">
<!-- <div id="city-sky-container">
<div id="city-container">
<label for="city">Enter City:</label>
<input type="text" id="city" oninput="cityInput();" city="city">
<button id="reset-city">Reset City</button>
</div>
<div id="sky-container">
<label for="sky">Choose a sky:</label>
<select name="sky" id="sky" onchange="skySelection();">
<option value="">--Select Sky-- </option>
<option value="sunny">Sunny</option>
<option value="cloudy">Cloudy</option>
<option value="rainy">Rainy</option>
<option value="snowy">Snowy</option>
</select>
</div>
</div> -->
<button id="decrease-btn">Decrease</button>
<span id="temperature">70°F</span>
<button id="increase-btn">Increase</button>
</div>

<div id="city-container">
<label for="city">Enter City:</label>
<input type="text" id="city" oninput="cityInput();" city="city">
<button id="check-current-temp" onclick="currentTempButton();" >Check Current Temp </button>
<button id="reset-city">Reset City</button>
</div>
<!-- <p id="temperature"></p> -->

<div id = "sky-container">
<label for="sky">Choose a sky:</label>
<select name="sky" id="sky" onchange="skySelection();">
<option value="">--Select Sky-- </option>
<option value="sunny">Sunny</option>
<option value="cloudy">Cloudy</option>
<option value="rainy">Rainy</option>
<option value="snowy">Snowy</option>
</select>
</div>

<div id="sky-emoji-container">
<div id="skyEmoji"> 😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️ </div>
</div>

<div id="reset-container">
<div id="city-container" value="">
</div>

<div id="landscape-container">
<figure>
<img id="landscape-img" src="styles/weather.png" alt="Weather">
</figure>
</div>

<div id="emoji-container">
<div id="emoji"> 🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️🌡️ </div>
</div>

<footer>
<p>© 2023 Hannah & Phalesa </p>
</footer>

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

200 changes: 200 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,200 @@
"use strict";

const state = {

Choose a reason for hiding this comment

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

Love how you all chose to use this psuedostate! I think that it is great practice for what you will see in React though it will be utilized differently!

temperature: 70,
emoji: null,
sky: "😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️🌧️😎🌈☁️",
skyEmoji: null,
lat: null,
lon: null
};

// DOM elements
const temperatureElement = document.getElementById('temperature');
const increaseBtn = document.getElementById('increase-btn');
const decreaseBtn = document.getElementById('decrease-btn');
const landscapeImg = document.getElementById('landscape-img');
const emojiElement = document.getElementById('emoji');
const cityElement = document.getElementById('city');
const resetCityButton = document.getElementById('reset-city');
const skyElement = document.getElementById('sky');
const skyEmojiElement = document.getElementById('skyEmoji');
const checkCurrentTempElement = document.getElementById('check-current-temp');
Comment on lines +13 to +22

Choose a reason for hiding this comment

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

Pieces of code like this are usually found in an event handler that runs on the event DOMContentLoaded, basically once the page is html is loaded on the webpage you will run a bunch of initial logic such as grabbing elements and adding event handlers to them. It will look something like this:

document.addEventListener("DOMContentLoaded", function () {
    const increaseTemp = document.querySelector("#increase-temp");
    const decreaseTemp = document.querySelector("#decrease-temp");
    const displayTemp = document.querySelector("#display-temp");
    const resetButton = document.querySelector("#reset-button"); 
    const searchButton = document.querySelector("#search-button");
    const cityName = document.getElementById("city-name");
    const cityInput = document.getElementById("city-input");
    const selectSky = document.querySelector("#sky-dropdown");
    const result = document.querySelector("#sky");
    const landscape = document.querySelector("#landscape");
    
    increaseTemp.addEventListener("click", increaseTemperature);
    decreaseTemp.addEventListener("click", decreaseTemperature);
    ...
}

This is also usually found at the bottom of the file too, that way you can put all your function definitions for event handlers above it!

// const demoElement = document.getElementById('demo');


// find city latitude and longitude
const findCityLocation = () => {
let lat;
let lon;
return axios.get('http://127.0.0.1:5000/location', {
params: {
q: document.getElementById("city").value
}
})
.then( (response) => {
console.log(response)
console.log(document.getElementById("city").value);
lat = response.data[0]['lat'];
lon = response.data[0]['lon'];
console.log('success in findLatitudeAndLongitude!', lat, lon);
getWeather({ lat: lat, lon: lon});
})
.catch((error) => {
console.log(error)
});
};
Comment on lines +27 to +46

Choose a reason for hiding this comment

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

Here's an alternative to promise chaining! You can use the async/await keywords to have your function wait until a promise is fulfilled and then you pass the results of that promise to other pieces of your function like assigning your return values as variables or other things like that. It looks something like this:

const findCityLocation = async () => {
    let lat;
    let lon;
    const resp = await axios.get('http://127.0.0.1:5000/location', {
        params: {
            q: document.getElementById("city").value
        }
    })
    
    try {
      [lat, lon] = resp.data[0]
      getWeather({ lat: lat, lon: lon});
    } catch (error) {
       console.log(error)
    }
};


const getWeather = (query) => {
axios.get('http://127.0.0.1:5000/weather', {
params: {
lat: query.lat,
lon: query.lon,
}
})
.then((response) => {
console.log(response)
state.temperature = Math.floor((response.data["main"]["temp"] - 273.15) * 1.8 +32);
// document.getElementById("cityTemp").innerHTML = state.temperature;
updateTemperatureDisplay(state.temperature);
})

.catch((error) => {
console.log(error)
})
};

const currentTempButton = () => {
// cityInput();
findCityLocation();
}

// const convertToF = (temperature) => {
// return Math.trunc((temperature-273.15) * 9 /5 + 32)
// }






// const findCityLocation = async (cityName) => {
// return axios.get('https://localhost:5000/location/weather', {
// params: {
// q: cityName,
// },
// })
// .then(response => {
// const temperature = response.data.temperature;
// updateTemperatureDisplay(temperature);
// console.log(temperature);
// })
// .catch(error => {
// console.log(error);
// });
// };


// const checkTempButton = document.getElementById('check-current-temp');
// checkTempButton.addEventListener('click', () => {
// const cityName = cityElement.value;
// findCityLocation(cityName);
// });

// const resetCity = () => {
// cityElement.value = '';
// // findCityLocation('Pittsburgh');
// };


// const refreshUI = () => {
// temperatureElement.textContent = state.temperature;
// };


// Event listeners for the buttons
increaseBtn.addEventListener('click', increaseTemperature);
decreaseBtn.addEventListener('click', decreaseTemperature);
resetCityButton.addEventListener('click', resetCityName);
checkCurrentTempElement.addEventListener('click', cityInput);

// Function to increase the temperature
function increaseTemperature() {
state.temperature++;
updateTemperatureDisplay(state.temperature);
// findCityLocation(cityElement.value);
}

// Function to decrease the temperature
function decreaseTemperature() {
state.temperature--;
updateTemperatureDisplay(state.temperature);
// findCityLocation(cityElement.value);
}

// Function to reset city name & clear input field
function resetCityName() {
cityElement.value = '';
cityInput();
}

// Function to update the temperature display, change the text color, and update the landscape
function updateTemperatureDisplay(temperature) {
temperatureElement.textContent = `${temperature}°F`;

if (temperature >= 80) {

Choose a reason for hiding this comment

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

I can tell you all had fun with this one LOL

temperatureElement.style.color = 'red';
emojiElement.textContent = '☀️🏝️🥵🌞☀️☀️🏝️🥵🌞☀️☀️🏝️🥵🌞☀️☀️🏝️🥵🌞☀️☀️🏝️🥵🌞☀️☀️🏝️🥵🌞☀️🏝️🥵🌞';
landscapeImg.src = 'styles/sunny1.jpeg';
landscapeImg.alt = 'Sunny';
} else if (temperature >= 70 && temperature <= 79) {
temperatureElement.style.color = 'grey';
emojiElement.textContent = '🌞😶‍🌫️🌼🌷😎🍂🌤️🌞😶‍🌫️🌼🌷😎🍂🌤️🌞😶‍🌫️🌼🌷😎🍂🌤️🌞😶‍🌫️🌼🌷😎🍂🌤️';
landscapeImg.src = 'styles/cloudy.jpeg';
landscapeImg.alt = 'Cloudy';
} else if (temperature >= 60 && temperature <= 69) {
temperatureElement.style.color = 'indigo';
emojiElement.textContent = '☁️🫥🌦️🌧️🌤️🌧️☔️🌈☁️🫥🌦️🌧️🌤️🌧️☔️🌈☁️🫥🌦️🌧️🌤️🌧️☔️🌈☁️🫥🌦️🌧️🌤️🌧️☔️🌈';
landscapeImg.src = 'styles/rainy.jpeg';
landscapeImg.alt = 'Rainy';
} else if (temperature >= 50 && temperature <= 59) {
temperatureElement.style.color = 'orange';
emojiElement.textContent = '🌤️🍁🥮⛅️🍂😎🍃🌤️🍁🥮⛅️🍂😎🍃🌤️🍁🥮⛅️🍂😎🍃🌤️🍁🥮⛅️🍂😎🍃🌤️';
landscapeImg.src = 'styles/autumn.jpeg';
landscapeImg.alt = 'Autumn';
} else {
temperatureElement.style.color = 'teal';
emojiElement.textContent = '❄️❄️☃️☃️⛄️⛄️🤶🏾🥶🥶🥶⛄️⛄️⛄️❄️❄️❄️❄️🌨️🌨️🌨️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️';
landscapeImg.src = 'styles/snowy.jpeg';
landscapeImg.alt = 'Snowy';
}
}

//function to return city input
function cityInput() {

Choose a reason for hiding this comment

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

Nice, I see you used the hoisting functionality of the function keyword! Make sure to think about readability, however!

let cityName = document.getElementById("city").value;
document.getElementById("cityChoice").innerHTML = cityName;
}
//function to update sky selection when there is a change
function skySelection() {
var choice = document.getElementById("sky").value;
updateSkyDisplay();
}

function updateSkyDisplay() {
let sky = document.getElementById("sky").value

if (sky == "sunny") {
skyEmojiElement.textContent = '🌞😎☀️☀🌼😎🌞😎☀️☀🌼😎🌞😎☀️☀🌼😎🌞😎☀️☀🌼😎🌞😎☀️☀🌼😎🌞😎☀️';

} else if (sky === "cloudy") {
skyEmojiElement.textContent = '☁️☁️ ☁️ ☁️☁️ ☁️🌤 ☁️ ☁️☁️☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️☁️☁️☁️☁️ ☁️ 🌤 ☁️☁️☁️☁️🌤';

} else if (sky === "rainy") {
skyEmojiElement.textContent = '🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️☔️🌈🌦️🌧️🌧️';

} else if (sky === "snowy") {
skyEmojiElement.textContent = '❄️❄️☃️☃️⛄️⛄️🤶🏾🥶🥶🥶⛄️⛄️⛄️❄️❄️❄️❄️🌨️🌨️🌨️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️🌨️☃️⛷️⛄️🤶🏾🥶❄️☃️❄️';
}

}

Choose a reason for hiding this comment

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

Awesome job everyone! You really ate this one up! Please feel free to reach out to me if you have any questions about the comments I left or if you want to discuss anything in greater detail! ⭐️

Binary file added styles/Diagram - Untitled.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/autumn.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/cloudy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
88 changes: 88 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
body {
font-family: 'Rubik', sans-serif;
margin: 0;
padding: 0;
background-color: rgba(194, 227, 232, 0.892);
}

header {
background-color: rgba(11, 31, 94, 0.906);
text-align: center;
color: rgb(255, 255, 255);
padding: 10px;
}

nav h1 {
color: rgb(255, 255, 255);
font-size: 25px;
}

#temperature-container {
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
margin-top: 20px;
padding: 5px;
}

#temperature {
margin: 20px;
}

button {
padding: 8px 16px;
font-size: 16px;
}

#emoji-container {
display: flex;
align-items: center;
justify-content: center;
padding: 2px;
}

#sky-emoji-container {
display: flex;
align-items: center;
justify-content: center;
padding: 2px;
}

#landscape-container {
display: flex;
justify-content: center;
align-items: center;
height: 400px;
overflow: hidden;
}

#landscape-img {
max-width: 700px;
max-height: 400px;
}

#sky-container {
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
padding: 5px;
}

#city-container {
display: flex;
align-items: center;
justify-content: center;
font-size: 24px;
padding: 5px;
}


footer {
background-color: rgb(40, 12, 181);
font-size: 25px;
padding: 10px;
text-align: center;
color: rgb(255, 255, 255);
}
Binary file added styles/rainy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/snowy.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/sunny1.jpeg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added styles/weather.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.