-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
77 lines (65 loc) · 2.28 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import luxon from './modules/luxon.js';
import AwesomeBooks from './modules/book.js';
const awesomeBooks = new AwesomeBooks();
awesomeBooks.load();
if (awesomeBooks.getBooks().length < 1) {
awesomeBooks.addBook('The Power of Focus', 'Mark Victor Hansen');
}
const bookListSection = document.querySelector('#book-list');
const renderBookList = () => {
bookListSection.innerHTML = awesomeBooks
.getBooks()
.map(
(book, index) => `
<article class="book ${index % 2 === 0 ? 'dark' : ''}">
<div>
<p class="title">"${book.title}" by ${book.author}</p>
</div>
<button data-id=${book.id} class="remove">Remove</button>
</article>`,
)
.join('');
}
renderBookList();
const addBookForm = document.querySelector('#add-book');
addBookForm.addEventListener('submit', (event) => {
event.preventDefault();
const title = event.target.querySelector('#title').value;
const author = event.target.querySelector('#author').value;
awesomeBooks.addBook(title, author);
event.target.reset();
renderBookList();
});
bookListSection.addEventListener('click', (event) => {
if (event.target.classList.contains('remove')) {
const { id } = event.target.dataset;
awesomeBooks.deleteBook(+id);
renderBookList();
}
});
const dateSection = document.querySelector('.date');
const dateTime = luxon.DateTime.now().toLocaleString(
luxon.DateTime.DATETIME_FULL,
);
dateSection.innerHTML = dateTime;
const bookList = document.querySelector('.list-link');
const addNew = document.querySelector('.add-new');
const contact = document.querySelector('.contact');
const bookSection = document.querySelector('.books-list');
const addNewSection = document.querySelector('.form');
const contactSection = document.querySelector('.contact-container');
bookList.addEventListener('click', () => {
bookSection.style.display = 'block';
addNewSection.style.display = 'none';
contactSection.style.display = 'none';
});
addNew.addEventListener('click', () => {
bookSection.style.display = 'none';
addNewSection.style.display = 'block';
contactSection.style.display = 'none';
});
contact.addEventListener('click', () => {
bookSection.style.display = 'none';
addNewSection.style.display = 'none';
contactSection.style.display = 'block';
});