Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"dependencies": {
"firebase": "^4.1.1",
"immutable": "^3.8.1",
"material-components-web": "^0.13.0",
"prop-types": "^15.5.10",
"react": "^15.5.4",
"react-dom": "^15.5.4",
Expand All @@ -14,6 +15,7 @@
"react-router-redux": "^5.0.0-alpha.5",
"redux": "^3.6.0",
"redux-devtools-extension": "^2.13.2",
"redux-saga": "^0.15.3",
"uuid": "^3.0.1"
},
"devDependencies": {
Expand Down
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

<title>React App</title>
</head>
<body>
Expand Down
22 changes: 16 additions & 6 deletions src/App.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,38 @@
import 'api/config/firebase';
import React, { Component } from 'react';

import { createStore, combineReducers, applyMiddleware } from 'redux';
import { Provider } from 'react-redux';
import createHistory from 'history/createBrowserHistory';
import { Route, withRouter } from 'react-router-dom';
import { Route } from 'react-router-dom';
import { composeWithDevTools } from 'redux-devtools-extension';
import { ConnectedRouter, routerReducer, routerMiddleware } from 'react-router-redux';
import createSagaMiddleware from 'redux-saga';

import uuid from 'uuid';
import './App.css';

import Login from 'components/auth/container';
import Home from 'components/home/container';
import Login from 'components/auth';
import Home from 'components/home';
import Beers from 'components/beer';

import middleware from 'api/middlewares/middleware.js';
import sagas from 'api/sagas';
import reducers from 'api/reducers';

import { actions as authActions } from 'api/actions/auth';

window.uuid = uuid;

class App extends Component {


componentWillMount() {
const sagaMiddleware = createSagaMiddleware();
const composeEnhancers = composeWithDevTools({});
this.history = createHistory();
const routerReduxMiddleware = routerMiddleware(this.history);
const middlewares = [
middleware,
sagaMiddleware,
routerReduxMiddleware,
];
this.store = createStore(
Expand All @@ -34,6 +42,7 @@ class App extends Component {
}),
composeEnhancers(applyMiddleware(...middlewares))
);
sagaMiddleware.run(sagas);
}

componentDidMount() {
Expand All @@ -42,7 +51,7 @@ class App extends Component {

onAuthStateChanged = (payload) => {
const action = {
type: 'logged',
type: authActions.logged,
payload,
};
this.store.dispatch(action);
Expand All @@ -55,6 +64,7 @@ class App extends Component {
<div className="App">
<Route exact path="/" component={Home} />
<Route exact path="/login" component={Login} />
<Route exact path="/brewery/:id/:uid" component={Beers} />
</div>
</ConnectedRouter>
</Provider>
Expand Down
13 changes: 8 additions & 5 deletions src/api/actions/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,26 @@ import { push } from 'react-router-redux';
export const actions = {
login: 'BREWERY_AUTH_LOGIN',
logged: 'BREWERY_AUTH_LOGGED',
}
logout: 'BREWERY_AUTH_LOGOUT',
};

export const mapStateToProps = ({ user }) => ({ user });

export const mapDispatchToProps = (dispatch) => {
export const mapDispatchToProps = dispatch => {
return {
redirectToHome: (uid) => {
redirectToHome: uid => {
if (uid) {
dispatch(push('/'));
}
},
redirectToLogin: (uid) => {
redirectToLogin: uid => {
if (!uid) {
dispatch(push('/login'));
}
},
onLogin: () => dispatch({ type: 'login' })

onLogin: () => dispatch({ type: actions.login }),
onLogout: () => dispatch({ type: actions.logout }),
};
};

Expand Down
55 changes: 55 additions & 0 deletions src/api/actions/beer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const actions = {
add: 'BEER_LIST_ADD',
edit: 'BEER_LIST_EDIT',
update: 'BEER_LIST_UPDATE',
remove: 'BEER_LIST_REMOVE',
request: 'BEER_LIST_REQUEST',
requestSuccess: 'BEER_LIST_REQUEST_SUCCESS',
};

export const mapStateToProps = ({ beerList, beerEdit }) => ({ beerList, beerEdit });

export const mapDispatchToProps = dispatch => {
return {

request: (payload1, payload2) => dispatch({
type: actions.request,
payload1,
payload2,
}),

requestSuccess: payload => dispatch({
type: actions.requestSuccess,
payload,
}),

add: (payload1, payload2) => dispatch({
type: actions.add,
payload1,
payload2,
}),

remove: (payload, payload1, payload2) => dispatch({
type: actions.remove,
payload,
payload1,
payload2,
}),

update: (payload, payload1, payload2) => dispatch({
type: actions.update,
payload,
payload1,
payload2,
}),

edit: (payload, payload1, payload2) => dispatch({
type: actions.edit,
payload,
payload1,
payload2,
}),
};
};

export default {};
28 changes: 20 additions & 8 deletions src/api/actions/brewery.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import { push } from 'react-router-redux';

export const actions = {
add: 'BREWERY_LIST_ADD',
edit: 'BREWERY_LIST_EDIT',
request:'BREWERY_LIST_REQUEST',
update: 'BREWERY_LIST_UPDATE',
remove: 'BREWERY_LIST_REMOVE',
request: 'BREWERY_LIST_REQUEST',
requestSuccess: 'BREWERY_LIST_REQUEST_SUCCESS',
}
};

export const mapStateToProps = ({ list }) => ({ list });
export const mapStateToProps = ({ list, breweryEdit, user }) => ({ list, breweryEdit, user });

export const mapDispatchToProps = (dispatch) => {
export const mapDispatchToProps = dispatch => {
return {
request: () => dispatch({ type: actions.request }),
requestSuccess: payload => dispatch({
type: actions.requestSuccess,
payload
payload,
}),

add: () => dispatch({ type: actions.add }),

remove: payload => dispatch({
type: actions.remove,
payload,
}),

update: payload => dispatch({
type: actions.update,
payload
}),

edit: payload => dispatch({
type: actions.edit,
payload
payload,
}),
};
};
Expand Down
13 changes: 13 additions & 0 deletions src/api/config/firebase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import firebase from 'firebase';

const config = {
apiKey: "AIzaSyBp4WfcFIutxqzrGbCxcro9YxRUhHgoWe4",
authDomain: "feedback-4a295.firebaseapp.com",
databaseURL: "https://feedback-4a295.firebaseio.com",
projectId: "feedback-4a295",
storageBucket: "feedback-4a295.appspot.com",
messagingSenderId: "952975869388"
};
firebase.initializeApp(config);

window.firebase = firebase;
75 changes: 0 additions & 75 deletions src/api/middlewares/middleware.js

This file was deleted.

48 changes: 41 additions & 7 deletions src/api/reducers/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,54 @@
import { fromJS } from 'immutable';
import { actions as breweryActions } from 'api/actions/brewery';
import { actions as beerActions } from 'api/actions/beer';
import { actions as authActions } from 'api/actions/auth';

function listReducer(list = fromJS({}), action) {
if (action.type === 'BREWERY_LIST_REQUEST_SUCCESS') {
//User related
function userReducer(user = {}, action){
if(action.type === authActions.logged){
return action.payload || {};
}
return user;
}
//User related


//Brewery related
function listReducer(list = fromJS({}), action){
if(action.type === breweryActions.requestSuccess){
return fromJS(action.payload);
}
return list;
}
function breweryEdit(brewery = fromJS({}), action) {
if (action.type === breweryActions.edit) {
return action.payload;
}
return brewery;
}
//Brewery related


function userReducer(user = {}, action) {
if (action.type === 'logged') {
//Beer related
function beerListReducer(beerList = fromJS({}), action){
if(action.type === beerActions.requestSuccess){
return fromJS(action.payload) || fromJS({});
}
return beerList;
}
function beerEdit(beer = fromJS({}), action) {
if (action.type === beerActions.edit) {
return action.payload;
}
return user;
return beer;
}
//Beer related


export default {
export default{
user: userReducer,
list: listReducer,
};
beerList: beerListReducer,
breweryEdit: breweryEdit,
beerEdit: beerEdit,
}
Loading