MCPcopy Index your code
hub / github.com/CodeWithHarry/Sigma-Web-Dev-Course / App

Function App

Video 114/src/App.jsx:7–110  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

5import { v4 as uuidv4 } from 'uuid';
6
7function App() {
8
9 const [todo, setTodo] = useState("")
10 const [todos, setTodos] = useState([])
11 const [showFinished, setshowFinished] = useState(true)
12
13 useEffect(() => {
14 let todoString = localStorage.getItem("todos")
15 if(todoString){
16 let todos = JSON.parse(localStorage.getItem("todos"))
17 setTodos(todos)
18 }
19 }, [])
20
21
22 const saveToLS = (params) => {
23 localStorage.setItem("todos", JSON.stringify(todos))
24 }
25
26 const toggleFinished = (e) => {
27 setshowFinished(!showFinished)
28 }
29
30
31
32
33 const handleEdit = (e, id)=>{
34 let t = todos.filter(i=>i.id === id)
35 setTodo(t[0].todo)
36 let newTodos = todos.filter(item=>{
37 return item.id!==id
38 });
39 setTodos(newTodos)
40 saveToLS()
41 }
42
43 const handleDelete= (e, id)=>{
44 let newTodos = todos.filter(item=>{
45 return item.id!==id
46 });
47 setTodos(newTodos)
48 saveToLS()
49 }
50
51 const handleAdd= ()=>{
52 setTodos([...todos, {id: uuidv4(), todo, isCompleted: false}])
53 setTodo("")
54 saveToLS()
55 }
56
57 const handleChange= (e)=>{
58 setTodo(e.target.value)
59 }
60
61 const handleCheckbox = (e) => {
62 let id = e.target.name;
63 let index = todos.findIndex(item=>{
64 return item.id === id;

Callers

nothing calls this directly

Calls 2

handleEditFunction · 0.85
handleDeleteFunction · 0.85

Tested by

no test coverage detected