Build Status

View DEMO

Installation

git clone https://github.com/agl0809/react-location-history-player/
cd react-location-history-player
npm install

Available scripts

Runs the app in the development mode:

npm start

Open http://localhost:3000 to view it in the browser.
The page will reload if you make edits.You will also see any lint errors in the console.

Launches the test runner in the interactive watch mode:

npm test

Builds the app for production to the build folder:

npm run build

It correctly bundles React in production mode and optimizes the build for the best performance.
The build is minified and the file names include the hashes.

Settings

There are two different ways to set up the data provided in constants.js

Firebase service
By default Firebase service example will be used.

export const JSON_FILE_URL = 'https://api-project-923029851043.firebaseio.com/locations.json';

Google Takeout
Use a specific data file downloading the location history JSON file. Then move it to /public project folder .

export const JSON_FILE_URL = '/YOUR_FILE_NAME.json';

Code Style

Installation

Adding prettier package

npm install prettier

Run the following command in the project directory to install Airbnb eslint

$ (
  export PKG=eslint-config-airbnb;
  npm info "$PKG@latest" peerDependencies --json | command sed 's/[\{\},]//g ; s/: /@/g' | xargs npm install --save-dev "$PKG@latest"
)

Create .eslintrc.js in root folder

module.exports = {
  'env': {
    'browser': true,
    'jest': true,
    'es6': true,
    'node': true,
  },
  'extends': [
    'airbnb',
    'prettier',
  ],
  'plugins': [
    'prettier',
  ],
  'rules': {
    'prettier/prettier': ['error', {
      'singleQuote': true
    }],
  'react/jsx-filename-extension': [1, { 'extensions': ['.js', '.jsx'] }]
  },
  'parserOptions': {
    'ecmaFeatures': {
      'jsx': true,
    }
  }
}

Usage

Linting code

node_modules/.bin/eslint ./src

Fixing some errors

node_modules/.bin/eslint --fix ./src

Code Style Guide

Airbnb React/JSX Style Guide

Refs

Formating code automatically - CRA docs

displaying lint output in the editor - create-react-app docs

Create React App: Linting all the things

Set up create-react-app with Redux, React Router, Redux Thunk, Prettier, SCSS, Airbnb eslint, Standard stylelint, and CSS modules

Heroku Continuous Integration

Installation

The Heroku Command Line Interface is a tool for creating and managing Heroku apps from the command line, built with node.js and open source.

Create a new app

Creating a new heroku app using create-react-app-buildpack.

heroku create $APP_NAME --buildpack https://github.com/mars/create-react-app-buildpack.git

Update the heroku app

Running deploy process.

git push heroku master

The browser will show the app hosted by Heroku.

heroku open

Installation

Adding latest version using CLI in the project

npm install --save material-ui

React-Tap-Event-Plugin

Some components use react-tap-event-plugin to listen for touch events because onClick is not fast enough. It’s not needed for versions 0.19.0 and higher.

import injectTapEventPlugin from 'react-tap-event-plugin';
 
injectTapEventPlugin();

Roboto Font

Material-UI was designed with the Roboto font in mind. We include it in index.html.

    <script>
      var WebFontConfig = {
        google: { families: [ 'Roboto:400,300,500:latin' ] }
      };
      (function() {
        var wf = document.createElement('script');
        wf.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1/webfont.js';
        wf.type = 'text/javascript';
        wf.async = 'true';
        var s = document.getElementsByTagName('script')[0];
        s.parentNode.insertBefore(wf, s);
      })();
    </script>

Material-ui | official site | github repository | npm package |
React components that implement Google’s Material Design

Material Design | official site | guidelines |
Material Design is a unified system that combines theory, resources, and tools for crafting digital experiences.

Scaffolding

The project was scaffolded using create-react-app

Testing react components

Shadow Renderer

React Doc

Shallow rendering lets you render a component “one level deep”. The child components are not instantiated or rendered. This does not require a DOM.

Installing

 npm i --save-dev react-test-renderer

Usage

import ShallowRenderer from 'react-test-renderer/shallow';
import LocationHistoryMap from 'components/LocationHistoryMap';
import GoogleMap from 'google-map-react';
//...

const GM_ZOOM = 1;
const renderer = new ShallowRenderer();

renderer.render(<LocationHistoryMap zoom={GM_ZOOM}/>);

const result = renderer.getRenderOutput();

expect(result.props.className).toBe('map');
expect(result.props.children.type).toBe(GoogleMap);
expect(result.props.children.props.defaultZoom).toBe(GM_ZOOM);

Test Renderer

React doc | npm | github

Provides a React renderer that can be used to render React components to pure JavaScript objects, without depending on the DOM.

This package makes it easy to grab a snapshot of the platform view hierarchy (similar to a DOM tree) rendered by a React DOM or React Native component without using a browser or jsdom.

Installing

 npm i --save-dev react-test-renderer

Usage

import TestRenderer from 'react-test-renderer';

You can use Jest’s snapshot testing feature to automatically save a copy of the JSON tree to a file and check in your tests that it hasn’t changed.

const renderer = TestRenderer.create(<LocationHistoryMap/>);

renderer.toJSON();

You can also traverse the output to find specific nodes and make assertions about them.

import TestRenderer from 'react-test-renderer';
import LocationHistoryMap from 'components/LocationHistoryMap';
import GoogleMap from 'google-map-react';

const renderer = TestRenderer.create(<LocationHistoryMap />);
const instance = renderer.root;

expect(instance.findByType(GoogleMap).props.defaultZoom).toBe(13);

ReactTestUtils | React doc |

Makes it easy to test React components in the testing framework of your choice.

Testing React apps with Jest

Third party dependencies