generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
38 lines (33 loc) · 1.36 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
import AdderRemovebooks from './JS-Classes/AdderRemovebooks.js';
import ListBooks from './JS-Classes/listBook.js';
import Navigation from './JS-Classes/Navigation.js';
const adderRemovebooks = new AdderRemovebooks();
const listBooks = new ListBooks();
const nav = new Navigation();
const datetime = new Date();
const options = { year: 'numeric', month: 'long', day: 'numeric' };
const dateString = datetime.toLocaleDateString(undefined, options);
const timeString = datetime.toLocaleTimeString();
const dateTimeString = `${dateString} ${timeString}`;
const dateTimeElement = document.getElementById('date-time');
dateTimeElement.innerHTML = dateTimeString;
const form = document.querySelector('form');
listBooks.generate(adderRemovebooks.list(), datetime);
nav.navigation.addEventListener('click', (event) => {
if (event.target.id === 'nav-home') {
nav.sectionShow(document.getElementById('nav-list'));
} else if (event.target.nodeName === 'A') {
nav.sectionShow(event.target);
}
});
document.addEventListener('click', (event) => {
if (event.target && event.target.className.includes('remove-book')) {
adderRemovebooks.removeBook(event.target);
listBooks.generate(adderRemovebooks.list(), datetime);
}
});
form.addEventListener('submit', (event) => {
adderRemovebooks.addBooks();
listBooks.generate(adderRemovebooks.list());
event.preventDefault();
});