-
Notifications
You must be signed in to change notification settings - Fork 4
sauravkr818 - Task 1 #1
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
base: main
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ const todoElement = (item, i) => { | |
| const elem = document.createElement("div"); | ||
| elem.id = item.id; | ||
| elem.innerHTML = ` | ||
| <div class="row py-2 pb-2 text-center"> | ||
| <div class="row py-2 text-center"> | ||
| <div class="col-3 text-center">${i + 1}</div> | ||
| <div class="col-3" id=${item.id}> | ||
| <input type="checkbox" onchange="markItem(event)" ${ | ||
|
|
@@ -44,9 +44,10 @@ document.getElementById("todo-form").addEventListener("submit", (event) => { | |
| if (itemName) { | ||
| todoList.push(generateTodoItem(itemName)); | ||
| renderList(); | ||
| saveTodo(); | ||
| const alert = ` | ||
| <div class="text-center alert alert-success alert-dismissible fade show shadow border-0" role="alert" data-aos="fade-down"> | ||
| <strong>Congratulations, your item has been added. Save Changes. | ||
| <strong>Congratulations, your item has been added. | ||
| <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
| </div>`; | ||
| $("#confirmation").html(alert); | ||
|
|
@@ -60,7 +61,7 @@ const markItem = (event) => { | |
| if (todoItem.id === itemId) { | ||
| todoItem.isDone = !todoItem.isDone; | ||
| renderList(); | ||
|
|
||
| saveTodo(); | ||
| return true; | ||
| } | ||
| }); | ||
|
|
@@ -89,7 +90,7 @@ const deleteItem = (event) => { | |
| }); | ||
| }; | ||
|
|
||
| const saveTodo = (e) => { | ||
| const saveTodo = () => { | ||
| localStorage.setItem("todoList", JSON.stringify(todoList)); // key and its value | ||
| const saveInfo = ` | ||
| <div class="text-center alert alert-primary alert-dismissible fade show shadow border-0" role="alert" data-aos="zoom-in-down"> | ||
|
|
@@ -104,22 +105,28 @@ const saveTodo = (e) => { | |
| }; | ||
|
|
||
| const clearTodo = () => { | ||
| const clearInfo = ` | ||
| if (todoList.length){ | ||
| const approveClear = confirm("Are you sure you want to delete your all items"); | ||
| if(approveClear){ | ||
| `${localStorage.removeItem("todoList")} | ||
| ${(todoList = [])} | ||
| ${renderList()}` | ||
| const clearInfo = ` | ||
| <div class="text-center alert alert-primary alert-dismissible fade show shadow border-0" role="alert" data-aos="zoom-in-down"> | ||
| <strong>${ | ||
| todoList.length > 0 | ||
| ? "Your items have been successfully removed." | ||
| : "Please add any item." | ||
| } | ||
| <strong>Your items have been successfully removed.</strong> | ||
| <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
| </div>`; | ||
| </div>`; | ||
| $("#save-info").html(clearInfo); | ||
| todoList.length > 0 // if array length is null then do not show confirm msg. | ||
| ? `${confirm("Are you sure you want to delete your all items")} | ||
| ${localStorage.removeItem("todoList")} | ||
| ${(todoList = [])} // array made empty | ||
| ${renderList()}` | ||
| : ""; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should not do this. This is not at all readable and may not get properly formatted by eslint or other formatters. Use a simple |
||
| } | ||
| } | ||
| else{ | ||
| const clearInfo = ` | ||
| <div class="text-center alert alert-primary alert-dismissible fade show shadow border-0" role="alert" data-aos="zoom-in-down"> | ||
| <strong>Please add any item</strong> | ||
| <button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> | ||
| </div>`; | ||
| $("#save-info").html(clearInfo); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You should avoid the use of JQuery or any other library for a simple task which can be easily done without it.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I used jQuery just to display confirmation messages to the user. Should I remove the display messages and keep it simple?
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can do it without jQuery
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay bhaiya give me some time. |
||
| } | ||
| }; | ||
|
|
||
| try { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no need to call functions inside template strings unless you are storing it in a variable.
And these statements do not return anything so it is of no use to call it in a template string
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay got it.