Giter Site home page Giter Site logo

microverse-todo-list's People

Watchers

 avatar

microverse-todo-list's Issues

Self-assessment: JS best practices

> Simplicity

function buildTaskRightElement(task) {
const taskRightElement = createDivWithClass('todo-list-task-right');
const editElement = createElementWithClass('i', 'fa fa-ellipsis-v');
editElement.setAttribute('id', `edit-task-${task.index}`);
editElement.setAttribute('aria-hidden', 'true');
editElement.addEventListener('click', (e) => {
const targetElement = e.target;
const { parentElement } = targetElement;
const taskElement = parentElement.parentElement;
const taskIndex = targetElement.id.substring('edit-task-'.length);
const deleteElement = document.getElementById(`delete-task-${taskIndex}`);
taskElement.classList.add('editable');
targetElement.classList.add('hidden');
deleteElement.classList.remove('hidden');
const tasks = loadTasks();
const editableTask = tasks.filter((task) => task.index === parseInt(taskIndex, 10))[0];
const taskDescriptionInputElement = createElement('input');
taskDescriptionInputElement.setAttribute('type', 'text');
taskDescriptionInputElement.setAttribute('class', 'editable');
taskDescriptionInputElement.setAttribute('value', editableTask.description);
taskDescriptionInputElement.id = `task-description-${taskIndex}`;
const taskDescriptionElement = document.getElementById(`todo-list-task-description-${taskIndex}`);
const taskLeftElement = taskDescriptionElement.parentElement;
/* Remove description and add new input */
taskLeftElement.removeChild(taskDescriptionElement);
taskLeftElement.appendChild(taskDescriptionInputElement);
});
const deleteElement = createElementWithClass('i', 'fa fa-trash hidden');
deleteElement.setAttribute('id', `delete-task-${task.index}`);
deleteElement.setAttribute('aria-hidden', 'true');
deleteElement.addEventListener('click', (e) => {
const taskIndex = e.target.id.substring('delete-task-'.length);
let tasks = loadTasks();
tasks = tasks.filter((task) => task.index !== parseInt(taskIndex, 10));
let shiftedTasks = [];
for (let i = 0; i < tasks.length; i += 1) {
const task = tasks[i];
shiftedTasks = shiftedTasks.concat({
description: task.description,
completed: task.completed,
index: i + 1,
});
}
saveTasks(shiftedTasks);
displayTasks(); /* eslint-disable-line */
});
taskRightElement.appendChild(editElement);
taskRightElement.appendChild(deleteElement);
return taskRightElement;
}

This function could definitely be broken down into smaller functions.

Self-assessment: HTML and CSS best practices

No violations found:

  • HTML has proper use of semantic tags (there's a main tag)
  • !important is used only once
  • All element names and attributes are in lowercase
  • Attribute values (including the ones generated by JS) are quoted

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.