generated from Dagic-zewdu/js-lintor-template
/
action.js
51 lines (43 loc) · 1.56 KB
/
action.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
import { AddtoStorage } from './storage';
export const ArrangeList = (list) => list.map((item, index) => ({ ...item, index }));
export const AddtoList = (description, list) => {
const todo = [...list, { index: 1, description, completed: false }];
return ArrangeList(todo);
};
export const setCompleted = (id, value, list) => {
const todos = list.map((todo) => {
if (todo.index.toString() === id) { return { ...todo, completed: value }; }
return todo;
});
return todos;
};
export const removeCompleted = (list) => {
const todos = ArrangeList(list.filter((todo) => !todo.completed));
AddtoStorage(todos);
return todos;
};
export const CheckForm = (id, editFormIdList) => {
const form = editFormIdList.find((index) => index === id.toString());
return form;
};
export const AddRemoveEditForm = (id, editFormIdList) => {
const check = CheckForm(id, editFormIdList);
if (check) { return editFormIdList.filter((index) => index !== id.toString()); }
return [...editFormIdList, id];
};
export const removeUnCompleted = (list) => {
const todos = ArrangeList(list.filter((todo) => todo.completed));
AddtoStorage(todos);
return todos;
};
export const RemoveTodo = (id, todos) => {
const Todos = ArrangeList(todos.filter((todo) => todo.index.toString() !== id));
return Todos;
};
export const editTodos = (id, description, todos) => {
const todo = todos.find((t) => t.index.toString() === id);
const Todo = { ...todo, description };
const newTodos = todos.map((t) => (t.index.toString() === id ? Todo : t));
AddtoStorage(newTodos);
return newTodos;
};