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

SL c18- Cristal B. & Diana S. #77

Open
wants to merge 40 commits into
base: main
Choose a base branch
from
Open

SL c18- Cristal B. & Diana S. #77

wants to merge 40 commits into from

Conversation

cbcodee
Copy link

@cbcodee cbcodee commented Dec 12, 2022

No description provided.

Copy link

@anselrognlie anselrognlie left a comment

Choose a reason for hiding this comment

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

Looking good. Try to think about how to refactor the API call helpers so that they're a little more independent and reusable. I have some suggestions in the comments. There's also quite a bit of code based on similar if/else if statements that we could think about making more data-driven, simplifying our code, and reducing the likelihood of typos, so check my comments for more details. And rather than having element lookup and event registration code scattered throughout the script, prefer to group related operations together, and register them to run on page load with the DOMContentLoaded event.

@@ -0,0 +1,75 @@

* {
box-sizing: border-box;

Choose a reason for hiding this comment

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

👍 border-box breaks my brain much less than the default content-box rules.


body {
/* margin: 0; */
display: flex;

Choose a reason for hiding this comment

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

Nice use of flex along with specified element widths to achieve your four-square layout.


<h1 id="change-city" class="diff-city">🌳 Weather for the City of <span id="cityInput">Seattle</span> 🍃</h1>

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

Choose a reason for hiding this comment

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

Prefer to keep you script imports together. We should put this down by the script tag importing our index.js.

<span id="down"><button>🔽</button></span>
<button id="currentWeather">Get real time weather</button>
</div>
</div>

Choose a reason for hiding this comment

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

This is an extra closing div which breaks validation.

@@ -1,12 +1,59 @@

Choose a reason for hiding this comment

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

Be sure to validate your html when possible. The errors/warnings can help us write cleaner HTML. Even if our markup looks fine in the browser we're using, there's no guarantee invalid HTML will do so on other browsers, and it could even break in the same browser since there are no layout guarantees made for invalid HTML.

Comment on lines +70 to +71
state.city = newCity;
displayCity();

Choose a reason for hiding this comment

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

I like how this is set up to update the state value for the city, and then use the displayCity function, whose responsibility is to update the UI to reflect the current city state. Consider extracting these lines into a helper setCity(newCity) that you could also use in the reset handler.

const resetText = () => {
const newCity = document.getElementById('newCity');
newCity.value = 'Seattle';
updateCity();

Choose a reason for hiding this comment

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

updateCity expects to be registered as an event handler (it has a parameter to receive event details). Calling it here without event information leads to an error when trying to update the city in the UI. If we had a setCity helper as described above, we could use that instead, passing in the reset default city value.

const displayEmojis = () => {
let numColor = 'red';
let emojisBelow = '🌵__🐍_🦂_🌵🌴__🐍_🏜_🦂';
if (state.temp > 80) {

Choose a reason for hiding this comment

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

Notice the repetition in these if/else if blocks. Code like this tends to be finicky, since humans tend to make easily overlooked typos that can be hard to track down. Consider a data structure and accompanying code similar to the following:

const tempColors = [
  [80, {ground: 'ground emojis', color: 'temp color'}],
  [70, {ground: 'ground emojis', color: 'temp color'}],
  [60, {ground: 'ground emojis', color: 'temp color'}],
  [50, {ground: 'ground emojis', color: 'temp color'}],
  [null, {ground: 'ground emojis', color: 'temp color'}],
];

const getSettingsForTemp = (temp) => {
  for (const [boundaryTemp, tempSettings] of tempColors) {
    if (boundaryTemp === null || temp > boundaryTemp) {
      return tempSettings;
    }
  }
};

Looking for repetition in the structure of our code and refactoring it to be captured in a data structure instead can make our code more flexible (behavior can be changed solely by changing data) while simplifying the code working with the data.

If we had this function, how could we simplify the logic here in displayEmojis?

newEmojis.textContent = emojisBelow;

const temperature = document.getElementById('tempNum');
temperature.className = numColor;

Choose a reason for hiding this comment

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

Nice approach of setting a css class with the style details rather than setting the style properties in the code here itself.

temperature.textContent = String(state.temp);
};

const updateSky = () => {

Choose a reason for hiding this comment

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

The comments about splitting the function responsibility for temp/color would also apply to the sky function here. To think about how we could make this more data-driven, consider what changes we might make to this function if we had a data structure resembling:

const skySettings = {
  clouds: 'clouds emoji',
  sunshine: 'sunshine emoji',
  rain: 'rain emoji',
  snow: 'snow emoji',
  wind: 'wind emoji',
};

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