-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
56 lines (44 loc) · 1.43 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
import Book from './modules/books.js';
import Store from './modules/store.js';
import displayBook from './modules/display.js';
import navigation from './modules/navigation.js';
import { DateTime } from './luxon/src/luxon.js';
navigation();
// Display the clock
setInterval(() => {
const time = DateTime.now();
document.querySelector('.clock').innerHTML = time.toLocaleString(DateTime.DATETIME_FULL_WITH_SECONDS).slice(0, -4);
}, 1000);
// Event: Display Books
document.addEventListener('DOMContentLoaded', displayBook.displayBooks);
let increment = 0;
// Event: Add a Book
document.querySelector('#formId').addEventListener('submit', (e) => {
// Prevent actual submit
e.preventDefault();
// Get form values
const title = document.querySelector('#title').value;
const author = document.querySelector('#author').value;
const id = increment;
increment++;
// Validate
if (title === '' || author === '') {
alert('Please fill in all fields');
} else {
// Instantiate book
const book = new Book(title, author, id);
// Add Book to displayBook
displayBook.addBookToList(book);
// Add book to store
Store.addBook(book);
// Clear fields
displayBook.clearFields();
}
});
// Event: Remove a Book
document.querySelector('#listBooks').addEventListener('click', (e) => {
// Remove book from displayBook
displayBook.deleteBook(e.target);
// Remove book from store
Store.removeBook(e.target);
});