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

Amethyst - Elaine Watkins and Sarah Watkins #73

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
84 changes: 79 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,87 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Weather Report</title>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Rubik&display=swap" rel="stylesheet">
<link rel="stylesheet" href="styles/index.css" />
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Kanit:wght@200&display=swap" rel="stylesheet">
<script src="https://kit.fontawesome.com/b581a87b17.js" crossorigin="anonymous"></script>
<title>Weather Report</title>

</head>

<!--
body
container - Flexbox Rows
4 Rows -
Header Row
h1
Temperature & Location Row
Temperature, Buttons section
Location section
City Name & Sky Row
City Name - Textbox section
Sky - Dropdown section
Weather Garden Row - Background (Sky)
Clouds section
Landscape section

blue #0c79bd, yellow #fdbb2d
-->


<body>
<script src="./src/index.js"></script>
<main class="container">
<header class="row">
<h1>Weather Report</h1>
</header>
<section class="row weather-for-city">
<section id="temperature">
<div>
<i class="fa-sharp fa-solid fa-chevron-left"></i>
<h2>
<span id="degrees">70</span>
&#x2109;
</h2>
<i class="fa-sharp fa-solid fa-chevron-right"></i>
</div>
<button id="reset-city">Reset City</button>
</section>
<section id="city">
<h2 id="city-header">Atlanta, <br> GA</h2>
</section>
</section>

<!-- <div id="city">City Name</div>
<input type="text" id="city-input" oninput="updateCityName()" /> -->
<section class="row choose-city-sky">
<section class="choose-city">
<h4>City Name: </h4>
<input id="textbox"></input>
</section>
<section class="choose-sky">
<h4>Sky:</h4>
<select class="select-sky" name="select-sky">
<option value="sunny">Sunny</option>
<option value="cloudy">Cloudy</option>
<option value="rainy">Rainy</option>
<option value="snowy">Snowy</option>
</select>
</section>
</section>
<section class="row weather-garden">
<section id="sky">
<p>☁️ ☁️ ☁️ ☁️ ☀️ ☁️ ☁️ ☁️ ☁️</p>
</section>
<section id="landscape">
<p>🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷</p>
</section>
</section>
Comment on lines +61 to +82

Choose a reason for hiding this comment

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

Your Markup looks great!

</main>
<script src="./node_modules/axios/dist/axios.min.js"></script>
<script src="./src/index.js"></script>
</body>
</html>
</html>



155 changes: 155 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,155 @@
const state = {
left_arrow: null,
right_arrow: null,
degreeCountLabel: null,
landscape: "🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷",
degreeCount: 70,
textBox: null,
sky: "☁️ ☁️ ☁️ ☀️ ☁️ ☁️",
degreeCount: 70,
sky_options: null,
temp: 0,
tempDisplay: null,
cityHeader: null
}
Comment on lines +1 to +14

Choose a reason for hiding this comment

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

Nice!


const convertKelvintoFahrenheight = (kelv_degree) => {
state.degreeCount = Math.floor((kelv_degree - 273.15) * 9/5 + 32)
}

const findCityLocation = async (cityName) => {
await axios.get('http://localhost:5000/location', {
params: {
q: cityName
}
})
.then(response => {
axios.get('http://localhost:5000/weather', {
params: {
lat: response.data[0].lat,
lon: response.data[0].lon
}
}).then(response => {
// state.temp = response.data.main.temp
// state.degreeCount = state.temp
convertKelvintoFahrenheight(response.data.main.temp)
state.degreeCountLabel.textContent = state.degreeCount
change_color()
console.log(state.degreeCount)
})
})
.catch((error) => {
console.log(error);
})
Comment on lines +20 to +43

Choose a reason for hiding this comment

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

Great function naming, this looks really clean 💯

}

const resetCity = () => {
state.textBox.value = 'Atlanta'
state.cityHeader.innerText = 'Atlanta'
findCityLocation('Atlanta')
}

findCityLocation()

Choose a reason for hiding this comment

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

👍🏾

// city, name, latitude, longitude, temp (state - global variables)

const refreshUI = () => {
state.degreeCountLabel.textContent = state.degreeCount;
}

const change_color = () => {
if (state.degreeCountLabel.textContent >= 80)
{
state.degreeCountLabel.style.color = 'red';
change_landscape("🌵__🐍_🦂_🌵🌵__🐍_🏜_🦂")
} else if (state.degreeCountLabel.textContent >= 70) {
state.degreeCountLabel.style.color = 'orange';
change_landscape("🌸🌿🌼__🌷🌻🌿_☘️🌱_🌻🌷")
} else if (state.degreeCountLabel.textContent >= 60)
{
state.degreeCountLabel.style.color = 'gold';
change_landscape("🌾🌾_🍃_🪨__🛤_🌾🌾🌾_🍃")
} else if (state.degreeCountLabel.textContent >= 50) {
state.degreeCountLabel.style.color = 'green';
change_landscape("🌲🌲⛄️🌲⛄️🍂🌲🍁🌲🌲⛄️🍂🌲")
} else {
state.degreeCountLabel.style.color = 'teal';
}
}

const change_landscape = (garden) => {
state.landscape.textContent = garden;
}

let decreaseDegree = (event) => {
--state.degreeCount;
change_color();
refreshUI();
}

let increaseDegree = (event) => {
++state.degreeCount;
change_color();
refreshUI();
}

function updateCityName(event) {
if (event.key === "Enter") {

const cityNameInput = document.getElementById('textbox');
Comment on lines +79 to +98

Choose a reason for hiding this comment

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

Super smart approach!

const cityName = cityNameInput.value.trim();

const cityElement = document.getElementById('city-header');
cityElement.textContent = cityName;
findCityLocation(cityName)
}
}
let changeSky = (event) => {
console.log(event.target.value);
if (event.target.value == 'sunny') {
state.sky.textContent = '☁️ ☁️ ☁️ ☀️ ☁️ ☁️'
} else if (event.target.value == 'cloudy') {
state.sky.textContent = '☁️☁️ ☁️ ☁️ ☁️ 🌤 ☁️ ☁️☁️'
} else if ( event.target.value == 'rainy') {
state.sky.textContent = '🌧🌈⛈🌧🌧💧⛈🌧🌦🌧💧🌧🌧'
} else {
state.sky.textContent = '🌨❄️🌨🌨❄️❄️🌨❄️🌨❄️❄️🌨🌨'
}
}
// Updatecity name - takes location and updates city
// city and state object

const loadControls = () => {
state.degreeCountLabel = document.getElementById('degrees')
state.left_arrow = document.querySelector('.fa-chevron-left');
state.right_arrow = document.querySelector('.fa-chevron-right');
state.landscape = document.getElementById('landscape')
state.textBox = document.getElementById('textbox')
console.log(state)
state.landscape = document.getElementById('landscape');
state.sky_options = document.querySelector('.select-sky');
state.sky = document.getElementById('sky');
state.resetCity = document.getElementById('reset-city');
state.cityHeader = document.getElementById('city-header');
}

const registerEvents = () => {
state.left_arrow.addEventListener('click', decreaseDegree);
state.right_arrow.addEventListener('click', increaseDegree);
state.textBox.addEventListener('keypress',updateCityName)
state.sky_options.addEventListener('change', changeSky);
state.resetCity.addEventListener('click', resetCity)
}

const onLoaded = () => {
// steps to carry out when the page has loaded
loadControls();
registerEvents();
refreshUI();
};

// we would usually run the onLoaded function in
// response to the document finishing loading, but in
// code sandbox, the page has already loaded by the
// time our script is added to the page.
// document.addEventListener("DOMContentLoaded", onLoaded);
onLoaded();
Loading