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

Conversation

momofAnAl
Copy link

No description provided.

momofAnAl and others added 27 commits December 2, 2024 13:42
…e, change value to empty string whenever click the Reset button for City
…location in order to get the weather, and try to convert to F from Kelvin
…ate the gerrealtimetemperraturebutton to return the temperature in city with lat and lon provided
Copy link

@mikellewade mikellewade left a comment

Choose a reason for hiding this comment

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

Nice work! Please let me know if there are any questions about the comments made.

@@ -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.

Comment on lines +1 to +3
let temperature = 48;

const tempValue = document.getElementById('tempValue');

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!

Comment on lines +4 to +10
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');

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?

Comment on lines +13 to +30
const skyOptions = {
'sunny': {
'text': "☁️ ☁️ ☁️ ☀️ ☁️ ☁️",
'backgroundColor': "#DFFFFF",
},
'cloudy': {
'text': "☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️",
'backgroundColor': "#D3D3D3",
},
'rainy': {
'text': "🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧",
'backgroundColor': "#B0C3DF",
},
'snowy': {
'text': "🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨",
'backgroundColor': "#ADD9E6",
},
};

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!

Comment on lines +31 to +39
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);
});

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.

Comment on lines +85 to +94
const city = headerCityName.textContent;

getCityLocation (city)
.then(({ lat, lon }) => {
return getCityTemperature(lat,lon);
})
.catch((error) => {
console.log('Error data:', error);
tempValue.textContent = 'Unable to get temperature';
})

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.


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.

Comment on lines +97 to +111
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
});
};

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!

Comment on lines +119 to +121
tempValue.textContent = `${fahrenheitTemp}°F`;
tempValue.style.color = getFontColor(fahrenheitTemp);
landScape.textContent = getLandscape(fahrenheitTemp);

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;.

Comment on lines +135 to +142
cityNameInput.addEventListener('input', (event) => {
updateCityName(event.target.value);
});

cityNameReset.addEventListener('click', () => {
cityNameInput.value = '';
updateCityName('Seattle');
});

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants