-
Notifications
You must be signed in to change notification settings - Fork 88
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
Jamie Horvath C-17 Digital Sharks #87
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
'use strict'; | ||
// const axios = require('axios'); | ||
|
||
const state = { | ||
location: '', | ||
temp: 70, | ||
weather: '', | ||
lat: 0, | ||
lon: 0, | ||
}; | ||
Comment on lines
+4
to
+10
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const getTemp = () => { | ||
axios | ||
.get('http://localhost:5000/weather', { | ||
params: { | ||
lat: state.lat, | ||
lon: state.lon, | ||
}, | ||
}) | ||
.then((response) => { | ||
state.temp = parseInt( | ||
((response.data['current'].temp - 273) * 9) / 5 + 32 | ||
); | ||
state.weather = response.data['current']['weather'][0].main; | ||
console.log('success in finding weather!', state.temp, state.weather); | ||
tempChange(state.temp, true); | ||
}) | ||
.catch((error) => { | ||
console.log('error in weather'); | ||
}); | ||
return state.temp; | ||
}; | ||
Comment on lines
+12
to
+32
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const tempToColor = () => { | ||
let newTemp = state.temp; | ||
//I became aware after the fact I could set 'hsl()' | ||
const toHex = (dec) => (dec < 16 ? '0' + dec.toString(16) : dec.toString(16)); | ||
const normalize = (newTemp) => (newTemp % 35) / 35; | ||
Comment on lines
+37
to
+38
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. LOVE this formula to generate the temp color!!! |
||
|
||
let color = []; | ||
if (newTemp <= -35) { | ||
color = ['00', '00', 'FF']; | ||
} else if (newTemp < 0) { | ||
color = ['00', toHex(parseInt(255 * (1 + normalize(newTemp)))), 'FF']; | ||
} else if (newTemp < 35) { | ||
color = ['00', 'FF', toHex(parseInt(255 * (1 - normalize(newTemp))))]; | ||
} else if (newTemp < 70) { | ||
color = [toHex(parseInt(255 * normalize(newTemp))), 'FF', '00']; | ||
} else if (newTemp < 105) { | ||
color = ['FF', toHex(parseInt(255 * (1 - normalize(newTemp)))), '00']; | ||
} else { | ||
color = ['FF', '00', '00']; | ||
} | ||
return ['#', ...color].join(''); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Clever! |
||
}; | ||
|
||
const tempChange = (temp, set) => { | ||
const currentTemp = document.querySelector('#temp'); | ||
if (set) { | ||
currentTemp.textContent = temp; | ||
} else { | ||
state.temp += temp; | ||
currentTemp.textContent = state.temp; | ||
} | ||
currentTemp.style.color = tempToColor(); | ||
|
||
seasonChange(); | ||
}; | ||
Comment on lines
+57
to
+68
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const seasonChange = () => { | ||
const currentSeason = document.querySelector('#season'); | ||
if (state.temp < 30) { | ||
season = '🌲🌲⛄️🍂🍁🌲⛄️🍂🌲'; | ||
} else if (state.temp < 60) { | ||
season = '🌾_🍃_🪨__🛤_🌾_🍃'; | ||
} else if (state.temp < 90) { | ||
season = '🌸🌿_🌱_🌻🌷_🌼__🌷'; | ||
} else { | ||
season = '🌵_🐍🌵__🐍_🏜_🦂🌵'; | ||
} | ||
currentSeason.textContent = season; | ||
}; | ||
Comment on lines
+70
to
+82
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const weatherChange = () => { | ||
const currentWeather = document.querySelector('#weatherBox'); | ||
const setWeather = document.querySelector('#weather'); | ||
let weatherLookup = { | ||
Sunny: '☁️ ☁️ ☁️ ☀️ ☁️ ☁️', | ||
Cloudy: '☁️☁️ ☁️ ☁️☁️ ☁️ 🌤 ☁️ ☁️☁️', | ||
Rainy: '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧', | ||
Snowy: '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨', | ||
}; | ||
|
||
state.weather = currentWeather.value; | ||
|
||
setWeather.textContent = weatherLookup[state.weather]; | ||
}; | ||
Comment on lines
+84
to
+97
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
///////////////////////////////////////////// | ||
const getLocation = () => { | ||
print; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think you need htis line. |
||
axios | ||
.get('http://localhost:5000/location', { | ||
params: { | ||
q: state.location, | ||
}, | ||
}) | ||
.then((response) => { | ||
state.lat = response.data[0].lat; | ||
state.lon = response.data[0].lon; | ||
console.log('success in finding location!', state.lat, state.lon); | ||
}) | ||
.catch((error) => { | ||
console.log('error in location'); | ||
Comment on lines
+110
to
+113
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good job in error handling and utilizing logs to confirm the behavior of your |
||
}); | ||
return {}; | ||
}; | ||
|
||
const locationChange = () => { | ||
const currentLocation = document.querySelector('#location'); | ||
const locationButton = document.querySelector('#locationReset'); | ||
|
||
state.location = currentLocation.value; | ||
getLocation(); | ||
locationButton.textContent = state.location; | ||
currentLocation.value = ''; | ||
}; | ||
Comment on lines
+118
to
+126
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const clearLocation = () => { | ||
const locationButton = document.querySelector('#locationReset'); | ||
locationButton.textContent = 'Reset Location'; | ||
state.location = ''; | ||
state.lat = 0; | ||
state.lon = 0; | ||
}; | ||
Comment on lines
+128
to
+134
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
const registerEventHandlers = () => { | ||
const upTempButton = document.querySelector('#up_temp'); | ||
upTempButton.addEventListener('click', (event) => tempChange(1, false)); | ||
const downTempButton = document.querySelector('#down_temp'); | ||
downTempButton.addEventListener('click', (event) => tempChange(-1, false)); | ||
const setTempButton = document.querySelector('#lookup_temp'); | ||
setTempButton.addEventListener('click', (event) => getTemp()); | ||
|
||
const updateLocation = document.querySelector('#location'); | ||
updateLocation.addEventListener('change', (event) => locationChange()); | ||
const updateWeather = document.querySelector('#weatherBox'); | ||
updateWeather.addEventListener('change', (event) => weatherChange()); | ||
|
||
const locationResetButton = document.querySelector('#locationReset'); | ||
locationResetButton.addEventListener('click', (event) => clearLocation()); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); | ||
tempChange(0, false); | ||
Comment on lines
+136
to
+154
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
body{ | ||
width: 100vw; | ||
height: 100vh; | ||
margin: 0%; | ||
font-size: 4vw; | ||
background-image: linear-gradient(190deg, #f67f2f, #49b8fe); | ||
background-size: cover; | ||
background-repeat: no-repeat; | ||
background-attachment: fixed; | ||
display:flex; | ||
flex-direction:column; | ||
/* justify-content: center; */ | ||
align-items: center; | ||
} | ||
.container { | ||
border-radius: .5em; | ||
width: 10em; | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
background-color: rgb(0, 255, 255); | ||
} | ||
#locationReset{ | ||
width: auto; | ||
} | ||
#location { | ||
margin: 0%; | ||
font-size: .5em; | ||
} | ||
.h_buttons { | ||
display: flex; | ||
justify-content: space-around; | ||
width: 100%; | ||
} | ||
.h_buttons div{ | ||
border-radius: 1px; | ||
box-shadow: 0px 0px 3px 1px white; | ||
|
||
width: 25%; | ||
text-align: center; | ||
} | ||
|
||
#temp { | ||
margin: 0%; | ||
font-size: 6em; | ||
text-align: center; | ||
} | ||
|
||
#weather { | ||
font-size:.5em; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These are great notes, however, the intended use of PRs is to share code that we'd like our team to also have. I highly recommend putting these type of notes in a local branch as you're working through some code.