clientjs/packages/annotation-dashboard-explorunivers/src/store.js
author ymh <ymh.work@gmail.com>
Fri, 14 Sep 2018 17:57:34 +0200
changeset 0 5f4fcbc80b37
child 4 df751568fda6
permissions -rw-r--r--
Create new repository to host all dashboard developments This project contains the commons components and all the dashboard instances
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
0
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     1
import React, { Component } from 'react';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     2
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     3
import thunkMiddleware from 'redux-thunk';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     4
import { Provider } from 'react-redux';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     5
import { createLogger } from 'redux-logger';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     6
import { createStore, applyMiddleware, compose } from 'redux';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     7
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     8
import { rootReducer, actions } from 'dashboard-components';
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
     9
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    10
const { fetchAnnotations } = actions;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    11
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    12
let middlewares = [thunkMiddleware];
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    13
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    14
if (process.env.NODE_ENV !== 'production') {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    15
  const loggerMiddleware = createLogger();
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    16
  middlewares = [...middlewares, loggerMiddleware];
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    17
}
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    18
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    19
/* eslint-disable no-underscore-dangle */
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    20
const composeEnhancers = window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ || compose;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    21
/* eslint-enable */
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    22
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    23
const store = createStore(
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    24
  rootReducer,
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    25
  composeEnhancers(applyMiddleware(...middlewares)),
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    26
);
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    27
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    28
export default WrappedComponent => class extends Component {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    29
  componentWillMount() {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    30
    const apiUrl = process.env.REACT_APP_API_URL;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    31
    const discussionUrl = process.env.REACT_APP_DISCUSSION_URL;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    32
    store.dispatch(fetchAnnotations(apiUrl, discussionUrl));
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    33
  }
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    34
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    35
  render() {
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    36
    return <Provider store={store}><WrappedComponent {...this.props} /></Provider>;
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    37
  }
5f4fcbc80b37 Create new repository to host all dashboard developments
ymh <ymh.work@gmail.com>
parents:
diff changeset
    38
};