-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
28 lines (23 loc) · 974 Bytes
/
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
import Helper from './helpers.js';
const helperObj = new Helper();
// display the books in the localStorage on load
helperObj.display();
// Event listener for the addition to localnow(M)L to page
document.querySelector('#add-btn').addEventListener('click', () => {
const title = document.querySelector('#title').value;
const author = document.querySelector('#author').value;
if (title === '' || author === '') {
document.querySelector('.error').innerText = 'Kindly make sure title and author are filled';
return;
}
document.querySelector('.error').innerText = '';
helperObj.add(title, author);
document.querySelectorAll('.remove').forEach((elem) => {
elem.addEventListener('click', (e) => helperObj.remove(e, e.currentTarget.dataset.id));
});
});
// Handle single page functionality
document.querySelectorAll('.links').forEach((link) => {
link.addEventListener('click', helperObj.navHandler);
});
setInterval(helperObj.dateHandler, 1000);