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

Created Toast For Todo Actions #179

Open
wants to merge 1 commit 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
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h1 class="subtitle">Todo-List</h1>
</div>
</footer>

<div id="toast" class="toast"></div>
<script src="script.js"></script>
</body>
</html>
7 changes: 7 additions & 0 deletions package-lock.json

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

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,8 @@
"eslint": "^9.12.0",
"globals": "^15.11.0",
"prettier": "^3.3.3"
},
"dependencies": {
"to-do-list": "file:"
}
}
18 changes: 14 additions & 4 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ checkIcon.classList.add('fa-solid', 'fa-check');
document.querySelector('.js-name-input').addEventListener('input', (e) => {
let input = e.target.value;
if (input.length === 120) {
alert('max character limits exceeded');
showToast("Max characters reached");
}
});

Expand Down Expand Up @@ -57,9 +57,7 @@ function addTodo() {

// Validation checks
if (!name || !date || !time || !category || !priority) {
alert(
'Please fill in all fields: task, date, time, category, and priority.'
);
showToast("Provide required fields");
return;
}

Expand Down Expand Up @@ -93,6 +91,8 @@ function addTodo() {
// Save to localStorage
localStorage.setItem('todoList', JSON.stringify(todoList));

showToast('Todo saved successfully');

// Reset the inputs
clearInputs();

Expand All @@ -104,6 +104,7 @@ function deleteTodo(index) {
// Remove the specific todo from the list
todoList.splice(index, 1);
localStorage.setItem('todoList', JSON.stringify(todoList));
showToast('Todo deleted successfully');
updateTodoList();
}

Expand Down Expand Up @@ -311,3 +312,12 @@ document.addEventListener('DOMContentLoaded', () => {
.querySelector('.js-filter-input')
.addEventListener('change', filterTodos);
});

function showToast(message) {
var toast = document.getElementById("toast");
toast.className = "toast show";
toast.innerHTML = message;
setTimeout(function () {
toast.className = toast.className.replace("show", "hide");
}, 3000);
}
23 changes: 23 additions & 0 deletions style.css
Original file line number Diff line number Diff line change
Expand Up @@ -387,3 +387,26 @@ Animating title
height: fit-content;
max-height: 35vh;
}

.toast {
visibility: hidden;
min-width: 250px;
background-color: #333;
color: #fff;
text-align: center;
border-radius: 5px;
padding: 16px;
position: fixed;
z-index: 1;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
font-size: 17px;
opacity: 0;
transition: opacity 0.5s ease-in-out;
}

.toast.show {
visibility: visible;
opacity: 1;
}
Loading