Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kindly review - Ravi Bhushan #2

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 4 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@
"dependencies": {
"react": "^18",
"react-dom": "^18",
"next": "14.2.6"
"next": "14.2.6",
"react-toastify": "10.0.5"
},
"devDependencies": {
"typescript": "^5",
"@types/node": "^20",
"@types/react": "^18",
"@types/react-dom": "^18"
"@types/react-dom": "^18",
"react-toastify": "10.0.5"
}
}
21 changes: 19 additions & 2 deletions src/components/AddTodoForm.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React, { useState } from "react";
import React, {useState} from "react";
import {ToastContainer, Bounce, toast} from "react-toastify";
import "react-toastify/dist/ReactToastify.css";

interface AddTodoFormProps {
addTodo: (title: string, desc: string) => void;
Expand All @@ -8,21 +10,35 @@ interface AddTodoFormProps {
* AddTodoForm: Create two input fields for title, and description string fields
* As well as a submit button which creates the new To Do via addTodo
*/
function AddTodoForm({ addTodo }: AddTodoFormProps) {
function AddTodoForm({addTodo}: AddTodoFormProps) {
const [title, setTitle] = useState<string>('');
const [desc, setDesc] = useState<string>('');

const handleSubmit = (event: React.FormEvent) => {
event.preventDefault();
addTodo(title, desc);
setTitle('');
setDesc('');
var toasterMesage = "Added TODO with title [" + title + "]";
toast(toasterMesage, {
position: "top-right",
autoClose: 5000,
hideProgressBar: false,
closeOnClick: true,
pauseOnHover: true,
draggable: true,
progress: undefined,
theme: "light",
transition: Bounce,
});
};

return (
<form onSubmit={handleSubmit}>
<div>
<label>Title:</label>
<input
value={title}
type="text"
placeholder="Provide a title for the new To Do"
onChange={(e) => setTitle(e.target.value)}
Expand All @@ -39,6 +55,7 @@ function AddTodoForm({ addTodo }: AddTodoFormProps) {
/>
</div>
<button type="submit">Add To Do</button>
<ToastContainer/>
</form>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/components/TodoList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ function TodoList({ todos, deleteTodo, toggleComplete, toggleUrgent }: TodoListP
<ul>
{todos.map((todo) => (
<TodoItem
key={todo.id}
todo={todo}
deleteTodo={deleteTodo}
toggleComplete={toggleComplete}
Expand Down
15 changes: 4 additions & 11 deletions src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,11 @@ export default function Home() {
isUrgent: false,
};

todos.push(newTodo);
setTodos(todos);
setTodos([...todos, newTodo]);
};

const deleteTodo = (id: number) => {
setTodos(todos.filter((todo) => todo.id === id));
setTodos(todos.filter((todo) => todo.id !== id));
};

const toggleProperty = useCallback((id: number, property: keyof Pick<Todo, 'isCompleted' | 'isUrgent'>) => {
Expand All @@ -48,7 +47,7 @@ export default function Home() {
return todo;
});
setTodos(updatedTodos);
}, [setTodos]);
}, [todos, setTodos]);

const displayTodoList = (todoList:Todo[]) => {
return (
Expand All @@ -62,13 +61,7 @@ export default function Home() {
};

const displayTodos = (displayUrgent: boolean) => {
return displayTodoList(todos.filter((x) => {
if (displayUrgent) {
return !x.isCompleted && x.isUrgent === displayUrgent;
} else {
return !x.isCompleted && x.isUrgent !== displayUrgent;
}
}));
return displayTodoList(todos.filter((x) => !x.isCompleted && x.isUrgent === displayUrgent));
};

const displayComplete = () => {
Expand Down