Commit 34c64b06 by Ajmal.S

header and todoform corrections

parent b320fbb1
...@@ -29,24 +29,18 @@ function App() { ...@@ -29,24 +29,18 @@ function App() {
} }
] ]
// const [todos, setTodos] = useState([]);
// const [editId, setEdit] = useState(false); // const [editId, setEdit] = useState(false);
// const [inputValue, setInputValue] = useState(""); // const [inputValue, setInputValue] = useState("");
// const handleEditChange = (id, text) => { const onEdit = (id, text) => {
// setEdit(id); console.log(id, text)
// setInputValue(text); };
// };
const onComplete = (id, text) => {
console.log(id, text)
}
// const addTodo = (todo) => {
// if (!todo.text || /^\s*$/.test(todo.text)) {
// alert('Please add a Todo')
// return;
// }
// const newTodos = [todo, ...todoData];
// setTodos(newTodos);
// console.log(newTodos);
// };
// const removeTodo = (id) => { // const removeTodo = (id) => {
// const removedArr = [...todos].filter((todoId) => todoId.id !== id); // const removedArr = [...todos].filter((todoId) => todoId.id !== id);
...@@ -93,11 +87,11 @@ function App() { ...@@ -93,11 +87,11 @@ function App() {
<> <>
<div className='task-main'> <div className='task-main'>
<Header count={todoData} /> <Header count={todoData.length} />
{/* {todoData.map((todos) => ( {todoData.map((todos) => (
<TodoItem key={todos.id} children={todos.text} complete={todos.isComplete}/> <TodoItem key={todos.id} todoId={todos.id} complete={todos.isComplete} onEdit={onEdit} onComplete={onComplete}>{todos.text}</TodoItem>
))} */} ))}
{/* <Todos todos={todos} {/* <Todos todos={todos}
completeTodo={completeTodo} completeTodo={completeTodo}
......
...@@ -3,7 +3,7 @@ import React from 'react'; ...@@ -3,7 +3,7 @@ import React from 'react';
const Header = ({ count }) => { const Header = ({ count }) => {
return ( return (
<div className='App'> <div className='App'>
<div className='task-head'><b>You have {count.length > 0 ? count.length : 'No'} {count.length <= 1 ? 'Todo' : 'Todos'}</b></div> <div className='task-head'><b>You have {count > 0 ? count : 'No'} {count <= 1 ? 'Todo' : 'Todos'}</b></div>
</div> </div>
) )
} }
......
import PropTypes from 'prop-types'; import PropTypes from 'prop-types';
import React, { useState } from 'react'; import React, { useState } from 'react';
function TodoForm(props) { function TodoForm() {
const [input, setInput] = useState(''); const [input, setInput] = useState('');
const [todos, setTodos] = useState([]);
const onChange = (e) => { const onChange = (e) => {
setInput(e.target.value); setInput(e.target.value);
}; };
const addTodo = (todo) => {
if (!todo.text || /^\s*$/.test(todo.text)) {
alert('Please add a Todo')
return;
}
const newTodos = [todo, ...todos];
setTodos(newTodos);
console.log('newTodos =>', newTodos);
};
const Submit = (e) => { const Submit = (e) => {
e.preventDefault(); e.preventDefault();
props.onSubmit({ addTodo({
id: Math.floor(Math.random() * 10000), id: Math.floor(Math.random() * 10000),
text: input, text: input,
isEdit: false, isEdit: false,
...@@ -29,9 +41,7 @@ function TodoForm(props) { ...@@ -29,9 +41,7 @@ function TodoForm(props) {
onChange={onChange} onChange={onChange}
/> />
</div> </div>
<button className='btn' onClick={Submit}> <button className='btn'>Submit</button>
Submit
</button>
</div> </div>
</form> </form>
); );
......
import React from 'react' import React from 'react'
const TodoItem = ({ children, complete }) => { const TodoItem = ({ todoId, children, complete, onEdit, onComplete }) => {
const className = `todos ${complete ? 't-complete' : ''}` const className = `todos ${complete ? 't-complete' : ''}`
...@@ -8,8 +8,8 @@ const TodoItem = ({ children, complete }) => { ...@@ -8,8 +8,8 @@ const TodoItem = ({ children, complete }) => {
<div className="task"> <div className="task">
<div className="task-body-content"> <div className="task-body-content">
<div style={{ display: 'flex' }}> <div style={{ display: 'flex' }}>
<input type='checkbox' defaultChecked={complete}></input> <input type='checkbox' defaultChecked={complete} onChange={() => onComplete(todoId, complete)}></input>
<span style={{ cursor: 'pointer' }} className={className}>{children}</span> <span style={{ cursor: 'pointer' }} className={className} onClick={() => onEdit(todoId, children)}>{children}</span>
</div> </div>
</div> </div>
</div > </div >
......
...@@ -23,7 +23,7 @@ body { ...@@ -23,7 +23,7 @@ body {
.add-form { .add-form {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
margin: 10px 10px 10px 5px; margin: 30px 10px 10px 5px;
} }
.form-control input { .form-control input {
...@@ -58,11 +58,9 @@ body { ...@@ -58,11 +58,9 @@ body {
display: flex; display: flex;
justify-content: space-between; justify-content: space-between;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
padding: 5px 12px; padding: 5px 6px;
}
.task-body-content:last-child{
border: none;
} }
.t-complete { .t-complete {
text-decoration: line-through; text-decoration: line-through;
} }
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment