How to Build a React Todo App with a Pomodoro Timer using Cosmic

Community Articles
Community Articles How to Build a React Todo App with a Pomodoro Timer using Cosmic

In this tutorial, I'm going to show you how to create a Todo list app with pomodort timer included using React and Cosmic. We will be using Cosmic npm package for implementing the basic CRUD for our objects and to retrieve data and media from Cosmic. Let's get started.

TL;DR

View the Demo
Download the GitHub repo

Prerequisites

You will be requiring to install Node JS and npm before starting. Make sure you already have them.

Getting Started

Doing everything using the existing git repo

First of all, you have to be sure you have node > 6.x and yarn installed, than run the following commands:

After successfull completion of the last command browser window will automatically open package.json will look like this.

Now the app has to be running on http://localhost:300

Let's setup webpack.config.js

Code written here is responsible for compiling React JS.

Setting up ./src/components/app/app.js

In this file we are creating the home page file. So in state we are keeping the following data.

  1. Form-> title : Responsible for new task input value
  2. List: Array of strings, here are saved all the tasks
  3. showNewTaskInput: Boolean value, responsible for show/hide the new task input
  4. notification: Current notification name, we also have types for notifications listed below as an object, here are sorted the names for the notification types.

We use the following methods in our Class:

  1. Constructor: We are setupping new Api service, this gonna be used to connect to the Cosmic API.
  2. ComponentWillMount: This is function which belongs to React component lifecycle, here we just call another method created by us.
  3. getData: Function which does a call to the API and updates the list of tasks, after what we reset the value of new task input using this.resetForm()
  4. createNotification: Function which gets a notification type as an argument and puts it in the state for further use
  5. onChange: Function is responsible to keep the new task title in the state.
  6. onSave: Function creates a new task using the Cosmic api.
  7. onStart: Function is responsible for starting the timer for specific task, it calls the Api to save the start time in the Cosmic's db.
  8. onDone: Function is responsible for setting the status of specific task to "Done".
  9. onUpdate: Function is responsible to update specific task's title.
  10. showNewTaskInput: Function shows new task input.
  11. resetForm: Function is responsible for cleaning the value of the new task input.
  12. render: In render we put our html, and call our functions mentioned above.

Setting up ./src/task-list/list-item/index.js


Inlist-item we are creating each task item


In state we are keeping 2 items:

  1. editing: If the title is currently in process of change
  2. title: Current title of the task

Below we 3 functions coming after. They will call the functions passed to component by props.

Next 2 functions have some logic in them. Here they are:

  1. onEdit: Function which is responsive for updating the state editing item.
  2. onChange: Function which changes the title item in the state.

Then we have 2 React component lifecycle methods:

  1. componentWillReceiveProps: In this function we are checking if component has recieved new props we are updating our local state.
  2. render: All the HTML code goes here. Where we call our functions mentioned above.

Setting up ./src/components/countdown/index.js


In this file we are using Moment JS for doing basic calculation for the time countdown.

We are all set up, you can run the application, and enjoy it.

You may also like


In this short walk-through, I show you how to add localization to your Cosmic Object Types.
The beauty of using a static site generator is that your backend can be completely separate. In this video, I switch from markdown files to Cosmic!
We recently released Cosmic Functions (public beta). We're excited to help teams build amazing modern products together with new serverless solutions.
In this tutorial I’ll demonstrate how to build an Authentication app using Angular 6 and Cosmic. Starting from scratch, learn how to build, configure and deploy this Angular6 Auth app to the Cosmic App Server for testing purposes.
In this article I’m going demonstrate how to publish new Objects containing survey responses in Cosmic as they are completed in Typeform. Click here to connect Typeform to Cosmic using Zapier.
An Object in Cosmic can be a page, a blog post, an author or anything you want it to be. Cosmic gives you the freedom to create and manage content openly and create your own data structure. Each Object allows for the creation of a title, slug, content and Metafields.

Get Started with Cosmic

Build personal projects for free. Add your team at unbeatable prices.
Start Building Talk to Sales