generated from microverseinc/readme-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
73 lines (56 loc) · 2.08 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
import Book from './modules/constructor.js';
import UI from './modules/ui.js';
import Store from './modules/store.js';
import { DateTime } from './node_modules/luxon/build/es6/luxon.js';
const dt = DateTime.now().toLocaleString(DateTime.DATETIME_FULL);
document.getElementById('date-time').innerHTML = dt;
document.addEventListener('DOMContentLoaded', UI.displayBooks);
document.querySelector('#book-form').addEventListener('submit', (e) => {
e.preventDefault();
const title = document.querySelector('#btitle').value;
const author = document.querySelector('#author').value;
const isbn = document.querySelector('#isbn').value;
const book = new Book(title, author, isbn);
UI.addBookToList(book);
Store.addBook(book);
UI.clearFields();
});
document.querySelector('#book-list').addEventListener('click', (e) => {
UI.deleteBook(e.target);
Store.removeBook(e.target.previousElementSibling.textContent);
});
const bookList = document.querySelector('#book-list');
const listHead = document.querySelector('.list-head');
const bookForm = document.querySelector('#book-form');
const addBookTitle = document.querySelector('.add-book-title');
const contactInfo = document.querySelector('.contact-info');
const Toogle = () => {
bookList.style.display = 'block';
bookForm.style.display = 'none';
addBookTitle.style.display = 'none';
listHead.style.display = 'block';
contactInfo.style.display = 'none';
};
document.querySelector('#List').addEventListener('click', () => {
Toogle();
});
const addToogle = () => {
bookList.style.display = 'none';
bookForm.style.display = 'flex';
addBookTitle.style.display = 'block';
listHead.style.display = 'none';
contactInfo.style.display = 'none';
};
document.querySelector('#add-new').addEventListener('click', () => {
addToogle();
});
const contactToogle = () => {
bookList.style.display = 'none';
bookForm.style.display = 'none';
addBookTitle.style.display = 'none';
contactInfo.style.display = 'block';
listHead.style.display = 'none';
};
document.querySelector('#contact').addEventListener('click', () => {
contactToogle();
});