-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
51 lines (45 loc) · 1.44 KB
/
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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/* eslint-disable max-classes-per-file */
/* eslint-disable no-unused-vars */
import Book from './modules/book.js';
import Storage from './modules/storage.js';
import Library, {
BOOK_STORAGE,
FORM,
TITLE,
AUTHOR,
} from './modules/library.js';
import CLOCK from './modules/clock.js';
const ADD_BUTTON = FORM.elements[2];
Library.displayLibrary();
ADD_BUTTON.addEventListener('click', () => {
const BOOK = new Book(TITLE.value, AUTHOR.value);
Library.createBook(BOOK);
Storage.setLocalStorage(BOOK);
Library.clearInputs();
});
BOOK_STORAGE.addEventListener('click', (e) => {
const TEXT = e.target.parentNode.children[0].textContent;
Library.removeBook(e.target);
Storage.removeFromLocalStorage(TEXT);
});
// Section pages
const NAV_LINKS = document.querySelector('.nav__links');
const LIST = document.querySelector('.book-list');
const ADD = document.querySelector('.add-book');
const CONTACT = document.querySelector('.contact');
NAV_LINKS.addEventListener('click', (e) => {
e.preventDefault();
if (e.target.classList.contains('List')) {
ADD.classList.remove('active');
CONTACT.classList.remove('active');
LIST.classList.add('active');
} else if (e.target.classList.contains('New')) {
CONTACT.classList.remove('active');
LIST.classList.remove('active');
ADD.classList.add('active');
} else {
LIST.classList.remove('active');
ADD.classList.remove('active');
CONTACT.classList.add('active');
}
});