Code Monkey home page Code Monkey logo

react_todo-app-add-and-delete's Introduction

React Todo App Add and Delete

It is the second part of the React Todo App with API.

Take your code implemented for Loading todos and implement the ability to add and remove todos.

Here is the working example

❗️❗️❗️
Please implement only adding and deleting todos in addition to what was already implemented.

All the other features from the working version will be implemented in the next task.
❗️❗️❗️

Check the API Documentation

Adding a todo

Add a todo with the entered title on the form submit:

  • if the title is empty show the Title can't be empty notification at the bottom;
  • use your userId for the new todo;
  • send a POST request to the API (check the API Documentation)
  • disable the input until receiving a response from the API;
  • immediately after sending a request create a todo with id: 0 and save it to the tempTodo variable in the state (NOT to the todos array);
  • show an independent TodoItem after the list if tempTodo is not null;
  • temp TodoItem should have the loader (check the original markup);
  • in case of success add the todo created by the API to the array (take it from the POST response);
  • in case of an API error show Unable to add a todo notification at the bottom;
  • set tempTodo to null to hide the extra TodoItem;

Don't try to implement animations for adding or removing Todos (at least until you finish everything else). If you really fill confident to try, there is a hint at the end of the description.

Deleting todos

Remove a todo on TodoDeleteButton click:

  • covered the todo with the loader while wating for the API response;
  • remove the todo from the list on success;
  • in case of API error show Unable to delete a todo notification at the bottom (the todo must stay in the list);

Remove all the completed todos after the Clear completed button click:

  • the button should be visible only if there is at least 1 completed todo;
  • the deletion should work as a several individual deletions running at the same time;

Instructions

IF you want to implement smooth animations

Click here to see the hint

Use React Transition Group

<section className="todoapp__main" data-cy="TodoList">
  <TransitionGroup>
    {visibleTodos.map(todo => (
      <CSSTransition
        key={todo.id}
        timeout={300}
        classNames="item"
      >
        <TodoItem
          todo={todo}
          isProcessed={processings.includes(todo.id)}
          onDelete={() => deleteTodo(todo.id)}
          onUpdate={updateTodo}
        />
      </CSSTransition>
    ))}

    {creating && (
      <CSSTransition
        key={0}
        timeout={300}
        classNames="temp-item"
      >
        <TodoItem
          todo={{
            id: Math.random(),
            title,
            completed: false,
            userId: user.id,
          }}
          isProcessed
        />
      </CSSTransition>
    )}
  </TransitionGroup>
</section>

Here are the styles used in this example

.item-enter {
  max-height: 0;
}

.item-enter-active {
  overflow: hidden;
  max-height: 58px;
  transition: max-height 0.3s ease-in-out;
}

.item-exit {
  max-height: 58px;
}

.item-exit-active {
  overflow: hidden;
  max-height: 0;
  transition: max-height 0.3s ease-in-out;
}

.temp-item-enter {
  max-height: 0;
}

.temp-item-enter-active {
  overflow: hidden;
  max-height: 58px;
  transition: max-height 0.3s ease-in-out;
}

.temp-item-exit {
  max-height: 58px;
}

.temp-item-exit-active {
  transform: translateY(-58px);
  max-height: 0;
  opacity: 0;
  transition: 0.3s ease-in-out;
  transition-property: opacity, max-height, transform;
}

.has-error .temp-item-exit-active {
  transform: translateY(0);
  overflow: hidden;
}

react_todo-app-add-and-delete's People

Contributors

mgrinko avatar mhrynko avatar yuriiholiuk avatar

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.