Skip to content

Commit

Permalink
Merge pull request #65 from PraveenMp/feature/changes-1
Browse files Browse the repository at this point in the history
Some Changes to To-Do App
  • Loading branch information
PraveenMp authored Jul 15, 2024
2 parents 5046358 + 7d47cfd commit 1f6a7fc
Show file tree
Hide file tree
Showing 12 changed files with 100 additions and 63 deletions.
1 change: 1 addition & 0 deletions to-do/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
118 changes: 70 additions & 48 deletions to-do/src/components/todo/TodoList.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import React, { useState, useEffect } from "react";

const TodoApp = () => {
const [tasks, setTasks] = useState([]);

Expand All @@ -12,11 +11,12 @@ const TodoApp = () => {
localStorage.setItem("tasks", JSON.stringify(tasks));
}, [tasks]);

const addTask = (taskText) => {
const addTask = (taskText, taskCategory) => {
const newTask = {
id: Date.now(),
text: taskText,
date: new Date().toISOString(),
category: taskCategory,
new: true,
inProgress: false,
completed: false,
Expand Down Expand Up @@ -51,8 +51,10 @@ const TodoApp = () => {

return (
<div className="container mt-5">
<h4>Praveen To-Do List</h4>
<TodoForm addTask={addTask} />
<h4 className="text-center mb-4">Praveen To-Do List</h4>
<div className="form-body mb-4">
<TodoForm addTask={addTask} />
</div>
<TodoList
tasks={tasks}
onCheckboxChange={handleCheckboxChange}
Expand All @@ -64,28 +66,36 @@ const TodoApp = () => {

const TodoForm = ({ addTask }) => {
const [taskText, setTaskText] = useState("");
const [taskCategory, setTaskCategory] = useState("Personal");

const handleSubmit = (e) => {
e.preventDefault();
if (!taskText.trim()) return;
addTask(taskText);
addTask(taskText, taskCategory);
setTaskText("");
setTaskCategory("Personal");
};





return (
<form onSubmit={handleSubmit}>
<div className="input-group mb-3">
<form onSubmit={handleSubmit} className="table-body-wrapper">
<div className="input-group">
<input
type="text"
className="form-control"
placeholder="Enter a new task"
value={taskText}
onChange={(e) => setTaskText(e.target.value)}
/>
<select
className="form-select"
value={taskCategory}
onChange={(e) => setTaskCategory(e.target.value)}
>
<option value="Personal">Personal</option>
<option value="Office">Office</option>
<option value="Home">Home</option>
<option value="Others">Others</option>
</select>
<button className="btn btn-primary" type="submit">
Add Task
</button>
Expand All @@ -94,44 +104,56 @@ const TodoForm = ({ addTask }) => {
);
};

const TodoList = ({ tasks, onCheckboxChange, onDelete }) => {
const TodoList = ({ tasks, onCheckboxChange, onDelete }) => {
const categories = ["Personal", "Office", "Home", "Others"];

return (
<table className="table">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">Task</th>
<th scope="col">Date</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{tasks.map((task, index) => (
<tr key={task.id}>
<th scope="row">{index + 1}</th>
<td>{task.text}</td>
<td>{new Date(task.date).toLocaleString()}</td>
<td>
<input
type="checkbox"
checked={task.completed}
onChange={() => onCheckboxChange(task.id)}
/>
{task.completed ? "Completed" : "In Progress"}
</td>
<td>
<button
className="btn btn-danger"
onClick={() => onDelete(task.id)}
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
<div>
{categories.map((category) => (
<div key={category} className="mb-4 table-body-wrapper">
<h5>{category}</h5>
<hr />
<table className="table">
<thead className="thead-dark">
<tr>
<th scope="col">#</th>
<th scope="col">Task</th>
<th scope="col">Date</th>
<th scope="col">Status</th>
<th scope="col">Actions</th>
</tr>
</thead>
<tbody>
{tasks
.filter((task) => task.category === category)
.map((task, index) => (
<tr key={task.id}>
<th scope="row">{index + 1}</th>
<td>{task.text}</td>
<td>{new Date(task.date).toLocaleString()}</td>
<td>
<input
type="checkbox"
checked={task.completed}
onChange={() => onCheckboxChange(task.id)}
/>
{task.completed ? "Completed" : "In Progress"}
</td>
<td>
<button
className="btn btn-danger btn-sm"
onClick={() => onDelete(task.id)}
>
Delete
</button>
</td>
</tr>
))}
</tbody>
</table>
</div>
))}
</div>
);
};

Expand Down
12 changes: 12 additions & 0 deletions to-do/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,21 @@ body {
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
background-color: #ccc;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;
}

.table-body-wrapper {
border: 1px solid #ccc;
border-radius: 15px;
padding: 15px;
background: #fff;
}

#root, .App, html {
background: #fbfbfb;
}
12 changes: 6 additions & 6 deletions todo/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"files": {
"main.css": "/todo/static/css/main.cc0e798d.css",
"main.js": "/todo/static/js/main.20573aeb.js",
"main.css": "/todo/static/css/main.82fc0197.css",
"main.js": "/todo/static/js/main.da563c78.js",
"static/js/787.c6a9a21d.chunk.js": "/todo/static/js/787.c6a9a21d.chunk.js",
"index.html": "/todo/index.html",
"main.cc0e798d.css.map": "/todo/static/css/main.cc0e798d.css.map",
"main.20573aeb.js.map": "/todo/static/js/main.20573aeb.js.map",
"main.82fc0197.css.map": "/todo/static/css/main.82fc0197.css.map",
"main.da563c78.js.map": "/todo/static/js/main.da563c78.js.map",
"787.c6a9a21d.chunk.js.map": "/todo/static/js/787.c6a9a21d.chunk.js.map"
},
"entrypoints": [
"static/css/main.cc0e798d.css",
"static/js/main.20573aeb.js"
"static/css/main.82fc0197.css",
"static/js/main.da563c78.js"
]
}
6 changes: 4 additions & 2 deletions todo/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@
<link rel="apple-touch-icon" href="/todo/logo192.png" />
<link rel="manifest" href="/todo/manifest.json" />
<title>React App</title>
<script defer="defer" src="/todo/static/js/main.20573aeb.js"></script>
<link href="/todo/static/css/main.cc0e798d.css" rel="stylesheet">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"
integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
<script defer="defer" src="/todo/static/js/main.da563c78.js"></script>
<link href="/todo/static/css/main.82fc0197.css" rel="stylesheet">
</head>

<body><noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions todo/static/css/main.82fc0197.css.map

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion todo/static/css/main.cc0e798d.css.map

This file was deleted.

1 change: 0 additions & 1 deletion todo/static/js/main.20573aeb.js.map

This file was deleted.

Large diffs are not rendered by default.

File renamed without changes.
1 change: 1 addition & 0 deletions todo/static/js/main.da563c78.js.map

Large diffs are not rendered by default.

0 comments on commit 1f6a7fc

Please sign in to comment.