-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (37 loc) · 1.16 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { getLogo } from "./getLogo.js";
const searchInput = document.querySelector(".js-search-input");
const searchForm = document.querySelector(".js-search-form");
const resultContainer = document.querySelector(".js-result-container");
searchForm.addEventListener("submit", (e) => {
e.preventDefault();
const searchTerm = searchInput.value;
showFetchingMessage();
getLogo(searchTerm).then((data) => {
console.log(data);
if (data != undefined) {
renderLogo(data);
} else {
renderError();
}
});
});
function renderLogo(data) {
clearContainer();
resultContainer.classList.add("border-class");
const logo = document.createElement("img");
logo.src = data;
resultContainer.appendChild(logo);
}
function clearContainer() {
resultContainer.innerHTML = "";
}
function showFetchingMessage() {
clearContainer();
resultContainer.classList.remove("border-class");
resultContainer.innerHTML = `<div class="lds-ellipsis"><div></div><div></div><div></div><div></div></div>`;
}
function renderError() {
clearContainer();
resultContainer.classList.remove("border-class");
resultContainer.innerHTML = `<p class="msg">Invalid url!</p>`;
}