-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
29 lines (26 loc) · 932 Bytes
/
index.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
import books from './modules/books.js';
import components from './modules/components.js';
components.initialize();
const links = document.querySelectorAll('.nav-ul-li');
links.forEach((link) => {
link.addEventListener('click', (event) => {
if (event.target.innerHTML === 'List') {
components.displayBooks();
} else if (event.target.innerHTML === 'New') {
components.displayForm();
} else if (event.target.innerHTML === 'Contact') {
components.displayContactDetails();
}
});
});
document.querySelector('.save-button > button').addEventListener('click', (event) => {
event.preventDefault();
const bookTitle = document.querySelector('.book-title').value;
const bookAuthor = document.querySelector('.book-author').value;
if (bookTitle && bookAuthor) {
books.saveBooks(bookTitle, bookAuthor);
components.clearNewBookForm();
} else {
components.displayNewBookError();
}
});