-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
62 lines (54 loc) · 1.94 KB
/
script.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
import { getFilterMenuOption } from "./handlers.js";
import { removeTodo } from "./handlers.js";
import { addTodo } from "./renderers.js";
import { createTodoTest } from "./tests/index.test.js";
document.querySelector("#addButton").addEventListener("click", showForm);
document.querySelector("#bin").addEventListener("click", removeTodo);
document.querySelector("#back").addEventListener("click", removeForm);
const dropdownMenu = document.getElementById("filterDropdown");
dropdownMenu.addEventListener("change", filterToDos);
const sources = document.querySelectorAll("#todo-container > *");
console.log(sources);
sources.forEach((element) => {
element.addEventListener("drag", (event) => console.log(event));
});
// save todos to local storage, call after renderer to addTodo
function saveToStorage(todos) {
localStorage.setItem("todos", JSON.stringify(todos));
}
function showForm(event) {
// this stops checkign required fields
event.preventDefault();
console.log("click start");
const formElement = document.querySelector("#todo-form");
if (formElement.style.display === "none") {
formElement.style.display = "flex";
document.querySelector("#textInput").focus();
} else {
addTodo(event);
}
console.log("click finish");
}
export function removeForm() {
console.log("hide form");
const form = document.querySelector("#todo-form");
form.style.display = "none";
form.reset();
}
export function filterToDos(selectedCategory = getFilterMenuOption()) {
const toDos = document.querySelectorAll(".todo-container > div");
toDos.forEach((toDo) => {
const category = toDo.querySelector(".category").textContent;
if (selectedCategory === "" || category === selectedCategory) {
toDo.style.display = "flex";
} else {
toDo.style.display = "none";
}
});
}
if (location.href.includes("test")) {
createTodoTest();
} else if (confirm("Run tests?")) {
createTodoTest();
}
console.log(location.href.includes("test"));