-
Notifications
You must be signed in to change notification settings - Fork 100
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
Panthers - Billie Betts #91
base: main
Are you sure you want to change the base?
Changes from all commits
e0181bd
dd3b74f
2c93b09
ca06cca
77265bb
eb522d5
8d6be48
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 |
---|---|---|
@@ -1,5 +1,9 @@ | ||
{ | ||
"dependencies": { | ||
"axios": "^0.27.2" | ||
} | ||
"dependencies": { | ||
"axios": "^0.27.2" | ||
}, | ||
"devDependencies": { | ||
"gh-pages": "^4.0.0", | ||
"parcel-bundler": "1.12.5" | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,213 @@ | ||
// LOCATION | ||
|
||
currentCity = document.getElementById('cityName').value; | ||
|
||
const updateCity = () => { | ||
let inputCity = document.getElementById('cityName').value; | ||
let showCity = document.getElementById('setCity'); | ||
showCity.innerHTML = inputCity; | ||
currentCity = inputCity; | ||
}; | ||
|
||
const resetCity = () => { | ||
let cityInput = document.getElementById('cityName'); | ||
cityInput.value = 'Atlanta'; | ||
updateCity(); | ||
}; | ||
|
||
// CONDITIONS | ||
|
||
let selectConditions = document.querySelectorAll('input[type="radio"]'); | ||
|
||
let condResult = document.getElementById('cond_result'); | ||
condResult.innerHTML = '✨'; | ||
|
||
const updateCondition = () => { | ||
try { | ||
let selected = document.querySelector( | ||
"input[name='Conditions']:checked" | ||
).value; | ||
condResult.innerHTML = selected; | ||
} catch {} | ||
}; | ||
|
||
// TEMP DEPENDANTS | ||
|
||
let defaultTemp = 'LOADING...'; | ||
let currentTemp = defaultTemp; | ||
|
||
const HOW_YA_FEELIN = ['🥶', '😮💨', '😄', '😎', '😅', '🥵', '🤔']; | ||
const HILLS_ARE_ALIVE = ['🧊', '🌲', '🌷', '🌻', '🌴', '🔥', '🌎']; | ||
Comment on lines
+39
to
+40
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. Cute emojis! 😁 |
||
const REPO_RAINBOW = [ | ||
'#993BDB', | ||
'#2B52FF', | ||
'#0BD769', | ||
'#FFE146', | ||
'#FF7912', | ||
'#FF0000', | ||
]; | ||
|
||
let showField = document.getElementById('temp_field'); | ||
let showYou = document.getElementById('you_are_here'); | ||
|
||
const updateTempies = (adjustedTemp) => { | ||
let tempSetting = 6; | ||
|
||
if (adjustedTemp > 99) { | ||
tempSetting = 5; | ||
} else if (adjustedTemp > 79) { | ||
tempSetting = 4; | ||
} else if (adjustedTemp > 65) { | ||
tempSetting = 3; | ||
} else if (adjustedTemp > 39) { | ||
tempSetting = 2; | ||
} else if (adjustedTemp > 14) { | ||
tempSetting = 1; | ||
} else if (adjustedTemp <= 14) { | ||
tempSetting = 0; | ||
} | ||
Comment on lines
+53
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. Nice work with this conditional Billie! |
||
|
||
currentTemp = adjustedTemp; | ||
|
||
showField.innerHTML = HILLS_ARE_ALIVE[tempSetting]; | ||
showYou.innerHTML = HOW_YA_FEELIN[tempSetting]; | ||
Comment on lines
+72
to
+73
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. Nice approach to this array 🥳 |
||
shownTemp.innerHTML = adjustedTemp; | ||
document.getElementById('temp_result').style.color = | ||
REPO_RAINBOW[tempSetting]; | ||
}; | ||
|
||
// TEMPERATURE | ||
|
||
let shownTemp = document.getElementById('temp_result'); | ||
|
||
shownTemp.innerHTML = currentTemp; | ||
|
||
const handleAdd = () => { | ||
currentTemp++; | ||
shownTemp.innerHTML = currentTemp; | ||
|
||
updateTempies(currentTemp); | ||
}; | ||
|
||
const handleSub = () => { | ||
currentTemp--; | ||
shownTemp.innerHTML = currentTemp; | ||
|
||
updateTempies(currentTemp); | ||
}; | ||
Comment on lines
+85
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. Great function naming 👍🏾 |
||
|
||
// API CALLS | ||
|
||
const findWeather = (query) => { | ||
let locationData, weatherData; | ||
let modifiedLocData, modifiedWeathData; | ||
|
||
axios | ||
.get('http://127.0.0.1:5000/location', { | ||
params: { | ||
q: currentCity, | ||
format: 'json', | ||
}, | ||
}) | ||
.then((response) => { | ||
locationData = response.data; | ||
|
||
const modifyLocation = (locationData) => { | ||
let latlon = []; | ||
let focusLocation = locationData[0]; | ||
|
||
let focusLat = Number(focusLocation['lat']); | ||
let adjustLat = focusLat.toFixed(2); | ||
latlon.push(adjustLat); | ||
|
||
let focusLon = Number(focusLocation['lon']); | ||
let adjustLon = focusLon.toFixed(2); | ||
latlon.push(adjustLon); | ||
|
||
return latlon; | ||
}; | ||
|
||
modifiedLocData = modifyLocation(locationData); | ||
|
||
axios | ||
.get('http://127.0.0.1:5000/weather', { | ||
params: { | ||
Comment on lines
+106
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. Consider breaking this function up a bit. It's taking on a lot responsibilty. Whenever we see a function that is more than 10 lines long we should consider seprating concerns. This is completely preferential but just a note. More on this here: https://dmitripavlutin.com/the-art-of-writing-small-and-plain-functions/ |
||
lat: modifiedLocData[0], | ||
lon: modifiedLocData[1], | ||
format: 'json', | ||
}, | ||
}) | ||
.then((response) => { | ||
weatherData = response.data; | ||
|
||
const modifyWeather = (weatherData) => { | ||
let relevantData = [weatherData['main'], weatherData['weather']]; | ||
let defTempCond = []; | ||
|
||
let unmodifiedTemp = relevantData[0]['temp']; | ||
let tempF = ((unmodifiedTemp - 273.15) * 9) / 5 + 32; | ||
let modifiedTemp = tempF.toFixed(0); | ||
defTempCond.push(modifiedTemp); | ||
|
||
let condID = Number(relevantData[1][0]['id']); | ||
let idToCond = 'sunny'; | ||
|
||
if (condID > 800) { | ||
idToCond = '⛅'; | ||
} else if (condID === 800) { | ||
idToCond = '✨'; | ||
} else if (condID > 700) { | ||
idToCond = '⛅'; | ||
} else if (condID > 599) { | ||
idToCond = '☃️'; | ||
} else { | ||
idToCond = '🌈'; | ||
} | ||
|
||
defTempCond.push(idToCond); | ||
return defTempCond; | ||
}; | ||
|
||
Comment on lines
+143
to
+170
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. Consider moving this outside of the function to separate concerns but great work with this approach 🏁 |
||
modifiedWeathData = modifyWeather(weatherData); | ||
|
||
updateTempies(modifiedWeathData[0]); | ||
currentTemp = modifiedWeathData[0]; | ||
condResult.innerHTML = modifiedWeathData[1]; | ||
}) | ||
.catch((error) => { | ||
weatherData = 'An error has occured while fetching weather data.'; | ||
}); | ||
}) | ||
.catch((error) => { | ||
locationData = 'An error has occured while fetching location data.'; | ||
}); | ||
}; | ||
|
||
// UPDATE WITH DATA | ||
const updateWeather = () => { | ||
window.location.reload(); | ||
}; | ||
|
||
// REGISTERING EVENTS | ||
|
||
const registerEventHandlers = () => { | ||
updateTempies(currentTemp); | ||
|
||
const addTemp = document.getElementById('uppie'); | ||
addTemp.addEventListener('click', handleAdd); | ||
|
||
const subTemp = document.getElementById('downie'); | ||
subTemp.addEventListener('click', handleSub); | ||
|
||
updateCity(); | ||
const setCityInput = document.getElementById('cityName'); | ||
setCityInput.addEventListener('input', updateCity); | ||
|
||
updateCondition(); | ||
selectConditions.forEach((condition) => { | ||
condition.addEventListener('change', updateCondition); | ||
}); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); | ||
findWeather(currentCity); |
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.
Nice job using this radio, I'll allow it even though there's an issue with wave 05 (selecting the sky), the requirements specify that a user should select from a dropdown element.