Git Product home page Git Product logo

fend19-js1-todolist's Introduction

FEND19 - JavaScript 1 - To Do List

preview

Description

A simple To Do application that lets you add and remove tasks as well as filter the list of existing tasks by category and description. Tasks that are overdue are highlighted in red.

ToDo list is saved in local storage and persists through browser shut down.

Implementation

When the page is loaded for the first time todo list is loaded from localStorage.

let toDoItems = JSON.parse(localStorage.getItem("todo"));

If no items are found in local storage an example list is loaded for the purpose of presenting the project.

if (!toDoItems || Object.keys(toDoItems).length === 0) {
  toDoItems = {
    1: {
      task: "clean house",
      deadline: "2020-12-02",
      category: "Misc"
    },

New tasks can only be added if task description is not empty

function createNewTask() {
  // task description can't be empty
  const textInput = document.querySelector("#newTaskInput");
  if (textInput.value.length === 0) {
    textInput.focus();
    textInput.classList.replace("borderWhite", "borderRed");
    return;
  }

and deadline timestamp does not refer to a point of time in the past.

// deadline can't be before current time
const dateInput = document.querySelector("#dateSelector");
if (dateInput.validity.valid === false) {
  dateInput.focus();
  return;
}

List of items is filtered by category and keyword if such was specified.

function drawFilteredList(toDoItems) {
  const filterField = document.querySelector("#filterInput");
  const selectedCategory = document.querySelector('input [name="categoryInputGroup"]:checked').value;
  const filteredItems = [];
  for (const index in toDoItems) {
    const item = toDoItems[index];
    const isCorrectCategory = selectedCategory === "All" || selectedCategory === item["category"];
    const includesKeyword = item["task"].toLowerCase().includes(filterField.value.toLowerCase());
    if (isCorrectCategory && includesKeyword) filteredItems[index] = item;
  }
  drawTodoList(filteredItems);
}

fend19-js1-todolist's People

Contributors

dmitrijv avatar

Stargazers

Mahmud Al Hakim avatar

Watchers

James Cloos avatar

Forkers

mahmudalhakim

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.