Skip to content

A To-Do application that allows users to add, edit, and delete tasks with a title, date, and description. The app features a simple and responsive design for efficient task management.

Notifications You must be signed in to change notification settings

Yashi-Singh-1/To-Do-App

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

TODO App Solution

This is a solution to the Learn localStorage by Building a Todo App challenge on FreeCodeCamp. This challenge helps you understand how to use localStorage to persist data in a web application.

Table of contents

Overview

The challenge

Users should be able to:

  • Add new tasks with a title, date, and description
  • View a list of added tasks
  • Edit existing tasks
  • Delete tasks
  • The data should persist even after a page reload using localStorage

Screenshot

Preview

Links

My process

Built with

  • Semantic HTML5 markup
  • CSS custom properties
  • Flexbox
  • JavaScript (ES6)
  • localStorage

What I learned

Working on this project reinforced my understanding of:

  • localStorage: How to store and retrieve data in a web application.
  • JavaScript DOM Manipulation: How to dynamically create, update, and remove elements.
  • Event Handling: Managing form submissions, button clicks, and dialog interactions.
  • Conditional Logic: Handling unsaved changes and confirming user actions with dialogs.

Code snippets I’m proud of:

const addOrUpdateTask = () => {
  const dataArrIndex = taskData.findIndex((item) => item.id === currentTask.id);
  const taskObj = {
    id: `${titleInput.value.toLowerCase().split(" ").join("-")}-${Date.now()}`,
    title: titleInput.value,
    date: dateInput.value,
    description: descriptionInput.value,
  };

  if (dataArrIndex === -1) {
    taskData.unshift(taskObj);
  } else {
    taskData[dataArrIndex] = taskObj;
  }

  localStorage.setItem("data", JSON.stringify(taskData));
  updateTaskContainer();
  reset();
};
.task-form {
  display: flex;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background-color: var(--white);
  border-radius: 5px;
  padding: 15px;
  width: 300px;
  height: 350px;
  flex-direction: column;
  justify-content: space-between;
  overflow: auto;
}
const editTask = (buttonEl) => {
    const dataArrIndex = taskData.findIndex(
    (item) => item.id === buttonEl.parentElement.id
  );

  currentTask = taskData[dataArrIndex];

  titleInput.value = currentTask.title;
  dateInput.value = currentTask.date;
  descriptionInput.value = currentTask.description;

  addOrUpdateTaskBtn.innerText = "Update Task";

  taskForm.classList.toggle("hidden");  
}

Continued development

In future projects, I aim to:

  • Implement Advanced Features: Adding task prioritization, categories, or tags.
  • Explore More Storage Options: Such as session storage or IndexedDB for more complex scenarios.
  • Improve UI/UX: Enhancing the form with better validation and user feedback.

Useful resources

Author

Acknowledgments

A special thank you to FreeCodeCamp for providing this challenge. It was a great opportunity to practice JavaScript and understand localStorage. Also, thanks to the community for their support and feedback. Lastly, a shout-out to MDN Web Docs for their comprehensive documentation and tutorials.