class UI {
constructor() {
/*
* The area where our GitHub user data will be placed
* "this.profileSection" refers to the
Stars: ${repo.stargazers_count}
Watchers: ${repo.watchers_count}
Forks: ${repo.forks_count}
`;
})
// Display the content
document.querySelector("#repos").innerHTML = output;
}
show_alert_messages() {
// Clear any existing alerts
this.clear_alert_message();
// Create the div
let alertDiv = document.createElement("div");
// Add classes
alertDiv.classList.add("alert", "alert-danger");
// Add the text
alertDiv.append("No user found.");
// Identify the parent
const SEARCH_CONTAINER = document.querySelector(".search-container");
// Insert the alert div into the DOM
SEARCH_CONTAINER.insertBefore(alertDiv, SEARCH_CONTAINER.firstElementChild);
// Alert lingers for 2 seconds
setTimeout(this.clear_alert_message, 2000);
}
clear_alert_message() {
// Identify the alert
const CURRENT_ALERT = document.querySelector(".alert");
if(CURRENT_ALERT) {
// Remove it if it exists
CURRENT_ALERT.remove();
} else {
// do nothing
}
}
clear_profile() {
/*
* Clear out the profile area
* The line '[this.profileSection.innerHTML = "";] is slower than what is used below
* source: https://coderwall.com/p/nygghw/don-t-use-innerhtml-to-empty-dom-elements
*/
while (this.profileSection.firstChild) {
this.profileSection.removeChild(this.profileSection.firstChild);
}
}
}