Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
  • Loading branch information
emrekurtarr committed Nov 6, 2021
1 parent 5bd51dc commit 6a05312
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Week2-TodoAppWithReact/todo-app-react/src/App.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,37 @@
import './App.css';

//Importing components
import Form from './components/Form/form';
import Todolist from './components/Todolist/todolist';

//Hooks
import {useState,useEffect} from 'react';

// My constant local storage key
const STORAGEKEYOFTODOS = "myTodos";

function App() {

//States
const [inputText,setInputText] = useState("");
const [todos,setTodos] = useState([]);
const [status,setStatus] = useState("all");
const [filteredTodos,setFilteredTodos] = useState([]);


//Events

//It is called only once when app is rendered
// for taking existing todos from local storage
// and showing in UI
useEffect(() => {
console.log("storage effect")
getTodosFromLocalStorage();
}, [])

useEffect(() => {
console.log("effect1")
if(status === "completed"){
console.log("status completed")
setFilteredTodos(todos.filter((todo) => todo.isCompleted === true))
}
else if(status === "uncompleted"){
console.log("status UNNcompleted")
setFilteredTodos(todos.filter((todo) => todo.isCompleted === false))
}
else{
Expand All @@ -35,15 +41,11 @@ function App() {
},[todos])

useEffect(() => {
console.log("effect2")
switch (status) {
case "completed":
console.log("status completed")
setFilteredTodos(todos.filter((todo) => todo.isCompleted === true))
break;
case "uncompleted":
console.log("status UNNcompleted")
//console.log(todos.filter((todo) => todo.isCompleted === false))
setFilteredTodos(todos.filter((todo) => todo.isCompleted === false))
break;
default:
Expand All @@ -52,9 +54,8 @@ function App() {
}
},[status])





const saveTodosToLocalStorage = () => {
localStorage.setItem(STORAGEKEYOFTODOS,JSON.stringify(todos))
}
Expand All @@ -72,7 +73,7 @@ function App() {
<div className="App">

<header >
<h1>Emre KURTAR's todo list</h1>
<h1>Emre KURTAR's To-Do</h1>
</header>
<Form
inputText = {inputText}
Expand Down

0 comments on commit 6a05312

Please sign in to comment.