-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
67 lines (61 loc) · 1.9 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
import {
AddBookForm, bookTitle, bookAuthor, error, viewBook, addBook,
contact, list, addButton, contactButton, formAdd, isClicked, dateTime,
} from './modules/htmlElements.js';
import Book from './modules/bookClass.js';
import luxon from './modules/luxon.js';
const books = new Book();
document.addEventListener('DOMContentLoaded', () => {
viewBook.style.display = 'none';
addBook.style.display = 'block';
contact.style.display = 'none';
});
list.addEventListener('click', () => {
if (isClicked === false) {
viewBook.style.display = 'block';
addBook.style.display = 'none';
contact.style.display = 'none';
}
});
addButton.addEventListener('click', () => {
if (isClicked === false) {
viewBook.style.display = 'none';
addBook.style.display = 'block';
contact.style.display = 'none';
}
});
contactButton.addEventListener('click', () => {
if (isClicked === false) {
viewBook.style.display = 'none';
addBook.style.display = 'none';
contact.style.display = 'block';
}
});
AddBookForm.addEventListener('submit', (e) => {
e.preventDefault();
const title = bookTitle.value;
const author = bookAuthor.value;
if (title === '' || author === '') {
error.innerHTML = 'Please fill in all fields';
setTimeout(() => {
error.innerHTML = '';
}, 5000);
} else {
const books = new Book(title, author);
books.addBook();
formAdd.innerHTML = `"${title}" was added to your collection`;
formAdd.style.animation = 'fadeIn 2s ease-in-out';
setTimeout(() => {
formAdd.style.animation = 'fadeOut 2s ease-in-out';
}, 5000);
setTimeout(() => {
formAdd.innerHTML = '';
}, 6000);
bookTitle.value = '';
bookTitle.focus();
bookAuthor.value = '';
error.innerHTML = '';
}
});
dateTime.innerText = luxon.DateTime.now().setLocale('en-US').toLocaleString(luxon.DateTime.DATETIME_FULL_WITH_SECONDS);
window.onload = books.render();