Skip to content

Commit

Permalink
components
Browse files Browse the repository at this point in the history
components
TodoList
TodoItem
InputForm
  • Loading branch information
EuJinnLucaShow committed Nov 25, 2023
1 parent dfa3b59 commit b3a1a34
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 59 deletions.
Binary file modified public/favicon.ico
Binary file not shown.
28 changes: 1 addition & 27 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,13 @@
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<!--
manifest.json provides metadata used when your web app is installed on a
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>Todo App</title>
</head>

<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.

You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
<div id="root"></div>

To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>

</html>
49 changes: 44 additions & 5 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
import InputForm from './components/InputForm'
import InputForm from 'components/InputForm';
import TodoList from 'components/TodoList';
import { useState } from 'react';

const App = () => {
const [tasks, setTasks] = useState([]);
const [inputValue, setInputValue] = useState('');

const addTask = () => {
if (inputValue.trim() !== '') {
const newTask = {
id: tasks.length + 1,
title: inputValue,
completed: false,
};
setTasks([...tasks, newTask]);
setInputValue('');
}
};

const deleteTask = taskId => {
const updatedTasks = tasks.filter(task => task.id !== taskId);
setTasks(updatedTasks);
};

const toggleTaskStatus = taskId => {
const updatedTasks = tasks.map(task =>
task.id === taskId ? { ...task, completed: !task.completed } : task,
);
setTasks(updatedTasks);
};

function App() {
return (
<div style={{display: 'flex', justifyContent: 'center'}}>
<InputForm/>
<div className="todo-app">
<h1>TODO List</h1>
<InputForm
inputValue={inputValue}
setInputValue={setInputValue}
addTask={addTask}
/>
<TodoList
tasks={tasks}
toggleTaskStatus={toggleTaskStatus}
deleteTask={deleteTask}
/>
</div>
);
}
};

export default App;
21 changes: 10 additions & 11 deletions src/components/InputForm.jsx
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import React from 'react';

const InputForm = () => {

const InputForm = ({ inputValue, setInputValue, addTask }) => {
return (
<form onSubmit={''}>
<h3 style={{ display: 'flex', justifyContent: 'center'}}>To-Do</h3>
<div className="add-task">
<input
type="text"
value={""}
onChange={''}
required
type="text"
value={inputValue}
onChange={e => setInputValue(e.target.value)}
placeholder="Enter task..."
/>
<button type="submit">Add</button>
</form>
<button onClick={addTask}>Add Task</button>
</div>
);
};

export default InputForm;
export default InputForm;
25 changes: 9 additions & 16 deletions src/components/TodoItem.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
import React from 'react';

const TodoItem = ({ todo, onDelete, onEdit }) => {
const { id, title, completed } = todo;

const handleDelete = () => {
onDelete(id);
};

const handleEdit = () => {
onEdit(id);
};

const TodoItem = ({ task, toggleTaskStatus, deleteTask }) => {
return (
<div className="todo-item">
<input type="checkbox" checked={completed} onChange={() => {}} />
<p className={completed ? 'completed' : ''}>{title}</p>
<button onClick={handleEdit}>Edit</button>
<button onClick={handleDelete}>Delete</button>
<div className="task">
<span
style={{ textDecoration: task.completed ? 'line-through' : 'none' }}
onClick={() => toggleTaskStatus(task.id)}
>
{task.title}
</span>
<button onClick={() => deleteTask(task.id)}>Delete</button>
</div>
);
};
Expand Down
19 changes: 19 additions & 0 deletions src/components/TodoList.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import TodoItem from './TodoItem';

const TodoList = ({ tasks, toggleTaskStatus, deleteTask }) => {
return (
<div className="tasks">
{tasks.map(task => (
<TodoItem
key={task.id}
task={task}
toggleTaskStatus={toggleTaskStatus}
deleteTask={deleteTask}
/>
))}
</div>
);
};

export default TodoList;
6 changes: 6 additions & 0 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,9 @@ code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

.todo-app {
display: flex;
flex-direction: column;
align-items: center;
}

0 comments on commit b3a1a34

Please sign in to comment.