Skip to content

Commit

Permalink
feat: Add login check
Browse files Browse the repository at this point in the history
  • Loading branch information
mori-dev committed Dec 8, 2016
1 parent 5f18d76 commit 386b4f0
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
27 changes: 27 additions & 0 deletions src/containers/common/logged_in_required.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// @flow
import { connect } from 'react-redux';
// import { bindActionCreators } from 'redux';
import MESSAGES from '../../messages';


function mapStateToProps(state: Object): Object {
return {};
}

function mapDispatchToProps(dispatch: Function): Object {
return {
// someActions: bindActionCreators(someActions, dispatch),
};
}

export default function loggedInRequired(WrappedComponent: any) {
class loggedInRequiredWrappedComponent extends WrappedComponent {
componentWillMount() {
// if (!this.state.storeState.session.foobar) {
if (true) {
console.log(MESSAGES.LOG_IN_CHECK);
}
}
}
return connect(mapStateToProps, mapDispatchToProps)(loggedInRequiredWrappedComponent);
}
9 changes: 8 additions & 1 deletion src/containers/home_container.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// @flow
import React, { Component } from 'react';
import { connect } from 'react-redux';
import { compose } from 'redux';
import loggedInRequired from './common/logged_in_required';

function mapStateToProps(state: Object): Object {
return {};
Expand All @@ -21,4 +23,9 @@ class HomeContainer extends Component {
}
}

export default connect(mapStateToProps, mapDispatchToProps)(HomeContainer);
HomeContainer = compose(
loggedInRequired,
connect(mapStateToProps, mapDispatchToProps),
)(HomeContainer)

export default HomeContainer;
1 change: 1 addition & 0 deletions src/messages.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// @flow
const MESSAGES = {
OFFLINE_NOTIFICATION: 'オフラインです',
LOG_IN_CHECK: 'ログインチェックを行いました',
};

export default MESSAGES;

0 comments on commit 386b4f0

Please sign in to comment.