-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
43 lines (31 loc) · 1.12 KB
/
main.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
const searchForm = document.querySelector('.search');
const link = document.getElementById('links');
const getLinks = async (term) => {
// let uri = `http://localhost:3000/links?_sort=name&_order=asc`;
let uri = 'https://singlebuck.herokuapp.com/links/?_sort=name&_order=asc';
if(term) {
uri += `&q=${term}`;
link.innerHTML = "";
}
const res = await fetch(uri);
const data = await res.json();
// console.log(data);
data.forEach(i => {
let template = `
<div class="fixed-content card " data-aos="fade-up">
<h2>${i.name}</h2>
<a href="${i.link}">Website</a>
<img src="${i.image}" class="img" alt="portfolio image">
<a href="./detail.html?id=${i.id}">Read more</a>
</div>
`;
// link.innerHTML = template;
link.insertAdjacentHTML('beforeend', template);
});
}
searchForm.addEventListener('submit', (e) => {
e.preventDefault();
getLinks(searchForm.term.value.trim());
});
window.addEventListener('DOMContentLoaded', () => getLinks());
// getLinks();