Skip to content

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

Open
cbcodee wants to merge 40 commits intoAda-C18:mainfrom
cbcodee:main
Open

SL c18- Cristal B. & Diana S.#77
cbcodee wants to merge 40 commits intoAda-C18:mainfrom
cbcodee:main

Conversation

@cbcodee
Copy link
Copy Markdown

@cbcodee cbcodee commented Dec 12, 2022

No description provided.

Copy link
Copy Markdown

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

Comment thread styles/index.css
@@ -0,0 +1,75 @@

* {
box-sizing: border-box;
Copy link
Copy Markdown

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.

Comment thread styles/index.css

body {
/* margin: 0; */
display: flex;
Copy link
Copy Markdown

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.

Comment thread index.html

<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>
Copy link
Copy Markdown

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.

Comment thread index.html
<span id="down"><button>🔽</button></span>
<button id="currentWeather">Get real time weather</button>
</div>
</div>
Copy link
Copy Markdown

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.

Comment thread index.html
@@ -1,12 +1,59 @@

Copy link
Copy Markdown

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 thread src/index.js
Comment on lines +70 to +71
state.city = newCity;
displayCity();
Copy link
Copy Markdown

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.

Comment thread src/index.js
const resetText = () => {
const newCity = document.getElementById('newCity');
newCity.value = 'Seattle';
updateCity();
Copy link
Copy Markdown

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.

Comment thread src/index.js
const displayEmojis = () => {
let numColor = 'red';
let emojisBelow = '🌵__🐍_🦂_🌵🌴__🐍_🏜_🦂';
if (state.temp > 80) {
Copy link
Copy Markdown

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?

Comment thread src/index.js
newEmojis.textContent = emojisBelow;

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

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.

Comment thread src/index.js
temperature.textContent = String(state.temp);
};

const updateSky = () => {
Copy link
Copy Markdown

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