Skip to content

Stephanie/Crows and Olga/Possums Weather App#5

Open
Olga-allgood wants to merge 11 commits into
Ada-C24:mainfrom
Olga-allgood:deployed-version
Open

Stephanie/Crows and Olga/Possums Weather App#5
Olga-allgood wants to merge 11 commits into
Ada-C24:mainfrom
Olga-allgood:deployed-version

Conversation

@Olga-allgood

Copy link
Copy Markdown

No description provided.

@anselrognlie anselrognlie left a comment

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 good overall, but please review my comments, and let me know if you have any questions.

Comment thread src/index.js
updateDisplay();
};

onLoaded();

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Since this script is set to run defered, it should be OK to call onLoaded directly like this and have reasonable certainty that the page elements will have been loaded. Still, consider registering this to run with the DOMContentLoaded event.

Comment thread src/index.js


const loadControls = () => {
state.temperatureDisplay = document.getElementById('tempValue');

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 to load any of the elements I'll be using just once, and then access them later on. Doing so avoids possible typos in the string values used in the lookup value.

Comment thread src/index.js

};

const changeSky = () => {

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 function updates the sky display, but it doesn't get called until the sky picker changes, meaning no sky is shown when the page loads.

Comment thread src/index.js
@@ -0,0 +1,243 @@
const state = {
currentTemperature: 50,
currentLandscape: '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲',

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 landscape is being calculated from the temperature further down. currentLandscape doesn't appear to be used and can be removed. Looking it up as needed (as you did) is the preferred approach.

Comment thread src/index.js
const state = {
currentTemperature: 50,
currentLandscape: '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲',
currentWeatherState: 4,

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 currentWeatherState is also calculated from the temperature. Rather than storing it as a separate value, it could be calculated from the current temperature as needed. If we can calculate one value from another (think back to calculating is_complete from completed_at in Task List API), we should try to avoid storing the dependent data.

Comment thread src/index.js
Comment on lines +106 to +108
if (state.temperatureColor) {
state.temperatureDisplay.classList.remove(state.temperatureColor);
}

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 needing to track the previous class in order to remove it, we can either

  1. Attempt to remove all possible classes (fine for a small number of classes)
  for (const colorClass of Object.values(COLOR_STATES))
    state.temperatureDisplay.classList.remove(colorClass);
  }

or 2. Since the page structure is set up so that the temperture element should only ever have a single class applied, use the className property instead to replace the class with the new one. Sometimes the element structure needs to be adjusted to accomodate this if there may need to be other structural classes applied, but here, that's not a concern.

  state.temperatureDisplay.className = COLOR_STATES[state.currentWeatherState];

Ideally, as noted below, rather than storing the currentWeatherState, we could just compute it from the temperature.

Comment thread src/index.js
Comment on lines +120 to +126
const LANDSCAPE_STATES = {
1: '🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂',
2: '🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷',
3: '🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃',
4: '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲',
5: '🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲'
};

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

As with the color, we could give these buckets more meaningful names.

Comment thread index.html
Comment on lines +36 to +39
<option>Sunny</option>
<option>Cloudy</option>
<option>Rainy</option>
<option>Snowy</option>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

options allow us to set a value so that the JS value we read from the control can be set independent of the values being displayed. This can allow us to pick values that better match logic we're running (such as matching the names of the CSS classes we want to assign).

We could likewise just pick some arbitrary set of ids, and establish the mapping to the CSS class similar to how we can pick a string of emoji.

            <option value="sunny">Sunny</option>
            <option value="cloudy">Cloudy</option>
            <option value="rainy">Rainy</option>
            <option value="snowy">Snowy</option>

Comment thread src/index.js
Snowy: '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨',
};

const selected = state.skySelector.value;

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 reading the current sky value directly from the sky picker, consider having an event handle that stores the current value into the state, and then separate the logic that updates the UI to read the current sky from the state.

Comment thread src/index.js
Comment on lines +186 to +187
state.cityNameDisplay.textContent = state.updatedCityName.value;
state.headerCityName.textContent = state.updatedCityName.value;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to my recommendation for the sky, rather than updating the UI directly from the control value, have one function that responds to the change events and updates state, and another that updates the UI based on the current state.

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