-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
84 lines (74 loc) · 2.12 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
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
78
79
80
81
82
83
84
/* eslint-disable no-unused-vars */
/* eslint-disable no-undef */
/* global Collection */
const collection = new Collection();
const button = document.getElementById('button');
const buttonList = document.getElementById('list');
const buttonAdd = document.getElementById('add');
const buttonContact = document.getElementById('contact');
const error = document.getElementById('error-msg');
const showContent = (content) => {
const list = document.querySelector('.all-books');
const add = document.querySelector('.add-new-book');
const contact = document.querySelector('.contact');
if (content === 'list') {
list.classList.remove('d-none');
add.classList.add('d-none');
contact.classList.add('d-none');
collection.showCollection();
}
if (content === 'add') {
list.classList.add('d-none');
add.classList.remove('d-none');
contact.classList.add('d-none');
}
if (content === 'contact') {
list.classList.add('d-none');
add.classList.add('d-none');
contact.classList.remove('d-none');
}
};
const validateEmpty = () => {
const title = document.getElementById('title');
const author = document.getElementById('author');
let isEmpty = false;
if (title.value.trim().length === 0 || author.value.trim().length === 0) {
isEmpty = true;
return isEmpty;
}
return isEmpty;
};
const showError = () => {
error.classList.remove('d-none');
};
const hideError = () => {
error.classList.add('d-none');
};
buttonList.addEventListener('click', () => {
showContent('list');
});
buttonAdd.addEventListener('click', () => {
showContent('add');
});
buttonContact.addEventListener('click', () => {
showContent('contact');
});
button.addEventListener('click', () => {
if (validateEmpty()) {
showError();
} else {
hideError();
collection.addBook();
// showContent('list');
}
});
const removeBook = (id) => {
collection.removeBook(id);
};
collection.showCollection();
const dateTime = luxon.DateTime;
const time = document.getElementById('time');
const showTime = () => {
time.innerText = dateTime.now().toLocaleString(dateTime.DATETIME_MED);
};
window.setInterval(showTime, 2000);