Skip to content
Merged
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
18 changes: 17 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,18 @@ scrollBtn.addEventListener("click", function () {
});
});

const input = document.querySelector('input')
const scrollContainer = document.querySelector('.scroll-container')
//add event listener for when input is focused
input.addEventListener('keydown', (e) => {
if (e.key === 'Enter') {
//stop browser from refreshing
e.preventDefault()
getMatches()
}
});


const btn = document.getElementById('keyword-btn');
btn.addEventListener('click', getMatches);

Expand All @@ -28,6 +40,10 @@ async function getMatches() {
} catch (err) {
console.error(err);
}
//reset search bar to empty
document.querySelector('input').value = ''
//scroll back to the top
scrollContainer.scrollTop = 0
}

/**
Expand All @@ -40,7 +56,7 @@ function renderMatches(matches) {
list.innerHTML = '';

// For every match found, render the objects to the DOM in JSON format
if(matches.length > 0) {
if (matches.length > 0) {
matches.forEach(match => {
const li = document.createElement('li');

Expand Down