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

Phoenix-AnhTran , Sphinx-Tatiana-Snook #7

Open
wants to merge 27 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
e5193fe
create html, css files for the project
momofAnAl Dec 2, 2024
2a98557
Update click button for increase and decrease temp with changing colo…
momofAnAl Dec 2, 2024
a5c5594
update html and city name
momofAnAl Dec 2, 2024
216b525
update the city using helper function and set it back to original cit…
momofAnAl Dec 2, 2024
f9a2532
created helper function font color and landscape for updateTemperatur…
momofAnAl Dec 3, 2024
2b20710
update location and weather and connect with weather proxy server
momofAnAl Dec 3, 2024
90c188b
wave4 connection to proxy server
tatianasnook Dec 3, 2024
f7bc38e
wave4: displaying current temp
tatianasnook Dec 3, 2024
17c7a14
update the id name in getRealTime button and update the get city and …
momofAnAl Dec 3, 2024
0d321b3
Merge branch 'main' of https://github.com/momofAnAl/weather-report
momofAnAl Dec 3, 2024
1909956
remove the extra ) at line 71 in getCityTemperature function
momofAnAl Dec 3, 2024
4d239c3
wave 5
tatianasnook Dec 4, 2024
012a9f2
Update skyDisplay in weather Garden and addding skyOptions to change …
momofAnAl Dec 4, 2024
0a4cc58
Resolve conflict and accept the change in css,html and index.js
momofAnAl Dec 4, 2024
c03f30b
small changes to wave 5
tatianasnook Dec 4, 2024
6ade546
nothing was changed
momofAnAl Dec 4, 2024
32a1e4e
Merge branch 'main' of https://github.com/momofAnAl/weather-report
momofAnAl Dec 4, 2024
87c5141
change back to background color
momofAnAl Dec 4, 2024
5165003
update background change color
momofAnAl Dec 4, 2024
a4132eb
change the transition in CSS and update the url link for weather prox…
momofAnAl Dec 4, 2024
7efa5a3
update the local url for axios in main branch
momofAnAl Dec 4, 2024
ec14029
update the url with location and weather
momofAnAl Dec 4, 2024
399fb16
change the logic in realTimeButton, remove .then inside that button
momofAnAl Dec 4, 2024
4d3b572
Merge branch 'deployed-version'
momofAnAl Dec 4, 2024
fcc3718
Create helper function for both getlocation and get temperrature, upd…
momofAnAl Dec 4, 2024
aa8c0a9
update logic when we update the city , it also update the font color …
momofAnAl Dec 5, 2024
b445734
throw error to prevent executing undefined data
momofAnAl Dec 6, 2024
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
48 changes: 46 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,15 +1,59 @@
<!DOCTYPE html>
<html lang="en">

Choose a reason for hiding this comment

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

The spacing is being used for readability and separating different parts of the page, this is fine for me. Just be mindful that some developers might prefer for there to be no empty spaces.

<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles/index.css" />
<link rel="stylesheet" href="styles/index.css">
</head>

<body>
<header class="header__header">
<h1>Weather Report</h1>
<span>For the lovely city of
<span id="headerCityName" class="header__city-name">Seattle</span></span>
</header>
<section class="temperature__section">
<h2>Temperature</h2>
<div class="temperature__content">
<div class="temperature__controls">
<span id="increaseTempControl">⬆️</span>
<span id="tempValue"></span>
<span id="decreaseTempControl">⬇️</span>
</div>
<button id="getRealTimeTempButton">Get Realtime Temperature</button>
</div>

</section>
<section class="sky__section">
<h2>Sky</h2>
<select id="skySelect">
<option value="sunny">Sunny</option>
<option value="cloudy">Cloudy</option>
<option value="rainy">Rainy</option>
<option value="snowy">Snowy</option>
</select>

</section>

<section class="city-name__section">
<h2>City Name</h2>
<input type="text" id="cityNameInput">
<button id="cityNameReset" class="city-name__reset-btn">Reset</button>
</section>

<section class="garden__section">
<h2>Weather Garden</h2>
<div id="gardenContent" class="garden__content">
<div id="skyDisplay">☁️ ☁️ ☁️ ☀️ ☁️ ☁️</div>
<div id="landscape"></div>
</div>
</section>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<script src="./src/index.js"></script>
</body>
</html>
</html>
145 changes: 145 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
let temperature = 48;

const tempValue = document.getElementById('tempValue');
Comment on lines +1 to +3

Choose a reason for hiding this comment

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

Nice work on appropriately using the let and const keywords!

const increaseTempControl = document.getElementById('increaseTempControl');
const decreaseTempControl = document.getElementById('decreaseTempControl');
const landScape = document.getElementById('landscape');
const cityNameInput = document.getElementById('cityNameInput');
const cityNameReset = document.getElementById('cityNameReset');
const headerCityName = document.getElementById('headerCityName');
const getRealTimeTempButton = document.getElementById('getRealTimeTempButton');
Comment on lines +4 to +10

Choose a reason for hiding this comment

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

Looks like we are doing similar logic in a few places (finding an element by id and then, later in our code, adding an event handler to it for a specific event). Do you think that this could call for a helper function to make our code a bit more DRY?


//Update the sky options when we choose different sky and change the color background in garden
const skyOptions = {
'sunny': {
'text': "☁️ ☁️ ☁️ ☀️ ☁️ ☁️",
'backgroundColor': "#DFFFFF",
},
'cloudy': {
'text': "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️",
'backgroundColor': "#D3D3D3",
},
'rainy': {
'text': "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧",
'backgroundColor': "#B0C3DF",
},
'snowy': {
'text': "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨",
'backgroundColor': "#ADD9E6",
},
};
Comment on lines +13 to +30

Choose a reason for hiding this comment

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

Nice way of storing these! You could even put them in another file and just import them to better declutter your code!

const skySelect = document.getElementById("skySelect");
const skyDisplay = document.getElementById("skyDisplay")
const gardenContent = document.getElementById("gardenContent")

skySelect.addEventListener("change", (event) => {
const skySelected = event.target.value;
console.log("Selected sky:", skySelected);
updateSky(skySelected);
});
Comment on lines +31 to +39

Choose a reason for hiding this comment

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

A few things here:

  • The event handler I would put in its own function that why it would be easier to read as well as maintain.
  • I would just moving the logic of adding event handlers to their respective HTML elements into something like document.addEventListener("DOMContentLoaded", RegisterEventHandlers);. That way we register the event handler functions to run when the DOM content has fully loaded. This ensures all HTML elements and resources are available before attempting to attach event handlers or manipulate the DOM.
  • Don't forget to remove console logs like this, you could accidentally leak private data. Also just helps to keep the code clutter free.


const updateSky = (sky) => {
const skySelectOption = skyOptions[sky]
console.log(skySelectOption)
if (skySelectOption) {
skyDisplay.textContent = skySelectOption.text;
gardenContent.style.backgroundColor = skySelectOption.backgroundColor;
}
};

//Update the temperature and change font color and landscape when increase and decrease temperature
const updateTemperature = () => {
tempValue.textContent = `${temperature}°F`;
tempValue.style.color = getFontColor(temperature);
landScape.textContent = getLandscape(temperature);
};

const getLandscape = (temp) => {
if (temp <= 59) return '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲';
if (temp <= 69) return '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃';
if (temp <= 79) return '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷';
return '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂';
};

const getFontColor = (temp) => {
if (temp <= 49) return 'teal';
if (temp <= 59) return 'green';
if (temp <= 69) return 'yellow';
if (temp <= 79) return 'orange';
return 'red';
};
Comment on lines +57 to +70

Choose a reason for hiding this comment

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

To make this a little more concise and avoid the multiple if statements we could use a loop and a list to do something like this instead:

const temperatureRanges = [
  { min: 80, color: "red", landscape: "🌵  🐍 🦂 🌵🌵  🐍 🏜 🦂" },
  { min: 70, color: "orange", landscape: "🌸🌿🌼  🌷🌻🌿 ☘️🌱 🌻🌷" },
  { min: 60, color: "salmon", landscape: "🌾🌾 🍃 🪨  🛤 🌾🌾🌾 🍃" },
  { min: 50, color: "green", landscape: "🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲" },
  { min: -Infinity, color: "blue", landscape: "⛄️ ⛄️ ⛄️" }, // Default for temperatures <= 49
];

for (const range of temperatureRanges) {
  if (state.currentTemp >= range.min) {
    tempValueElement.style.color = range.color;
    landscapeElement.textContent = range.landscape;
    break; // Stop once the matching range is found
  }
}

You do, however, lose some readability. Mainly because the person would need to realize that it utilizes the order retention of a list. Which one do you think you gravitate to and why?


increaseTempControl.addEventListener('click', () => {
temperature += 1;
updateTemperature();
});

decreaseTempControl.addEventListener('click', () => {
temperature -= 1;
updateTemperature();
});
updateTemperature();

//getRealTimeTemp button updates the temperature when we update the city
getRealTimeTempButton.addEventListener('click', () => {
const city = headerCityName.textContent;

getCityLocation (city)
.then(({ lat, lon }) => {
return getCityTemperature(lat,lon);

Choose a reason for hiding this comment

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

I don't think you actually need to return this since you aren't chaining it to anything else.

})
.catch((error) => {
console.log('Error data:', error);
tempValue.textContent = 'Unable to get temperature';
})
Comment on lines +85 to +94

Choose a reason for hiding this comment

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

I would also suggest moving this into its own function(s), things could get tricky to debug (especially working with chained promises inside of callback functions.

});

const getCityLocation = (city) => {
return axios
.get('https://ada-weather-report-proxy-server.onrender.com/location', {params:{'q': city}})
.then((locationResponse) => {
console.log(locationResponse);
const lat = locationResponse.data[0].lat;
const lon = locationResponse.data[0].lon;
console.log({ lat, lon });
return { lat, lon };
})
.catch((error) => {
console.log('Error data:', error);
throw error
});
};
Comment on lines +97 to +111

Choose a reason for hiding this comment

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

Nice work on this function!


const getCityTemperature = (lat, lon) => {
return axios
.get('https://ada-weather-report-proxy-server.onrender.com/weather', {params:{"lat": lat, "lon": lon}})
.then((tempResponse) => {
const kelvinTemp = tempResponse.data.main.temp;
const fahrenheitTemp = Math.floor(((kelvinTemp - 273.15) * 9) / 5 + 32);
tempValue.textContent = `${fahrenheitTemp}°F`;
tempValue.style.color = getFontColor(fahrenheitTemp);
landScape.textContent = getLandscape(fahrenheitTemp);
Comment on lines +119 to +121

Choose a reason for hiding this comment

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

If we restructured our code to use the state object that was talked about inside of the reading we could actually move this logic into their respective functions. This would help with SRP and make our code easier to debug and maintain. Essentially, we would just replace the code here with something like state.temp = tempResponse.data.main.temp; and then we could just call our functions that handle updating our UI. In those functions we could have something like tempValue.textContent = ${state.temp}°F;.

})
.catch((error) => {
console.log('Error data:', error);
throw error
});
};

//Update the city name when we input the city and headerCityName got update
//When we click reset, it comes back to our default setting
const updateCityName = (updateCity) => {
headerCityName.textContent = updateCity;
};

cityNameInput.addEventListener('input', (event) => {
updateCityName(event.target.value);
});

cityNameReset.addEventListener('click', () => {
cityNameInput.value = '';
updateCityName('Seattle');
});
Comment on lines +135 to +142

Choose a reason for hiding this comment

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

These could also be moved into the document.addEventListener callback that I mentioned above.




164 changes: 164 additions & 0 deletions styles/index.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
h2 {
margin: 0 auto 2rem auto;
}

body {
display: grid;
grid-template-columns: 1fr 2fr;
grid-template-rows: auto auto auto auto;
grid-gap: 1rem;

font-family: "Rubik", sans-serif;
font-size: 18px;
background-color: #1b69f9;
margin: 2rem;
}

.header__header {
color: white;
grid-column: span 3;
display: flex;
align-items: center;
margin: 2rem auto 3rem 0;
}

.header__header > h1 {
margin-right: 2rem;
font-size: 3em;
}

.header__city-name {
font-style: oblique;
font-size: 2rem;
}

.header__city-name::before,
.header__city-name::after {
content: "✨";
}

.temperature__section,
.sky__section,
.city-name__section {
border-radius: 8px;
padding: 2rem;
background-color: white;
}

.temperature__section {
grid-row: 2;
}

.temperature__section button {
background-color: #1b69f9;
border: none;
color: white;
padding: 15px 32px;
text-align: center;
text-decoration: none;
display: inline-block;
font-size: 16px;
border-radius: 10px
}

.sky__section {
grid-row: 3;
}

.city-name__section {
grid-row: 4;
}

.garden__section {
grid-row: 2 / span 3;
grid-column: 2;
text-align: center;
align-self: center;
}

.temperature__content {
display: flex;
flex-direction: row;
justify-content: space-around;
/* justify-content: center; */
}

#tempValue {
font-size: 3rem;
margin-left: 1.5rem;
/* padding-right: 1rem; */
/* margin-right: 1.5rem; */
}

.temperature__controls {
display: flex;
flex-direction: column;
align-items: center;
}

.garden__section > h2 {
color: white;
}

.garden__content {
min-height: 200px;
max-width: fit-content;
margin: auto;
padding: 2rem;
display: flex;
flex-direction: column;
justify-content: space-between;
border-radius: 8px;
font-size: 2em;
background-color: #DFFFFF;
transition: background-color 0.5s;
}

.city-name__reset-btn {
border: 0;
background-color: #1655cc;
color: white;
border-radius: 8px;
padding: 1rem;
font-family: "Rubik", sans-serif;
}

.red {
color: red;
}

.orange {
color: orange;
}

.yellow {
color: gold;
}

.yellow-green {
color: yellowgreen;
}

.green {
color: green;
}

.teal {
color: teal;
}

.cloudy {
background-color: lightgrey;
}

.sunny {
background-color: rgb(221, 255, 255);
}

.rainy {
background-color: lightblue;
}

.snowy {
background-color: lightsteelblue;
}