-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
67 lines (60 loc) · 1.96 KB
/
app.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
const forms = document.querySelectorAll(".delete-form");
forms.forEach((form) => {
form.addEventListener("submit", (e) => {
e.preventDefault();
let title = e.target.parentNode.querySelector(".title").textContent;
let inputVal = e.target.querySelector("input").value;
let errorText = e.target.querySelector("p");
if (title === inputVal) {
e.target.parentNode.remove();
} else {
console.log(e.target.querySelector("p"));
errorText.style.display = "block";
}
});
});
/**
* Open New Repository Modal
*/
document.getElementById('create-new').addEventListener('click', () => {
document.querySelector('.modal-overlay').classList.add('active');
})
/**
* Close New Repository Modal
*/
document.getElementById('close-modal').addEventListener('click', () => {
document.querySelector('.modal-overlay').classList.remove('active');
})
/**
* Create New Repository
*/
document.getElementById('new-repo-form').addEventListener('submit', (e) => {
e.preventDefault();
// Get the values from the form
let name = document.getElementById('repo-name').value;
let description = document.getElementById('repo-desc').value;
// Display the new repository
let reposDiv = document.querySelector('.repos');
let html = `
<div class="repo">
<div class="img"></div>
<div class="info">
<p class="title">${name}</p>
<p class="description">
${description}
</p>
</div>
<form class="delete-form">
<label>Type the repo name to delete</label>
<p>You must match the repository name</p>
<input type="text" />
<button>Delete Repository</button>
</form>
</div>
`;
reposDiv.insertAdjacentHTML('beforeend', html);
// Clear the form and close the modal
document.getElementById('repo-name').value = '';
document.getElementById('repo-desc').value = '';
document.querySelector('.modal-overlay').classList.remove('active');
});