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

Heather M - Sea Turtles C17 #16

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
.DS_Store
node_modules
.cache
.cache
jsExample.js
58 changes: 56 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,64 @@
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="viewport" content="width=device-width, initial-scale=1.75">
<title>Weather Report</title>
<!-- Link to Style Sheet -->
<link href="styles/style.css" rel="stylesheet" />
</head>
<body>

<div id="weather_body">
<header>
<a id="site_title" href="index.html">
<p>~ current temperature in ~</p>
</a>
<nav>
<div><button id="search_location" alt="Search or Enter Location">⌖</button></div>
<input type="search" id="location_text" value="Denver" placeholder="location"></input>
<div><button id="refresh_weather" alt="Refresh">⇢</button></div>
</nav>
</header>
Copy link

Choose a reason for hiding this comment

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

looks good

<figure id="weather_display">
<text id="numeric_temperature">25</text>
<div id="units_div"><button id="temperature_units">°C</button></div>
</figure>
<figure id="change_temperature">
<button id="decrease"alt="Decrease Temperature">&nbsp;-&nbsp;</button>
<button id="reset"alt="Reset Temperature">⃔&nbsp;&nbsp;</button>
<button id="increase"alt="Increase Temperature">&nbsp;+&nbsp;</button>
</figure>
Comment on lines +23 to +31
Copy link

Choose a reason for hiding this comment

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

I was curious why you decided on the figure tag. Normally you would see it with an img tag so you could embed an image with a caption. You could also use it for diagrams or listing code. An example here: https://www.geeksforgeeks.org/html5-figure-tag/

Here is an example of a flowchart you could look at for guidance on what tags to use for that focus on semantic html:
html_flowchart

<div id="sky">
<select name="sky_selector" id="sky_selector">
<option value=""> --- sky --- </option>
<option value="sunny">sunny</option>
<option value="cloudy">cloudy</option>
<option value="rainy">rainy</option>
<option value="snowy">snowy</option>
</select>
</div>
<div id="sky_display" class="ascii_art">
Copy link

Choose a reason for hiding this comment

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

I like this different approach to the sky display and landscape display

<pre>
| : : : : : │
| : : : : : │
| : : : : : │
</pre>
</div>
<div id="landscape" class="ascii_art">
<pre>
Copy link

Choose a reason for hiding this comment

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

good use of pre tag to keep your sky/landscape formatted

┼┼┼│ │ ┼┼│
┼┼┼┼┐ ┼┼┼│
┼┼┼┼│ * │┼┼┼┼│
┼┼┼┼┘ * │ ┼┼┼│
┼ ├────┼ ───────│ ┼┼┼│
┼┼┼┼│┐┐┐┐┐┐┐┐ ├├├├├├├├├──│┼ ┼┼┼│
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼
********************************
********************************
********************************
</pre>
</div>
</div>
<script src="src/index.js"></script>
<script src="./node_modules/axios/dist/axios.min.js"></script>
</body>
</html>
229 changes: 229 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,229 @@
// import axios from 'axios';
// const axios = require('axios');

const state = {
temp: 25,
tempUnits: '°C',
city: 'Denver',
lat: 39.7392,
lon: -104.985,
sky: 'sunny',
};

const landscapes = {
cold: '-----cold-----\
I X I I I I I I I I I I\
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\
********************************',
cool: '***cool***',
neutral:
'\
----neutral-----\
┼┼┼│ │ ┼┼│\
┼┼┼┼┐ ┼┼┼│\
┼┼┼┼│ * │┼┼┼┼│\
┼┼┼┼┘ * │ ┼┼┼│\
┼ ├────┼ ───────│ ┼┼┼│\
┼┼┼┼│┐┐┐┐┐┐┐┐ ├├├├├├├├├──│┼ ┼┼┼│\
┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼┼\
********************************\
********************************\
********************************',
warm: '^^^^^^warm^^^^^^',
hot: '<<<<<hot>>>>>',
};

const skies = {
sunny:
'\
| : : : : : │\
| : : : : : │\
| : : : : : │',
cloudy:
'\
| : = : = : = : = : │\
| : = : = : = : = : = │\
| = : = : = : = : = : │',
rainy:
'\
| : :: : : : : : : : : │\
| : : : : : : : : : : │\
| : : : :: : :: : :: : │',
snowy:
'\
| * * * * * * * │\
| * * * * * * * * * *│\
| * * * * * * ** * │',
};

const convertFtoC = (temp) => {
return Math.round(((temp - 32) * 5) / 9);
};

const convertKtoC = (temp) => {
return Math.round(temp - 273.15);
};

const convertCtoF = (temp) => {
return Math.round(temp * (9 / 5) + 32);
};

const changeLandscapeTemp = () => {
let color = 'rgba(150, 50, 110, 0.5)';
let degC = 0.0;
let landscape = landscapes.neutral;

if (state.tempUnits === '°F') {
degC = convertFtoC(state.temp);
} else {
degC = state.temp;
}
if (degC > 30) {
landscape = landscapes.hot;
color = 'rgba(150, 90, 30, 0.5)';
} else if (degC > 25) {
landscape = landscapes.warm;
color = 'rgba(120, 60, 40, 0.5)';
} else if (degC > 15) {
landscape = landscapes.neutral;
color = 'rgba(100, 110, 10, 0.5)';
} else if (degC > 0) {
landscape = landscapes.cool;
color = 'rgba(80, 10, 110, 0.5)';
} else if (degC <= 0) {
landscape = landscapes.cold;
color = 'rgba(5, 5, 110, 0.5)';
}

let backgroundColors = `radial-gradient(${color}, rgba(0, 0, 0, 0))`;

const backgroundColor = document.getElementById('weather_body');
backgroundColor.style.backgroundImage = backgroundColors;

const landscapeReturn = document.getElementById('landscape');
landscapeReturn.textContent = landscape;

const tempContainer = document.querySelector('#numeric_temperature');
tempContainer.textContent = `${state.temp}`;

const unitsContainer = document.querySelector('#temperature_units');
unitsContainer.textContent = `${state.tempUnits}`;
};

const changeUnits = () => {
const currentUnits = state.tempUnits;
// document.getElementById('#temperature_units').textContent;
// state.tempUnits = currentUnits;
console.log('current units: ' + currentUnits);
Comment on lines +115 to +117
Copy link

Choose a reason for hiding this comment

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

you can remove your console log and commented code

if (currentUnits === '°C') {
state.temp = convertCtoF(state.temp);
state.tempUnits = '°F';
} else if (currentUnits === '°F') {
state.temp = convertFtoC(state.temp);
state.tempUnits = '°C';
}
changeLandscapeTemp();
};

const increaseTemp = () => {
state.temp += 1;
changeLandscapeTemp();
};

const reset = () => {
state.temp = 25;
state.tempUnits = '°C';
changeLandscapeTemp();
resetLocation();
};

const decreaseTemp = () => {
state.temp -= 1;
changeLandscapeTemp();
};

const searchLocation = () => {
axios
.get('http://localhost:5000/location', {
params: {
q: state.city,
},
})
.then((response) => {
console.log('success!' + JSON.stringify(response.data[0]));
state.lat = response.data[0].lat;
state.lon = response.data[0].lon;
searchTemperature();
})
.catch((error) => {
console.log('searchLocation error: ' + error.response);
});
};

const searchTemperature = () => {
axios
.get('http://localhost:5000/weather', {
params: {
lat: state.lat,
lon: state.lon,
},
})
.then((response) => {
console.log('success!' + JSON.stringify(response.data.current.temp));
state.temp = convertKtoC(response.data.current.temp);
changeLandscapeTemp();
})
.catch((error) => {
console.log('searchTemperature error: ' + error.response);
});
};

const changeCity = () => {
Copy link

Choose a reason for hiding this comment

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

When I am typing in the input it should change the city name. From wave 3:

  • A text input element that allows the user to change the city name
    You should have an event listener for input like
 const cityNameInput = document.getElementById('cityNameInput');
  cityNameInput.addEventListener('input', updateCityName);

const newCity = document.getElementById('location_text').value;
const cityDisplay = document.getElementById('location_text');
state.city = newCity;
cityDisplay.textContent = state.city;
};

const resetLocation = () => {
const locationInput = document.getElementById('location_text');
locationInput.value = 'Denver';
changeCity();
};

const changeSky = () => {
// const currentSky = state.sky;
const skyInput = document.getElementById('sky_selector');
const skyValue = skyInput.options[skyInput.selectedIndex].value;
console.log('sky_selector' + skyValue);
state.sky = skyValue;
const skyReturn = document.getElementById('sky_display');
skyReturn.textContent = skies[state.sky];
};

const registerEventHandlers = () => {
changeCity();
const changeLocationOnInput = document.querySelector('#location_text');
changeLocationOnInput.addEventListener('change', searchLocation);

changeCity();
const changeLocation = document.querySelector('#refresh_weather');
changeLocation.addEventListener('click', searchLocation);

const changeUnitsButton = document.querySelector('#temperature_units');
changeUnitsButton.addEventListener('click', changeUnits);

const increaseTempButton = document.querySelector('#increase');
increaseTempButton.addEventListener('click', increaseTemp);

const resetButton = document.querySelector('#reset');
resetButton.addEventListener('click', reset);

const decreaseTempButton = document.querySelector('#decrease');
decreaseTempButton.addEventListener('click', decreaseTemp);

const skySelector = document.querySelector('#sky_selector');
skySelector.addEventListener('change', changeSky);
};

document.addEventListener('DOMContentLoaded', registerEventHandlers);
Empty file removed styles/index.css
Empty file.
72 changes: 72 additions & 0 deletions styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
html {
font-size: min(max(2rem, 4vw), 30px);
padding: calc(8px + 1.5625vw);
text-align: center;
}

header {
padding: calc(8px + 1.5625vw);
}

nav {
display: flex;
align-items: center;
flex-direction: row;
column-gap: 1rem;
row-gap: 0rem;
justify-content: center;
}

figure {
flex-wrap: nowrap;
display: flex;
align-items: center;
flex-direction: row;
row-gap: 0rem;
margin-top: 0;
margin-bottom: 0;
justify-content: center;
flex: 25%;
}

#weather_body {
display: flex;
flex-direction: column;
align-items: center;
background-image:
radial-gradient(rgba(100, 110, 10, 0.5), rgba(0, 0, 0, 0));
}

.ascii_art {
font-family: monospace;
font-size: 0.5rem;
line-height: 0.5rem;
text-align: center;
max-width: 32ch;
text-overflow: clip;
}

#location_text {
font-weight: bold;
font-size: large;
text-align: center;
}


#weather_display {
display: flex;
}

#numeric_temperature {
font-size: 8rem;
line-height: 90%;
}

#units_div {
align-self: flex-start;
flex-shrink: 2;
}

#change_temperature {
gap: 1rem;
}