-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (35 loc) · 1.25 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
import { TodoList } from "./components/TodoList.js";
import { fetchJSON } from "./Functions/api.js";
try{
//const todos = await fetchJSON("https://jsonplaceholder.typicode.com/todos?_limit=5")
const todosLocalStorage = localStorage.getItem('todos')?.toString()
let todos = []
if (todosLocalStorage) {
todos = JSON.parse(todosLocalStorage)
}
let list = new TodoList(todos)
list.appendTo(document.querySelector('.list-group'))
} catch {
alert('Erreur lors du chargement des données')
}
// Filters
const filters = document.querySelectorAll('.filter')
const listgroup = document.querySelector('.list-group')
filters.forEach((filter)=>{
filter.addEventListener('click',()=>{
filters.forEach((filter)=>{
filter.classList.remove('active')
});
filter.classList.add('active')
if (filter.classList.contains('todo')){
listgroup.classList.add('todo')
listgroup.classList.remove('done')
} else if (filter.classList.contains('done')){
listgroup.classList.add('done')
listgroup.classList.remove('todo')
} else {
listgroup.classList.remove('done')
listgroup.classList.remove('todo')
}
})
})