-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b53f750
commit 58c6c94
Showing
4 changed files
with
39 additions
and
35 deletions.
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
Binary file not shown.
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 |
---|---|---|
|
@@ -13,17 +13,13 @@ | |
<body> | ||
<div class="container"> | ||
<!-- navbar --> | ||
<nav class="navbar navbar-expand-lg navbar-light bg-light px-5"> | ||
<a class="navbar-brand" href="#"><h4>Mobile Hut</h4></a> | ||
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" | ||
aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation"> | ||
<span class="navbar-toggler-icon"></span> | ||
</button> | ||
<div class="collapse navbar-collapse" id="navbarSupportedContent"> | ||
<form class="form-inline my-2 my-lg-0 d-flex ms-auto"> | ||
<nav class="row navbar navbar-expand-lg navbar-light bg-light px-5"> | ||
<a class="col-12 col-md-6 navbar-brand text-center" href="#"><h4>Mobile Hut</h4></a> | ||
<div class="col-12 col-md-6 "> | ||
<div class="my-2 my-lg-0 d-flex ms-auto"> | ||
<input class="form-control mr-sm-2" id="name-input" type="search" placeholder="Search" aria-label="Search"> | ||
<button onclick="phoneData()" class="btn btn-outline-success my-2 my-sm-0 mx-2" type="submit">Search</button> | ||
</form> | ||
</div> | ||
</div> | ||
</nav> | ||
<!-- cards section --> | ||
|
@@ -40,14 +36,14 @@ <h2 class="text-center my-3">Sorry we don't find anything with your search😒</ | |
<div class="row text-center loading" id="loading"> | ||
<img src="./images/loading.gif" alt=""> | ||
</div> | ||
<div class="row text-center show-more" id="show-more"> | ||
<div class="col-12"><button class="btn btn-primary" onclick="showRemainingData()">Show more</button></div> | ||
</div> | ||
</div> | ||
|
||
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js" | ||
integrity="sha384-ka7Sk0Gln4gmtz2MlQnikT1wXgYsOg+OMhuP+IlRH9sENBO0LRn5q+8nbTov4+1p" | ||
crossorigin="anonymous"></script> | ||
<script src="./js/script.js"></script> | ||
|
||
|
||
|
||
</body> | ||
</html> |
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 |
---|---|---|
@@ -1,54 +1,59 @@ | ||
document.getElementById('loading').style.display = "none"; | ||
// fetch data | ||
const phoneData = () => { | ||
const inputFromuser = document.getElementById('name-input').value; | ||
const phoneName = inputFromuser.toLowerCase(); | ||
toggleLoading('block') | ||
fetch(`https://openapi.programming-hero.com/api/phones?search=${phoneName}`) | ||
.then(res => res.json()) | ||
.then(data => displayPhone(data)) | ||
toggleNotFound('none'); | ||
toggleLoading('block') | ||
document.getElementById('not-found').style.display = "none"; | ||
} | ||
|
||
// not found handler | ||
const toggleNotFound = (input) => { | ||
const notFound = document.getElementById('not-found'); | ||
notFound.style.display = input; | ||
|
||
} | ||
|
||
// loading handler | ||
const toggleLoading = (input) => { | ||
const loading = document.getElementById('loading'); | ||
loading.style.display = input; | ||
} | ||
|
||
// displaying data | ||
const displayPhone = (data) => { | ||
const cards = document.getElementById('cards'); | ||
cards.textContent = ''; | ||
toggleNotFound('none') | ||
|
||
if (data.status == false) { | ||
toggleNotFound('block'); | ||
toggleLoading('none'); | ||
cards.textContent = ""; | ||
document.getElementById('not-found').style.display = 'block'; | ||
toggleLoading('none') | ||
} else { | ||
for (let item of data.data) { | ||
const cards = document.getElementById('cards'); | ||
cards.textContent = ""; | ||
const allData = data.data; | ||
const firstData = data.data.slice(0, 20); | ||
for (let item of firstData) { | ||
const div = document.createElement('div'); | ||
div.classList.add('col-12'); | ||
div.classList.add('col-md-3'); | ||
div.classList.add('d-flex'); | ||
div.classList.add('justify-content-center'); | ||
div.classList.add('text-center'); | ||
div.innerHTML = ` | ||
<div class="card g-2" style="width: 90%;"> | ||
<img src="${item.image}" class="card-img-top" alt="${item.brand} mobile image"> | ||
<div class="card-body"> | ||
<h5 class="card-title">${item.brand}</h5> | ||
<p class="card-text">${item.phone_name}</p> | ||
</div> | ||
<div class="card g-2" style="width: 90%;"> | ||
<img src="${item.image}" class="card-img-top" alt="${item.brand} mobile image"> | ||
<div class="card-body"> | ||
<h5 class="card-title">${item.brand}</h5> | ||
<p class="card-text">${item.phone_name}</p> | ||
<button class="btn btn-primary">Specification</button> | ||
</div> | ||
` | ||
</div> | ||
` | ||
cards.appendChild(div) | ||
} | ||
toggleLoading('none') | ||
|
||
|
||
toggleNotFound('none'); | ||
toggleLoading('none'); | ||
} | ||
|
||
|
||
|
||
} |