Skip to content

Commit

Permalink
feat: add offline notification (by console.log
Browse files Browse the repository at this point in the history
  • Loading branch information
mori-dev committed Dec 8, 2016
1 parent 5e1429d commit 5f18d76
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions src/messages.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// @flow
const MESSAGES = {
OFFLINE_NOTIFICATION: 'オフラインです',
};

export default MESSAGES;
18 changes: 18 additions & 0 deletions src/middlewares/network_status_checker.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
// @flow
import * as ActionTypes from '../actions/action_types';
import MESSAGES from '../messages';

export default (store: any) => (next: any) => (action: any) => {
/* eslint-disable guard-for-in */
for (const key in ActionTypes) {
if ((ActionTypes[key] === action.type) && action.type.match(/.*_START$/)) {
if (!navigator.onLine) {
console.log(MESSAGES.OFFLINE_NOTIFICATION);
// TODO: モーダルダイアログでメッセージを表示する
// return next(openAlertDialog(MESSAGES.OFFLINE_NOTIFICATION));
return null;
}
}
}
return next(action);
};
6 changes: 4 additions & 2 deletions src/store/configure_store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,16 @@ import { routerMiddleware } from 'react-router-redux';
import { browserHistory } from 'react-router';
import rootSaga from '../sagas/index';
import rootReducer from '../reducers';
import responseCamelizer from '../middleware/response_camelizer';
import requestDecamelizer from '../middleware/request_decamelizer';
import responseCamelizer from '../middlewares/response_camelizer';
import requestDecamelizer from '../middlewares/request_decamelizer';
import networkStatusChecker from '../middlewares/network_status_checker';

const routing = routerMiddleware(browserHistory);
const sagaMiddleware = createSagaMiddleware();
const enhancer = compose(
applyMiddleware(
routing,
networkStatusChecker, // sagaMiddleware より前に置かないと _START をキャンセルしても API コールが行われる
sagaMiddleware,
responseCamelizer,
requestDecamelizer,
Expand Down

0 comments on commit 5f18d76

Please sign in to comment.