Skip to content

Commit

Permalink
Header created. Event listenter added to search button. API call created
Browse files Browse the repository at this point in the history
  • Loading branch information
Alejandro Gonzalvez authored and Alejandro Gonzalvez committed Jun 5, 2021
1 parent 878745c commit d864a3b
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 0 deletions.
53 changes: 53 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,66 @@
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-+0n0xVW2eSR5OomGNYDnhzAbDsOXxcvSN1TPprVMTNDbiYZCxYbOOl7+AMvyTG2x" crossorigin="anonymous">
<link rel="canonical" href="https://getbootstrap.com/docs/5.0/examples/headers/">
<link rel="stylesheet" href="style.css">
<title>Weather Report</title>
</head>
<body>

<header>
<div class="px-3 py-2 bg-dark text-white">
<div class="container">
<div class="d-flex flex-wrap align-items-center justify-content-center justify-content-lg-between">
<h1 id="header-title">Weather Forecast</h1>

<ul class="nav col-12 col-lg-auto my-2 justify-content-center my-md-0 text-small" id="navbar">
<li>
<a href="#" class="nav-link text-secondary">
<button>Home</button>
</a>
</li>
<!-- <li>
<a href="#" class="nav-link text-white">
<svg class="bi d-block mx-auto mb-1" width="24" height="24"><use xlink:href="#speedometer2"></use></svg>
Dashboard
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi d-block mx-auto mb-1" width="24" height="24"><use xlink:href="#table"></use></svg>
Orders
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi d-block mx-auto mb-1" width="24" height="24"><use xlink:href="#grid"></use></svg>
Products
</a>
</li>
<li>
<a href="#" class="nav-link text-white">
<svg class="bi d-block mx-auto mb-1" width="24" height="24"><use xlink:href="#people-circle"></use></svg>
Customers
</a>
</li> -->
</ul>
</div>
</div>
</div>
<div class="px-3 py-2 border-bottom mb-3">
<div class="container d-flex flex-wrap justify-content-center">
<form class="col-12 col-lg-auto mb-2 mb-lg-0 me-lg-auto" id="search-bar">
<input type="search" class="form-control" placeholder="Search for a city..." aria-label="Search">
<button id="searchBtn">Search</button>
</form>
</div>
</div>
</header>



<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.bundle.min.js" integrity="sha384-gtEjrD/SeCtmISkJkNUaaKMoLD0//ElJ19smozuHV6z3Iehds+3Ulb9Bn9Plx0x4" crossorigin="anonymous"></script>
<script src="script.js"></script>
</body>
</html>
58 changes: 58 additions & 0 deletions script.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
let lat;
let lon;
let searchButton = document.querySelector('#searchBtn');
let searchInput;


// Search bar function
function handleSearchFormSubmit(event) {
event.preventDefault();
searchInput = document.querySelector('.form-control').value;
console.log(searchInput)

if (!searchInput) {
console.error('You need to enter a city!');
return;
}

getWeather();
}

//Search button event listener
searchButton.addEventListener('click', handleSearchFormSubmit);


//Geolocation

// function getLocation() {
// if (navigator.geolocation) {
// navigator.geolocation.getCurrentPosition(showPosition);
// } else {
// console.log("cant get coordinates")
// }
// }
// function showPosition(position) {
// lat = position.coords.latitude;
// lon = position.coords.longitude;
// console.log(lat, lon)

// }
// getLocation();

// One Call API Call

function getWeather() {
let openWeather = 'api.openweathermap.org/data/2.5/weather?q={city name}&appid={7a9e308d5f5da317f65c95353cf68b30}' + searchInput;
console.log(openWeather)
$.ajax({
'url': openWeather,
'method': 'GET',
'timeout': 0,
'headers': {
'Content-Type': 'application/json',
}
})
};


// + '&latitude=' + lat + '&longitude=' + lon
33 changes: 33 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
.b-example-divider {
height: 3rem;
background-color: rgba(0, 0, 0, .1);
border: solid rgba(0, 0, 0, .15);
border-width: 1px 0;
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15);
}

.form-control-dark {
color: #fff;
background-color: var(--bs-dark);
border-color: var(--bs-gray);
}
.form-control-dark:focus {
color: #fff;
background-color: var(--bs-dark);
border-color: #fff;
box-shadow: 0 0 0 .25rem rgba(255, 255, 255, .25);
}

.bi {
vertical-align: -.125em;
fill: currentColor;
}

.text-small {
font-size: 85%;
}

.dropdown-toggle {
outline: 0;
}

0 comments on commit d864a3b

Please sign in to comment.