-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
77 lines (48 loc) · 1.7 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
/* eslint-disable linebreak-style */
// Import th Books Class
import BookData from './modules/Books.js';
// Import LocalStorage
import LocalStorage from './modules/LocalStorage.js';
// Import methods
import Methods from './modules/Methods.js';
// Import single Page events
import { listLinkOcult, addBookOcult, contactOcult } from './modules/Single_page.js';
// Import clock function
import './modules/Clock.js';
// define the base variables
const title = document.getElementById('title');
const author = document.getElementById('author');
const addBtn = document.getElementById('add-btn');
const booksList = document.getElementById('Books-List');
const error = document.querySelector('#error');
// Create an event to display the books
document.addEventListener('DOMContentLoaded', Methods.displayBooks);
// Create an event to Add the books
addBtn.addEventListener('click', () => {
if (author.value.length > 0 && title.value.length > 0) {
// Create a new Objet with the input information
const book = new BookData(author.value, title.value);
// Add book to UI
Methods.addBookToList(book);
// Add book to localStorage
LocalStorage.addBook(book);
// Clear Input
Methods.clearInput();
// Ocult error
error.classList.add('ocult');
} else {
// Show error message
error.classList.remove('ocult');
}
});
// Create an event to remove the book
booksList.addEventListener('click', (e) => {
// Remove the book from the list
Methods.deleteBook(e.target);
// Remove book from the store
LocalStorage.removeBooks(e.target.parentElement.previousElementSibling.firstChild.textContent);
});
// Execute single page events
listLinkOcult();
addBookOcult();
contactOcult();