Latest news about Bitcoin and all cryptocurrencies. Your daily crypto news habit.
In this tutorial, Iām going to show you how to create a Todo list app with pomodort timer included using React and Cosmic JS. We will be using Cosmic JS npm package for implementing the basic CRUD for our objects and to retrieve data and media from Cosmic JS. Letās getĀ started.
TL;DR
View the DemoDownload 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.
- Form-> titleĀ : Responsible for new task inputĀ value
- List: Array of strings, here are saved all theĀ tasks
- showNewTaskInput: Boolean value, responsible for show/hide the new taskĀ input
- 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:
- Constructor: We are setupping new Api service, this gonna be used to connect to the Cosmic JSĀ API.
- ComponentWillMount: This is function which belongs to React component lifecycle, here we just call another method created byĀ us.
- 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()
- createNotification: Function which gets a notification type as an argument and puts it in the state for furtherĀ use
- onChange: Function is responsible to keep the new task title in theĀ state.
- onSave: Function creates a new task using the Cosmic JSĀ api.
- 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.
- onDone: Function is responsible for setting the status of specific task toĀ āDoneā.
- onUpdate: Function is responsible to update specific taskāsĀ title.
- showNewTaskInput: Function shows new taskĀ input.
- resetForm: Function is responsible for cleaning the value of the new taskĀ input.
- 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:
- editing: If the title is currently in process ofĀ change
- 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:
- onEdit: Function which is responsive for updating the state editingĀ item.
- onChange: Function which changes the title item in theĀ state.
Then we have 2 React component lifecycle methods:
- componentWillReceiveProps: In this function we are checking if component has recieved new props we are updating our localĀ state.
- 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.
Conclusion
We are all set up, you can run the application, and enjoy it. If you have any questions, find me on CosmicĀ JS.
This article originally appears on CosmicĀ JS.
How to Build a React Todo App with a Pomodoro Timer using Cosmic JS was originally published in Hacker Noon on Medium, where people are continuing the conversation by highlighting and responding to this story.
Disclaimer
The views and opinions expressed in this article are solely those of the authors and do not reflect the views of Bitcoin Insider. Every investment and trading move involves risk - this is especially true for cryptocurrencies given their volatility. We strongly advise our readers to conduct their own research when making a decision.