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
8 changes: 7 additions & 1 deletion public/js/main.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
const btn = document.getElementById('keyword-btn');
btn.addEventListener('click', getMatches);

/**
* Name: getMatches
* Description: Find resources with keywords matching the user input
*/
async function getMatches() {
//gets the input from the text box and trims white space and makes it lower case
const keyword = document.querySelector('input').value.toLowerCase().trim();

try {
const res = await fetch('/api');
const data = await res.json();
// Filters array from the API for resources with keywords containing user value
const matches = data.filter(resource => resource.keywords.some(str => str.includes(keyword)));
renderMatches(matches);
} catch(err) {
} catch (err) {
console.error(err);
}
}
Expand Down