-
Notifications
You must be signed in to change notification settings - Fork 527
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
Sharks- Chinazo Onwukaike #14
Open
ChinazoOnwukaike
wants to merge
10
commits into
AdaGold:main
Choose a base branch
from
ChinazoOnwukaike:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7366427
complete wave 01, design and html
ChinazoOnwukaike dd0b5c9
Merge pull request #1 from ChinazoOnwukaike/wave-01
ChinazoOnwukaike f75d797
Completes wave 02. Changes pics and temp color dynamically
ChinazoOnwukaike dacbd1d
Merge pull request #2 from ChinazoOnwukaike/wave-02
ChinazoOnwukaike 48733bb
complete wave 03
ChinazoOnwukaike 7a6d8df
Merge pull request #3 from ChinazoOnwukaike/wave-03
ChinazoOnwukaike 5476c35
complete wave 04. add F/C toggle
ChinazoOnwukaike ed1ba21
Merge pull request #4 from ChinazoOnwukaike/wave-04
ChinazoOnwukaike 4f33a80
completes wave 05
ChinazoOnwukaike cec6b7b
Merge pull request #5 from ChinazoOnwukaike/wave-05
ChinazoOnwukaike File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
'use strict'; | ||
|
||
const state = { | ||
temp: 80, | ||
tempColor: 'red', | ||
tempBackground: 'url(../src/images/sunny.png)', | ||
cityName: 'Dallas', | ||
lat: 32.7762719, | ||
lon: -96.7968559, | ||
isF: true, | ||
skyBackground: 'url(../src/images/sunnySky.jpeg)', | ||
}; | ||
|
||
//Default Values | ||
const temp = document.getElementById('temp'); | ||
temp.textContent = state.temp + '°'; | ||
temp.style.color = state.tempColor; | ||
temp.style.color = state.cityName; | ||
|
||
const backColor = document.getElementsByTagName('main')[0]; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
|
||
// Change the color of the temp | ||
const changetempColor = () => { | ||
if ((state.isF && state.temp >= 80) || (!state.isF && state.temp >= 27)) { | ||
state.tempColor = 'red'; | ||
temp.style.color = state.tempColor; | ||
} else if ( | ||
(state.isF && state.temp < 80 && state.temp > 69) || | ||
(!state.isF && state.temp < 27 && state.temp > 20) | ||
) { | ||
state.tempColor = 'orange'; | ||
temp.style.color = state.tempColor; | ||
} else if ( | ||
(state.isF && state.temp < 70 && state.temp > 59) || | ||
(!state.isF && state.temp < 20 && state.temp > 15) | ||
) { | ||
state.tempColor = 'yellow'; | ||
temp.style.color = state.tempColor; | ||
} else if ( | ||
(state.isF && state.temp < 60 && state.temp > 49) || | ||
(!state.isF && state.temp < 15 && state.temp > 10) | ||
) { | ||
state.tempColor = 'green'; | ||
temp.style.color = state.tempColor; | ||
} else if ( | ||
(state.isF && state.temp < 50) || | ||
(!state.isF && state.temp < 10) | ||
) { | ||
state.tempColor = 'teal'; | ||
temp.style.color = state.tempColor; | ||
} | ||
}; | ||
|
||
// Change the background image by temp | ||
const changeBackImg = () => { | ||
if ((state.isF && state.temp >= 80) || (!state.isF && state.temp >= 27)) { | ||
state.tempBackground = 'url(../src/images/sunny.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'black'; | ||
} else if ( | ||
(state.isF && state.temp < 80 && state.temp > 69) || | ||
(!state.isF && state.temp < 27 && state.temp > 20) | ||
) { | ||
state.tempBackground = 'url(../src/images/spring.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'white'; | ||
} else if ( | ||
(state.isF && state.temp < 70 && state.temp > 59) || | ||
(!state.isF && state.temp < 20 && state.temp > 15) | ||
) { | ||
state.tempBackground = 'url(../src/images/cool.png)'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
backColor.style.color = 'white'; | ||
} else if ( | ||
(state.isF && state.temp < 60) || | ||
(!state.isF && state.temp < 15) | ||
) { | ||
state.tempBackground = 'url(../src/images/snow.png)'; | ||
backColor.style.color = 'white'; | ||
backColor.style.backgroundImage = state.tempBackground; | ||
} | ||
}; | ||
|
||
// Increase & Decrease the temp | ||
const increaseTemp = () => { | ||
state.temp++; | ||
temp.textContent = `${state.temp}°`; | ||
changetempColor(); | ||
changeBackImg(); | ||
}; | ||
|
||
const decreaseTemp = () => { | ||
state.temp--; | ||
temp.textContent = `${state.temp}°`; | ||
changetempColor(); | ||
changeBackImg(); | ||
}; | ||
|
||
// Change city name by input box | ||
const changeCity = (e) => { | ||
// const searchCity = document.getElementById('search-box'); | ||
const cityState = document.getElementById('city-state'); | ||
state.cityName = e.target.value; | ||
cityState.textContent = state.cityName; | ||
}; | ||
|
||
// Get lat lon of city. | ||
const getLatLon = () => { | ||
const url = 'http://127.0.0.1:5000/'; | ||
axios | ||
.get(url + 'location', { | ||
params: { | ||
q: state.cityName, | ||
}, | ||
}) | ||
.then((response) => { | ||
const data = response.data[0]; | ||
state.lat = data.lat; | ||
state.lon = data.lon; | ||
getWeather(); | ||
}) | ||
.catch((error) => { | ||
console.log('error!', error.response.data); | ||
}); | ||
}; | ||
|
||
// get weather data and update colors and background image | ||
const getWeather = () => { | ||
const url = 'http://127.0.0.1:5000/'; | ||
axios | ||
.get(url + 'weather', { | ||
params: { | ||
lat: state.lat, | ||
lon: state.lon, | ||
}, | ||
}) | ||
.then((response) => { | ||
const ktemp = response.data.current.temp; | ||
state.temp = kToF(ktemp); | ||
temp.textContent = `${state.temp}°`; | ||
changetempColor(); | ||
changeBackImg(); | ||
}) | ||
.catch((error) => { | ||
console.log('error!', error.response.data); | ||
}); | ||
}; | ||
|
||
// kelvin to F or C | ||
const kToF = (k) => { | ||
if (state.isF) { | ||
const conversion = (k - 273.15) * (9 / 5) + 32; | ||
return Math.round(conversion); | ||
} else if (!state.isF) { | ||
const conversion = k - 273.15; | ||
return Math.round(conversion); | ||
} | ||
}; | ||
|
||
// Toggle between F and C and change the button | ||
const setTempToggle = () => { | ||
state.isF = !state.isF; | ||
if (state.isF === false) { | ||
const toggle = document.getElementById('toggle'); | ||
toggle.classList.remove('fa-toggle-off'); | ||
toggle.classList.add('fa-toggle-on'); | ||
} else { | ||
const toggle = document.getElementById('toggle'); | ||
toggle.classList.remove('fa-toggle-on'); | ||
toggle.classList.add('fa-toggle-off'); | ||
} | ||
getLatLon(); | ||
}; | ||
|
||
//change sky | ||
const changeSky = (e) => { | ||
const skyImg = document.getElementById('sky-container'); | ||
const skyValue = document.getElementById('sky-select').value; | ||
|
||
if (skyValue === 'sunny') { | ||
state.skyBackground = 'url(../src/images/sunnySky.jpeg)'; | ||
skyImg.style.backgroundImage = state.skyBackground; | ||
} else if (skyValue === 'rainy') { | ||
console.log(skyValue); | ||
state.skyBackground = 'url(../src/images/rainSky.jpg)'; | ||
skyImg.style.backgroundImage = state.skyBackground; | ||
} else if (skyValue === 'snowy') { | ||
state.skyBackground = 'url(../src/images/snowySky.jpeg)'; | ||
skyImg.style.backgroundImage = state.skyBackground; | ||
} else if (skyValue === 'cloudy') { | ||
state.skyBackground = 'url(../src/images/cloudySky.jpeg)'; | ||
skyImg.style.backgroundImage = state.skyBackground; | ||
} | ||
}; | ||
|
||
// Reset search button | ||
const resetSearchBtn = () => { | ||
const searchBox = document.getElementById('search-box'); | ||
const cityState = document.getElementById('city-state'); | ||
searchBox.value = ''; | ||
state.cityName = 'Dallas'; | ||
cityState.textContent = state.cityName; | ||
getLatLon(); | ||
}; | ||
|
||
// Event Handlers | ||
const registerEventHandlers = () => { | ||
// Increse Decrease Arrows | ||
const upArrow = document.getElementById('arrow-up'); | ||
upArrow.addEventListener('click', increaseTemp); | ||
|
||
const downArrow = document.getElementById('arrow-down'); | ||
downArrow.addEventListener('click', decreaseTemp); | ||
|
||
//Search for city and reset city button | ||
const searchCity = document.getElementById('search-box'); | ||
searchCity.addEventListener('input', changeCity); | ||
|
||
const resetBtn = document.getElementById('search-reset-btn'); | ||
resetBtn.addEventListener('click', resetSearchBtn); | ||
|
||
//Get current temp | ||
const cityTempBtn = document.getElementById('currentTempBtn'); | ||
cityTempBtn.addEventListener('click', getLatLon); | ||
|
||
//Toggle btwn F/C | ||
const toggleFC = document.getElementById('tempToggle'); | ||
toggleFC.addEventListener('click', setTempToggle); | ||
|
||
//Change sky | ||
const skySelect = document.getElementById('sky-select'); | ||
skySelect.addEventListener('change', changeSky); | ||
|
||
// Default Values that need DOM content loading | ||
const skyContainer = document.getElementById('sky-container'); | ||
skyContainer.style.backgroundImage = state.skyBackground; | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', registerEventHandlers); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
since you aren't using this, let's get rid of it for the final submission!