From cd5496a66afd29915e3f2d2c31665b522b56cb95 Mon Sep 17 00:00:00 2001 From: Beka Tomashvili Date: Wed, 16 Nov 2016 03:57:13 +0400 Subject: [PATCH 1/4] changed eslint config --- .eslintrc | 1 + src/app/components/user/change_password.jsx | 103 ++++++++------- src/app/components/user/login.jsx | 136 ++++++++++---------- src/app/components/user/register.jsx | 132 ++++++++++--------- src/app/utils/authenticated.js | 6 +- 5 files changed, 196 insertions(+), 182 deletions(-) diff --git a/.eslintrc b/.eslintrc index 9f6fb2d..e212289 100644 --- a/.eslintrc +++ b/.eslintrc @@ -8,6 +8,7 @@ "rules": { "max-len": ["warn", 120], "indent": ["warn", 4], + "semi": [2, "never"], "react/jsx-indent": ["warn", 4] } } \ No newline at end of file diff --git a/src/app/components/user/change_password.jsx b/src/app/components/user/change_password.jsx index 1f17a1e..e977870 100644 --- a/src/app/components/user/change_password.jsx +++ b/src/app/components/user/change_password.jsx @@ -1,68 +1,71 @@ -import React, { Component } from 'react'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -import { changePassword } from '../../actions/firebase_actions'; +import React, { Component } from 'react' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import { changePassword } from '../../actions/firebase_actions' class ChangePassword extends Component { - constructor(props) { - super(props); - this.onFormSubmit = this.onFormSubmit.bind(this); - this.state = { - message: '', - }; - } + constructor(props) { + super(props) + this.onFormSubmit = this.onFormSubmit.bind(this) + this.state = { + message: '', + } + } - onFormSubmit(event) { - event.preventDefault(); - let password = this.refs.password.value; - let repeatPassword = this.refs.repeatPassword.value; - if (password !== repeatPassword) { - this.setState({ - message: 'Please password must match!', - }); - } else { - this.props.changePassword(password).then((data) => { - if (data.payload.errorCode) - this.setState({ message: data.payload.errorMessage }); - else - this.setState({ message: 'Password was changed!' }); - }); + onFormSubmit(event) { + event.preventDefault() + const password = this.refs.password.value + const repeatPassword = this.refs.repeatPassword.value + if (password !== repeatPassword) { + this.setState({ + message: 'Please password must match!', + }) + } else { + this.props.changePassword(password).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + this.setState({ message: 'Password was changed!' }) + } + }) + } } - } render() { - return ( -
-

Change Password

-
{this.state.message}
-
- - -
-
- - + return ( + +

Change Password

+
{this.state.message}
+
+ + +
+
+ + -
- - - ); - } +
+ + + ) + } } function mapDispatchToProps(dispatch) { - return bindActionCreators({ changePassword }, dispatch); + return bindActionCreators({ changePassword }, dispatch) } function mapStateToProps(state) { - return { currentUser: state.currentUser }; + return { currentUser: state.currentUser } } -export default connect(mapStateToProps, mapDispatchToProps)(ChangePassword); +export default connect(mapStateToProps, mapDispatchToProps)(ChangePassword) diff --git a/src/app/components/user/login.jsx b/src/app/components/user/login.jsx index ad7558b..670e8fe 100644 --- a/src/app/components/user/login.jsx +++ b/src/app/components/user/login.jsx @@ -7,100 +7,102 @@ import { loginUser, fetchUser, loginWithProvider } from '../../actions/firebase_ class UserLogin extends Component { - constructor(props) { - super(props); - this.onFormSubmit = this.onFormSubmit.bind(this); - this.loginWithProvider = this.loginWithProvider.bind(this); - this.state = { - message: '', + constructor(props) { + super(props); + this.onFormSubmit = this.onFormSubmit.bind(this); + this.loginWithProvider = this.loginWithProvider.bind(this); + this.state = { + message: '', }; } - loginWithProvider(provider) { - this.props.loginWithProvider(provider).then(data => { - if (data.payload.errorCode) - this.setState({ message: data.payload.errorMessage }) - else - browserHistory.push('/profile'); + loginWithProvider(provider) { + this.props.loginWithProvider(provider).then((data) => { + if (data.payload.errorCode) + {this.setState({ message: data.payload.errorMessage })}; + else + {browserHistory.push('/profile');} }); // alert("login with provider"); } - onFormSubmit(event) { - event.preventDefault(); - - var email = this.refs.email.value; - var password = this.refs.password.value; - this.props.loginUser({ email: email, password: password }).then(data => { - - if (data.payload.errorCode) - this.setState({ message: data.payload.errorMessage }) - else - browserHistory.push('/profile'); + onFormSubmit(event) { + event.preventDefault(); + let email = this.refs.email.value; + let password = this.refs.password.value; + this.props.loginUser({ email, password }).then((data) => { + if (data.payload.errorCode) + {this.setState({ message: data.payload.errorMessage })}; + else + {browserHistory.push('/profile');} } - ) - + ); } - render() { - return ( -
-
-

- {this.state.message} + render() { + return ( +

+ +

+ {this.state.message}

-

Login

-
- - +

Login

+
+ +
- - ) + ); } } function mapDispatchToProps(dispatch) { - return bindActionCreators({ - loginUser, - fetchUser, - loginWithProvider + return bindActionCreators({ + loginUser, + fetchUser, + loginWithProvider, }, dispatch); } function mapStateToProps(state) { - return { currentUser: state.currentUser }; - + return { currentUser: state.currentUser }; } export default connect(mapStateToProps, mapDispatchToProps)(UserLogin); diff --git a/src/app/components/user/register.jsx b/src/app/components/user/register.jsx index fd3a7b2..50daa2d 100644 --- a/src/app/components/user/register.jsx +++ b/src/app/components/user/register.jsx @@ -1,76 +1,84 @@ -import React, { Component } from 'react'; -import { browserHistory } from 'react-router'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -import { registerUser } from '../../actions/firebase_actions'; +import React, { Component } from 'react' +import { browserHistory } from 'react-router' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import { registerUser } from '../../actions/firebase_actions' class UserRegister extends Component { constructor(props) { - super(props); - this.onFormSubmit = this.onFormSubmit.bind(this); - this.state = { - message: '', - }; - } + super(props) + this.onFormSubmit = this.onFormSubmit.bind(this) + this.state = { + message: '', + } + } onFormSubmit(event) { - event.preventDefault(); + event.preventDefault() - const email = this.refs.email.value; - const password = this.refs.password.value; - this.props.registerUser({ email, password }).then((data) => { - if (data.payload.errorCode) - this.setState({ message: data.payload.errorMessage }); - else - browserHistory.push('/profile'); - } - ); - } + const email = this.refs.email.value + const password = this.refs.password.value + this.props.registerUser({ email, password }).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + browserHistory.push('/profile') + } + } + ) + } render() { return ( -
-
-

{this.state.message}

-

Register

-
- - -
-
- - -
- -

+
- ); + +
+ ) } } @@ -78,11 +86,11 @@ class UserRegister extends Component { function mapDispatchToProps(dispatch) { return bindActionCreators({ registerUser, - }, dispatch); + }, dispatch) } function mapStateToProps(state) { - return { currentUser: state.currentUser }; + return { currentUser: state.currentUser } } -export default connect(mapStateToProps, mapDispatchToProps)(UserRegister); +export default connect(mapStateToProps, mapDispatchToProps)(UserRegister) diff --git a/src/app/utils/authenticated.js b/src/app/utils/authenticated.js index 2893ecf..681cf8e 100644 --- a/src/app/utils/authenticated.js +++ b/src/app/utils/authenticated.js @@ -1,14 +1,14 @@ function requireAuth(nextState, replace) { - const data = JSON.parse(localStorage.getItem(localStorage.key(0))); + const data = JSON.parse(localStorage.getItem(localStorage.key(0))) if (!data.uid) { replace({ pathname: '/login', state: { nextPathname: nextState.location.pathname, }, - }); + }) } } -module.exports = requireAuth; +module.exports = requireAuth From 111a0a23791eecd9e9b9f3c78ae542afeebec1b1 Mon Sep 17 00:00:00 2001 From: Beka Tomashvili Date: Wed, 16 Nov 2016 04:00:08 +0400 Subject: [PATCH 2/4] eslint stuff --- src/app/actions/firebase_actions.js | 87 +++++++-------- src/app/components/index_home.jsx | 6 +- src/app/components/user/login.jsx | 4 +- src/app/components/user/profile.jsx | 123 +++++++++++---------- src/app/components/user/reset_password.jsx | 92 +++++++-------- 5 files changed, 157 insertions(+), 155 deletions(-) diff --git a/src/app/actions/firebase_actions.js b/src/app/actions/firebase_actions.js index 4ad4ee9..ed86e7f 100644 --- a/src/app/actions/firebase_actions.js +++ b/src/app/actions/firebase_actions.js @@ -1,4 +1,4 @@ -import FireBaseTools from '../utils/firebase'; +import FireBaseTools from '../utils/firebase' import { LOGIN_WITH_PROVIDER_FIREBASE, REGISTER_FIREBASE_USER, @@ -7,70 +7,69 @@ import { UPDATE_FIREBASE_USER, CHANGE_FIREBASE_USER_PASSWORD, FIREBASE_PASSWORD_RESET_EMAIL, - LOGOUT_FIREBASE_USER -} from './types'; - + LOGOUT_FIREBASE_USER, +} from './types' export function loginWithProvider(provider) { - const request = FireBaseTools.loginWithProvider(provider); - return { - type: LOGIN_WITH_PROVIDER_FIREBASE, - payload: request - } + const request = FireBaseTools.loginWithProvider(provider) + return { + type: LOGIN_WITH_PROVIDER_FIREBASE, + payload: request, + } } export function registerUser(user) { - const request = FireBaseTools.registerUser(user); - return { - type: REGISTER_FIREBASE_USER, - payload: request - } + const request = FireBaseTools.registerUser(user) + return { + type: REGISTER_FIREBASE_USER, + payload: request, + } } export function loginUser(user) { - const request = FireBaseTools.loginUser(user); - return { - type: LOGIN_FIREBASE_USER, - payload: request - } + const request = FireBaseTools.loginUser(user) + return { + type: LOGIN_FIREBASE_USER, + payload: request, + } } export function fetchUser() { - const request = FireBaseTools.fetchUser(); - return { - type: FETCH_FIREBASE_USER, - payload: request - } + const request = FireBaseTools.fetchUser() + return { + type: FETCH_FIREBASE_USER, + payload: request, + } } export function updateUser(user) { - const request = FireBaseTools.updateUserProfile(user); - return { - type: UPDATE_FIREBASE_USER, - payload: request - } + const request = FireBaseTools.updateUserProfile(user) + return { + type: UPDATE_FIREBASE_USER, + payload: request, + } } export function changePassword(newPassword) { - const request = FireBaseTools.changePassword(newPassword); - return { - type: CHANGE_FIREBASE_USER_PASSWORD, - payload: request - } + const request = FireBaseTools.changePassword(newPassword) + return { + type: CHANGE_FIREBASE_USER_PASSWORD, + payload: request, + } } export function resetPasswordEmail(email) { - const request = FireBaseTools.resetPasswordEmail(email); - return { - type: FIREBASE_PASSWORD_RESET_EMAIL, - payload: request - } + const request = FireBaseTools.resetPasswordEmail(email) + return { + type: FIREBASE_PASSWORD_RESET_EMAIL, + payload: request, + } } export function logoutUser(user) { - const request = FireBaseTools.logoutUser(user); - return { - type: LOGOUT_FIREBASE_USER, - payload: request - } + const request = FireBaseTools.logoutUser(user) + return { + type: LOGOUT_FIREBASE_USER, + payload: request, + } } diff --git a/src/app/components/index_home.jsx b/src/app/components/index_home.jsx index 4dd2de1..6358497 100644 --- a/src/app/components/index_home.jsx +++ b/src/app/components/index_home.jsx @@ -1,5 +1,3 @@ -import React from 'react'; +import React from 'react' -export default () => { - return
Home Page of our application!
; -}; +export default () =>
Home Page of our application!
diff --git a/src/app/components/user/login.jsx b/src/app/components/user/login.jsx index 670e8fe..a54daf5 100644 --- a/src/app/components/user/login.jsx +++ b/src/app/components/user/login.jsx @@ -20,8 +20,8 @@ class UserLogin extends Component { this.props.loginWithProvider(provider).then((data) => { if (data.payload.errorCode) {this.setState({ message: data.payload.errorMessage })}; - else - {browserHistory.push('/profile');} + else + { browserHistory.push('/profile');} }); // alert("login with provider"); } diff --git a/src/app/components/user/profile.jsx b/src/app/components/user/profile.jsx index 9c871a9..6b7f44c 100644 --- a/src/app/components/user/profile.jsx +++ b/src/app/components/user/profile.jsx @@ -1,79 +1,84 @@ -import React, {Component} from 'react'; -import firebase from '../../utils/firebase'; -import {connect} from 'react-redux'; -import {bindActionCreators} from 'redux'; -import {fetchUser, updateUser} from '../../actions/firebase_actions'; -import Loading from '../helpers/loading'; -import ChangePassword from './change_password'; +import React, { Component } from 'react' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import firebase from '../../utils/firebase' +import { fetchUser, updateUser } from '../../actions/firebase_actions' +import Loading from '../helpers/loading' +import ChangePassword from './change_password' class UserProfile extends Component { - constructor(props) { - super(props); - this.props.fetchUser(); - this.state = { - message: '' + constructor(props) { + super(props) + this.props.fetchUser() + this.state = { + message: '', + } + this.onFormSubmit = this.onFormSubmit.bind(this) } - this.onFormSubmit = this.onFormSubmit.bind(this); - } - onFormSubmit(event) { - event.preventDefault(); - var email = this.refs.email.value; - var displayName = this.refs.displayName.value; - this.props.updateUser({email: email, displayName: displayName}).then(data => { - - if (data.payload.errorCode) - this.setState({message: data.payload.errorMessage}) - else - this.setState({ - message: "Updated successfuly!" - }) - - } + onFormSubmit(event) { + event.preventDefault() + const email = this.refs.email.value + const displayName = this.refs.displayName.value + this.props.updateUser({ email, displayName }).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + this.setState({ + message: 'Updated successfuly!', + }) + } + } ) - } - - render() { - if (!this.props.currentUser) { - return } - return ( -
-
-

User Profile Page

-

{this.state.message}

-
-
- - -
-
- - -
- -
- -
- ) - } + render() { + if (!this.props.currentUser) { + return + } + + return ( +
+
+

User Profile Page

+

{this.state.message}

+
+
+ + +
+
+ + +
+ +
+ +
+ ) + } } function mapDispatchToProps(dispatch) { - return bindActionCreators({fetchUser, updateUser}, dispatch); + return bindActionCreators({ fetchUser, updateUser }, dispatch) } function mapStateToProps(state) { - return {currentUser: state.currentUser}; + return { currentUser: state.currentUser } } -export default connect(mapStateToProps, mapDispatchToProps)(UserProfile); +export default connect(mapStateToProps, mapDispatchToProps)(UserProfile) diff --git a/src/app/components/user/reset_password.jsx b/src/app/components/user/reset_password.jsx index 1755ec9..b0ccbcf 100644 --- a/src/app/components/user/reset_password.jsx +++ b/src/app/components/user/reset_password.jsx @@ -1,56 +1,56 @@ -import React, {Component} from 'react'; -import {connect} from 'react-redux'; -import {bindActionCreators} from 'redux'; -import {resetPasswordEmail} from '../../actions/firebase_actions'; +import React, { Component } from 'react' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import { resetPasswordEmail } from '../../actions/firebase_actions' class ResetPassword extends Component { - constructor(props) { - super(props); - this.state = { - message: '' + constructor(props) { + super(props) + this.state = { + message: '', + } + this.onFormSubmit = this.onFormSubmit.bind(this) } - this.onFormSubmit = this.onFormSubmit.bind(this); - } - - onFormSubmit(event) { - event.preventDefault(); - var email = this.refs.email.value; - this.props.resetPasswordEmail(email).then(data => { - - if (data.payload.errorCode) - this.setState({message: data.payload.errorMessage}) - else - this.setState({message: "Please see your email!"}) - - - }); - - } - - render() { - return ( - -
-
-

{this.state.message}

-
- - -
- -
-
+ onFormSubmit(event) { + event.preventDefault() + const email = this.refs.email.value + this.props.resetPasswordEmail(email).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + this.setState({ message: 'Please see your email!' }) + } + }) + } - ) - } + render() { + return ( + +
+
+

{this.state.message}

+
+ + +
+ +
+
+ + ) + } } function mapDispatchToProps(dispatch) { - return bindActionCreators({ - resetPasswordEmail - }, dispatch); + return bindActionCreators({ + resetPasswordEmail, + }, dispatch) } -export default connect(null, mapDispatchToProps)(ResetPassword); +export default connect(null, mapDispatchToProps)(ResetPassword) From 35eeb29adcc92eb0713b0e00366805dc70f08c84 Mon Sep 17 00:00:00 2001 From: Beka Tomashvili Date: Wed, 16 Nov 2016 04:03:05 +0400 Subject: [PATCH 3/4] loging.jsx elisnt stuff --- src/app/components/user/login.jsx | 178 +++++++++++++++--------------- 1 file changed, 92 insertions(+), 86 deletions(-) diff --git a/src/app/components/user/login.jsx b/src/app/components/user/login.jsx index a54daf5..d8300e8 100644 --- a/src/app/components/user/login.jsx +++ b/src/app/components/user/login.jsx @@ -1,108 +1,114 @@ -import React, { Component } from 'react'; -import { browserHistory, Link } from 'react-router'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -import { loginUser, fetchUser, loginWithProvider } from '../../actions/firebase_actions'; +import React, { Component } from 'react' +import { browserHistory, Link } from 'react-router' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import { loginUser, fetchUser, loginWithProvider } from '../../actions/firebase_actions' class UserLogin extends Component { constructor(props) { - super(props); - this.onFormSubmit = this.onFormSubmit.bind(this); - this.loginWithProvider = this.loginWithProvider.bind(this); - this.state = { - message: '', - }; - } + super(props) + this.onFormSubmit = this.onFormSubmit.bind(this) + this.loginWithProvider = this.loginWithProvider.bind(this) + this.state = { + message: '', + } + } loginWithProvider(provider) { - this.props.loginWithProvider(provider).then((data) => { - if (data.payload.errorCode) - {this.setState({ message: data.payload.errorMessage })}; - else - { browserHistory.push('/profile');} - }); - // alert("login with provider"); - } + this.props.loginWithProvider(provider).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + browserHistory.push('/profile') + } + }) + } onFormSubmit(event) { - event.preventDefault(); - - let email = this.refs.email.value; - let password = this.refs.password.value; - this.props.loginUser({ email, password }).then((data) => { - if (data.payload.errorCode) - {this.setState({ message: data.payload.errorMessage })}; - else - {browserHistory.push('/profile');} + event.preventDefault() + + const email = this.refs.email.value + const password = this.refs.password.value + this.props.loginUser({ email, password }).then((data) => { + if (data.payload.errorCode) { + this.setState({ message: data.payload.errorMessage }) + } else { + browserHistory.push('/profile') + } + }) } - ); - } render() { - return ( - - - ); - } + return ( + + + ) + } } function mapDispatchToProps(dispatch) { return bindActionCreators({ - loginUser, - fetchUser, - loginWithProvider, - }, dispatch); + loginUser, + fetchUser, + loginWithProvider, + }, dispatch) } function mapStateToProps(state) { - return { currentUser: state.currentUser }; + return { currentUser: state.currentUser } } -export default connect(mapStateToProps, mapDispatchToProps)(UserLogin); +export default connect(mapStateToProps, mapDispatchToProps)(UserLogin) From 410c8c7ab02005d1fae61734868d55f5f21b1833 Mon Sep 17 00:00:00 2001 From: Beka Tomashvili Date: Wed, 16 Nov 2016 04:06:42 +0400 Subject: [PATCH 4/4] eslint stuff --- src/app/actions/types.js | 18 +-- src/app/components/app.jsx | 144 +++++++++--------- src/app/components/helpers/loading.jsx | 10 +- src/app/config.js | 18 +-- src/app/index.js | 32 ++-- src/app/reducers/firebase_user_reducer.js | 26 ++-- src/app/reducers/index.js | 8 +- src/app/routes.js | 36 ++--- src/app/utils/firebase.js | 176 ++++++++-------------- 9 files changed, 210 insertions(+), 258 deletions(-) diff --git a/src/app/actions/types.js b/src/app/actions/types.js index 747255f..2b81951 100644 --- a/src/app/actions/types.js +++ b/src/app/actions/types.js @@ -1,11 +1,11 @@ -/// FIREBASE AUTH ACTIONS -export const LOGIN_WITH_PROVIDER_FIREBASE = 'LOGIN_WITH_PROVIDER_FIREBASE'; -export const REGISTER_FIREBASE_USER = 'REGISTER_FIREBASE_USER'; -export const LOGIN_FIREBASE_USER = 'LOGIN_FIREBASE_USER'; -export const FETCH_FIREBASE_USER = 'FETCH_FIREBASE_USER'; -export const UPDATE_FIREBASE_USER = 'UPDATE_FIREBASE_USER'; -export const CHANGE_FIREBASE_USER_PASSWORD = 'CHANGE_FIREBASE_USER_PASSWORD'; -export const FIREBASE_PASSWORD_RESET_EMAIL = 'FIREBASE_PASSWORD_RESET_EMAIL'; -export const LOGOUT_FIREBASE_USER = 'LOGOUT_FIREBASE_USER'; +// / FIREBASE AUTH ACTIONS +export const LOGIN_WITH_PROVIDER_FIREBASE = 'LOGIN_WITH_PROVIDER_FIREBASE' +export const REGISTER_FIREBASE_USER = 'REGISTER_FIREBASE_USER' +export const LOGIN_FIREBASE_USER = 'LOGIN_FIREBASE_USER' +export const FETCH_FIREBASE_USER = 'FETCH_FIREBASE_USER' +export const UPDATE_FIREBASE_USER = 'UPDATE_FIREBASE_USER' +export const CHANGE_FIREBASE_USER_PASSWORD = 'CHANGE_FIREBASE_USER_PASSWORD' +export const FIREBASE_PASSWORD_RESET_EMAIL = 'FIREBASE_PASSWORD_RESET_EMAIL' +export const LOGOUT_FIREBASE_USER = 'LOGOUT_FIREBASE_USER' diff --git a/src/app/components/app.jsx b/src/app/components/app.jsx index 12455d3..c7777be 100644 --- a/src/app/components/app.jsx +++ b/src/app/components/app.jsx @@ -1,91 +1,93 @@ -import React, { Component } from 'react'; -import { Link } from 'react-router'; -import { connect } from 'react-redux'; -import { bindActionCreators } from 'redux'; -import { fetchUser, logoutUser } from '../actions/firebase_actions'; +import React, { Component } from 'react' +import { Link } from 'react-router' +import { connect } from 'react-redux' +import { bindActionCreators } from 'redux' +import { fetchUser, logoutUser } from '../actions/firebase_actions' class App extends Component { - constructor(props) { - super(props); + constructor(props) { + super(props) + this.props.fetchUser() + this.logOut = this.logOut.bind(this) + } - this.props.fetchUser(); - this.logOut = this.logOut.bind(this); - } + logOut() { + this.props.logoutUser().then((data) => { + this.props.fetchUser() + }) + } - logOut() { - this.props.logoutUser().then(data=> { - // reload props from reducer - this.props.fetchUser(); - }); - } + renderUserMenu(currentUser) { + // if current user exists and user id exists than make user navigation + if (currentUser && currentUser.uid) { + return ( +
  • + +
      +
    • Profile
    • +
    • +
    • Logout
    • +
    +
  • + ) + } else { + return [ +
  • Login
  • , +
  • Register
  • , + ] + } + } - renderUserMenu(currentUser) { - // if current user exists and user id exists than make user navigation - if (currentUser && currentUser.uid) - return ( -
  • - -
      -
    • Profile
    • -
    • -
    • Logout
    • -
    -
  • - ) - else - return [ -
  • Login
  • , -
  • Register
  • - ] + render() { + return ( +
    + +
      + { this.renderUserMenu(this.props.currentUser) } +
    + +
    + -
    - {this.props.children} -
    -
    - ); - } +
    + {this.props.children} +
    +
    + ) + } } function mapDispatchToProps(dispatch) { - return bindActionCreators({ fetchUser, logoutUser }, dispatch); + return bindActionCreators({ fetchUser, logoutUser }, dispatch) } function mapStateToProps(state) { - return { currentUser: state.currentUser }; + return { currentUser: state.currentUser } } -export default connect(mapStateToProps, mapDispatchToProps)(App); +export default connect(mapStateToProps, mapDispatchToProps)(App) diff --git a/src/app/components/helpers/loading.jsx b/src/app/components/helpers/loading.jsx index f88742e..893d950 100644 --- a/src/app/components/helpers/loading.jsx +++ b/src/app/components/helpers/loading.jsx @@ -1,12 +1,10 @@ -import React from 'react'; +import React from 'react' -const Loading = () => { - return ( +const Loading = () => (
    Loading ....
    - ); -}; + ) -export default Loading; +export default Loading diff --git a/src/app/config.js b/src/app/config.js index 162b376..a9779b6 100644 --- a/src/app/config.js +++ b/src/app/config.js @@ -1,13 +1,13 @@ module.exports = { - // Change this to your firebase configuration! (Add Firebase to your web app) - FIREBASE_CONFIG: { + // Change this to your firebase configuration! (Add Firebase to your web app) + FIREBASE_CONFIG: { - apiKey: "AIzaSyAAzWIkcMqyHueh1yQt84HdpMFfzL1OZYc", - authDomain: "react-redux-firebase-d6283.firebaseapp.com", - databaseURL: "https://react-redux-firebase-d6283.firebaseio.com/", - storageBucket: "react-redux-firebase-d6283.appspot.com", - messagingSenderId: "425723634684" + apiKey: 'AIzaSyAAzWIkcMqyHueh1yQt84HdpMFfzL1OZYc', + authDomain: 'react-redux-firebase-d6283.firebaseapp.com', + databaseURL: 'https://react-redux-firebase-d6283.firebaseio.com/', + storageBucket: 'react-redux-firebase-d6283.appspot.com', + messagingSenderId: '425723634684', - } -}; + }, +} diff --git a/src/app/index.js b/src/app/index.js index fdb4564..8f56576 100644 --- a/src/app/index.js +++ b/src/app/index.js @@ -1,24 +1,24 @@ -import React from 'react'; -import ReactDOM from 'react-dom'; -import {Provider} from 'react-redux'; -import {createStore, applyMiddleware} from 'redux'; -import {Router, browserHistory} from 'react-router'; -import ReduxPromise from 'redux-promise'; +import React from 'react' +import ReactDOM from 'react-dom' +import { Provider } from 'react-redux' +import { createStore, applyMiddleware } from 'redux' +import { Router, browserHistory } from 'react-router' +import ReduxPromise from 'redux-promise' -import reducers from './reducers'; -import routes from './routes'; +import 'bootstrap-social' + +import reducers from './reducers' +import routes from './routes' -import 'bootstrap-social'; // for bundling your styles -import './bundle.scss'; +import './bundle.scss' -const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore); +const createStoreWithMiddleware = applyMiddleware(ReduxPromise)(createStore) ReactDOM.render( - - - - - , document.querySelector('.react-root')); + + + + , document.querySelector('.react-root')) diff --git a/src/app/reducers/firebase_user_reducer.js b/src/app/reducers/firebase_user_reducer.js index a4261db..16c6c32 100644 --- a/src/app/reducers/firebase_user_reducer.js +++ b/src/app/reducers/firebase_user_reducer.js @@ -6,29 +6,29 @@ import { UPDATE_FIREBASE_USER, CHANGE_FIREBASE_USER_PASSWORD, FIREBASE_PASSWORD_RESET_EMAIL, - LOGOUT_FIREBASE_USER -} from '../actions/types'; + LOGOUT_FIREBASE_USER, +} from '../actions/types' export default function (state = null, action) { - switch (action.type) { + switch (action.type) { case FETCH_FIREBASE_USER: - return action.payload; + return action.payload case LOGOUT_FIREBASE_USER: - return action.payload; + return action.payload case REGISTER_FIREBASE_USER: - return action.payload; + return action.payload case LOGIN_FIREBASE_USER: - return action.payload; + return action.payload case UPDATE_FIREBASE_USER: - return action.payload; + return action.payload case CHANGE_FIREBASE_USER_PASSWORD: - return action.payload; + return action.payload case FIREBASE_PASSWORD_RESET_EMAIL: - return action.payload; + return action.payload case LOGIN_WITH_PROVIDER_FIREBASE: - return action.payload; + return action.payload - } - return state; + } + return state } diff --git a/src/app/reducers/index.js b/src/app/reducers/index.js index 7baec34..855b428 100644 --- a/src/app/reducers/index.js +++ b/src/app/reducers/index.js @@ -1,8 +1,8 @@ -import { combineReducers } from 'redux'; -import FireBaseUserReducer from './firebase_user_reducer'; +import { combineReducers } from 'redux' +import FireBaseUserReducer from './firebase_user_reducer' const rootReducer = combineReducers({ currentUser: FireBaseUserReducer, -}); +}) -export default rootReducer; +export default rootReducer diff --git a/src/app/routes.js b/src/app/routes.js index 033823c..bb830f4 100644 --- a/src/app/routes.js +++ b/src/app/routes.js @@ -1,23 +1,23 @@ -import React from 'react'; -import { Route, IndexRoute } from 'react-router'; -import App from './components/app'; +import React from 'react' +import { Route, IndexRoute } from 'react-router' +import App from './components/app' -import HomeIndex from './components/index_home'; -import UserLogin from './components/user/login'; -import UserLogout from './components/user/logout'; -import UserRegister from './components/user/register'; -import UserProfile from './components/user/profile'; -import ResetPassword from './components/user/reset_password'; -import requireAuth from './utils/authenticated'; +import HomeIndex from './components/index_home' +import UserLogin from './components/user/login' +import UserLogout from './components/user/logout' +import UserRegister from './components/user/register' +import UserProfile from './components/user/profile' +import ResetPassword from './components/user/reset_password' +import requireAuth from './utils/authenticated' export default ( - - - - - - - + + + + + + + -); +) diff --git a/src/app/utils/firebase.js b/src/app/utils/firebase.js index 64c19f5..c7e4a86 100644 --- a/src/app/utils/firebase.js +++ b/src/app/utils/firebase.js @@ -1,11 +1,11 @@ -import firebase from 'firebase'; -import { FIREBASE_CONFIG } from '../config'; +import firebase from 'firebase' +import { FIREBASE_CONFIG } from '../config' -export const firebaseApp = firebase.initializeApp(FIREBASE_CONFIG); -export const firebaseAuth = firebaseApp.auth(); -export const firebaseDb = firebaseApp.database(); +export const firebaseApp = firebase.initializeApp(FIREBASE_CONFIG) +export const firebaseAuth = firebaseApp.auth() +export const firebaseDb = firebaseApp.database() -var FireBaseTools = { +const FireBaseTools = { /** * Return an instance of a firebase auth provider based on the provider string. @@ -13,21 +13,21 @@ var FireBaseTools = { * @param provider * @returns {firebase.auth.AuthProvider} */ - getProvider: (provider) => { - switch (provider) { - case 'email': - return new firebase.auth.EmailAuthProvider(); - case 'facebook': - return new firebase.auth.FacebookAuthProvider(); - case 'github': - return new firebase.auth.GithubAuthProvider(); - case 'google': - return new firebase.auth.GoogleAuthProvider(); - case 'twitter': - return new firebase.auth.TwitterAuthProvider(); - default: - } - }, + getProvider: (provider) => { + switch (provider) { + case 'email': + return new firebase.auth.EmailAuthProvider() + case 'facebook': + return new firebase.auth.FacebookAuthProvider() + case 'github': + return new firebase.auth.GithubAuthProvider() + case 'google': + return new firebase.auth.GoogleAuthProvider() + case 'twitter': + return new firebase.auth.TwitterAuthProvider() + default: + } + }, /** * Login with provider => p is provider "email", "facebook", "github", "google", or "twitter" @@ -35,17 +35,13 @@ var FireBaseTools = { * * @returns {any|!firebase.Thenable.<*>|firebase.Thenable} */ - loginWithProvider: (p) => { - let provider = FireBaseTools.getProvider(p); - return firebaseAuth.signInWithPopup(provider).then(function (result) { - return firebaseAuth.currentUser; - }).catch(function (error) { - return { - errorCode: error.code, - errorMessage: error.message - }; - }); - }, + loginWithProvider: (p) => { + const provider = FireBaseTools.getProvider(p) + return firebaseAuth.signInWithPopup(provider).then(result => firebaseAuth.currentUser).catch(error => ({ + errorCode: error.code, + errorMessage: error.message, + })) + }, /** * Register a user with email and password @@ -53,45 +49,33 @@ var FireBaseTools = { * @param user * @returns {any|!firebase.Thenable.<*>|firebase.Thenable} */ - registerUser: (user) => { - return firebaseAuth.createUserWithEmailAndPassword(user.email, user.password).then(user => { - return user; - }).catch(error => { - return { + registerUser: user => firebaseAuth.createUserWithEmailAndPassword(user.email, user.password).then(user => user).catch(error => ({ errorCode: error.code, - errorMessage: error.message - }; - }); - }, + errorMessage: error.message, + })), /** * Sign the user out * * @returns {!firebase.Promise.<*>|firebase.Thenable|firebase.Promise|!firebase.Thenable.<*>} */ - logoutUser: () => { - return firebaseAuth.signOut().then(() => { - return { + logoutUser: () => firebaseAuth.signOut().then(() => ({ success: 1, - message: 'logout' - }; - }); - }, + message: 'logout', + })), /** * Retrieve the current user (Promise) * @returns {Promise} */ - fetchUser: () => { - return new Promise((resolve, reject) => { - const unsub = firebaseAuth.onAuthStateChanged(user => { - unsub(); - resolve(user); - }, error => { - reject(error); - }) - }) - }, + fetchUser: () => new Promise((resolve, reject) => { + const unsub = firebaseAuth.onAuthStateChanged((user) => { + unsub() + resolve(user) + }, (error) => { + reject(error) + }) + }), /** * Log the user in using email and password @@ -99,16 +83,10 @@ var FireBaseTools = { * @param user * @returns {any|!firebase.Thenable.<*>|firebase.Thenable} */ - loginUser: (user) => { - return firebaseAuth.signInWithEmailAndPassword(user.email, user.password).then(user => { - return user; - }).catch(error => { - return { + loginUser: user => firebaseAuth.signInWithEmailAndPassword(user.email, user.password).then(user => user).catch(error => ({ errorCode: error.code, - errorMessage: error.message - } - }); - }, + errorMessage: error.message, + })), /** * Update a user's profile data @@ -116,16 +94,10 @@ var FireBaseTools = { * @param u * @returns {!firebase.Promise.<*>|firebase.Thenable|firebase.Promise|!firebase.Thenable.<*>} */ - updateUserProfile: (u) => { - return firebaseAuth.currentUser.updateProfile(u).then(() => { - return firebaseAuth.currentUser; - }, error => { - return { + updateUserProfile: u => firebaseAuth.currentUser.updateProfile(u).then(() => firebaseAuth.currentUser, error => ({ errorCode: error.code, - errorMessage: error.message - } - }) - }, + errorMessage: error.message, + })), /** * Reset the password given the specified email @@ -133,18 +105,12 @@ var FireBaseTools = { * @param email {string} * @returns {!firebase.Promise.<*>|firebase.Thenable|firebase.Promise|!firebase.Thenable.<*>} */ - resetPasswordEmail: (email) => { - return firebaseAuth.sendPasswordResetEmail(email).then(() => { - return { - message: 'Email sent' - } - }, error => { - return { + resetPasswordEmail: email => firebaseAuth.sendPasswordResetEmail(email).then(() => ({ + message: 'Email sent', + }), error => ({ errorCode: error.code, - errorMessage: error.message - } - }); - }, + errorMessage: error.message, + })), /** * Update the user's password with the given password @@ -152,34 +118,22 @@ var FireBaseTools = { * @param newPassword {string} * @returns {!firebase.Promise.<*>|firebase.Thenable|firebase.Promise|!firebase.Thenable.<*>} */ - changePassword: (newPassword) => { - return firebaseAuth.currentUser.updatePassword(newPassword).then(user => { - return user; - }, error => { - return { + changePassword: newPassword => firebaseAuth.currentUser.updatePassword(newPassword).then(user => user, error => ({ errorCode: error.code, - errorMessage: error.message - } - }); - }, + errorMessage: error.message, + })), /** * Send an account email verification message for the currently logged in user * * @returns {!firebase.Promise.<*>|firebase.Thenable|firebase.Promise|!firebase.Thenable.<*>} */ - sendEmailVerification: () => { - return firebaseAuth.currentUser.sendEmailVerification().then(() => { - return { - message: 'Email sent' - } - }, error => { - return { + sendEmailVerification: () => firebaseAuth.currentUser.sendEmailVerification().then(() => ({ + message: 'Email sent', + }), error => ({ errorCode: error.code, - errorMessage: error.message - } - }); - }, + errorMessage: error.message, + })), /** * Get the firebase database reference. @@ -187,9 +141,7 @@ var FireBaseTools = { * @param path {!string|string} * @returns {!firebase.database.Reference|firebase.database.Reference} */ - getDatabaseReference: (path) => { - return firebaseDb.ref(path); - } -}; + getDatabaseReference: path => firebaseDb.ref(path), +} -export default FireBaseTools; +export default FireBaseTools