Skip to content

PR _ Elsje and Bukunmi SL#80

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

PR _ Elsje and Bukunmi SL#80
bukunmig wants to merge 40 commits intoAda-C18:mainfrom
elsjeslothower:main

Conversation

@bukunmig
Copy link
Copy Markdown

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.

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

Comment thread styles/index.css
Comment on lines +4 to +5
--primaryColor: #0066FF;
--lightColor: #abaed3;
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 CSS vars

Comment thread styles/index.css
Comment on lines +37 to +40
grid-template-areas:
"a b c"
"a b c"
"a b c";
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

These template areas don't appear to be used in the rest of your css. To make use of the template areas, there would need to be corresponding grid-area properties set on various classes that the browser would use to match them up to the appropriate template area.

Instead, it's the grid-template-columns a few lines down that's doing the work here.

Comment thread index.html
<span id="currentCity">Seattle</span>
</div>
<div>
<h2 class="interactive">To view the precise temp in {city}, click here:</h2>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Looks like you intended to fill in the city name in this message.

Comment thread index.html

<main class="container">
<!-- column a -->
<section class="a">
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

You don't have a class called a in your styles. I'm assuming this was intended to associate this content with the first column in the grid. It turns out that the grid-template-columns setting simply takes the child elements in order, assigning them to the columns in order.

Comment thread index.html
<section class="c">
<div>
<h2>Current temperature is:</h2>
<span id="displayedTemp">72</span>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than hard-coding a value for UI elements (which just happens to match the initial value backing the control), I like to leave the initial markup blank, and update the UI on first load from the initial backing values in the JS code. So like here, leave off the 72, then when the document loads, update the UI in the JS to show the initial temperature value. This would protect us from changing the default starting JS value, but having it be out of sync with what the UI is showing.

I would tend to do this for any of the configurable elements (temperature, ground, sky, city).

Comment thread src/index.js
Comment on lines +115 to +116
lat: state.lat,
lon: state.lon,
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 app doesn't need to track the lat/lon over time. It's only used during the chained city/weather call. So rather than stashing those values in the state, consider making the lat and lon input parameters to this function.

Comment thread src/index.js
const toFahrenheit = (k) => (k - 273.15) * (9 / 5) + 32;

const getWeather = () => {
axios
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We should always return any promise chains we create in helper functions (axios.get starts a promise chain) so that additional actions could be chained onto the end after the function logic completes.

  return axios.get(...).then(...)

Comment thread src/index.js
Comment on lines +122 to +125
state.temp = cityTemp
console.log("success!!", response.status);
tempChange();
landscapeChange();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than stashing the temperature result directly in the application state here, consider returning the temperature from the .then callback. This would make it available to a subsequent .then callback that could be chained outside this helper. In that case, we also need to be sure to return the end of the promise chain itself from the helper, so that additional actions can be chained to run after this helper completes.

Comment thread src/index.js

const getLatAndLon = () => {
let lat, lon;
axios
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 return here as mentioned above.

Comment thread src/index.js
Comment on lines +146 to +148
state.lat = lat;
state.lon = lon;
getWeather();
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Rather than stashing the lat/lon and then calling the weather api call directly, consider returning the lat/lon from this .then callback so that it would be available to act as the input to a subsequent .then callback. We could then make a separate function whose responsibility is to combine the city->lat/lon function with the lat/lon->weather function.

Assuming getLatAndLon was a function taking a city name and returning a promise to an object shaped like {lat: 0, lon: 0}, and getWeather was a function taking lat and lon values, and returning a promise to a temperature, we could write a third function getWeatherForCity as follows:

const getWeatherForCity = (cityName) => {
  return getLatAndLon(cityName)
    .then(({lat, lon}) => {
      return getWeather(lat, lon);
    })
};

We could then use this as

getWeatherForCity(state.city)
  .then(temp => {
      // code that was in getWeather above
      state.temp = temp;
      console.log("success!!", response.status);
      tempChange();
      landscapeChange();
  })

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