Skip to content

Commit

Permalink
Add to heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
avvazana committed Nov 13, 2018
1 parent d37a9c1 commit 57ce763
Show file tree
Hide file tree
Showing 22 changed files with 1,180 additions and 974 deletions.
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
ruby-2.3.7
ruby-2.5.1
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
source 'https://rubygems.org'
git_source(:github) { |repo| "https://github.com/#{repo}.git" }

ruby '2.3.7'

ruby '2.5.1'
gem 'rails_12factor'
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
gem 'rails', '~> 5.2.1'
# Use postgresql as the database for Active Record
Expand Down
8 changes: 7 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ GEM
nokogiri (>= 1.6)
rails-html-sanitizer (1.0.4)
loofah (~> 2.2, >= 2.2.2)
rails_12factor (0.0.3)
rails_serve_static_assets
rails_stdout_logging
rails_serve_static_assets (0.0.5)
rails_stdout_logging (0.0.5)
railties (5.2.1)
actionpack (= 5.2.1)
activesupport (= 5.2.1)
Expand Down Expand Up @@ -228,6 +233,7 @@ DEPENDENCIES
pry-rails
puma (~> 3.11)
rails (~> 5.2.1)
rails_12factor
sass-rails (~> 5.0)
selenium-webdriver
spring
Expand All @@ -237,7 +243,7 @@ DEPENDENCIES
web-console (>= 3.3.0)

RUBY VERSION
ruby 2.3.7p456
ruby 2.5.1p57

BUNDLED WITH
1.17.1
1 change: 0 additions & 1 deletion app/views/api/users/show.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
debugger
json.partial! 'api/users/user', user: @user
12 changes: 12 additions & 0 deletions frontend/actions/session_actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import * as SessionApiUtil from '../util/session_api_util';
export const RECEIVE_CURRENT_USER = "RECEIVE_CURRENT_USER";
export const RECEIVE_USER = 'RECEIVE_USER';
export const LOGOUT_CURRENT_USER = "LOGOUT_CURRENT_USER";
export const RECEIVE_SIGNIN_ERRORS = "RECEIVE_SIGNIN_ERRORS";
export const RECEIVE_SIGNUP_ERRORS = "RECEIVE_SIGNUP_ERRORS";

export const receiveCurrentUser = user => ({
type: RECEIVE_CURRENT_USER,
Expand All @@ -18,6 +20,16 @@ const logoutCurrentUser = () => ({
type: LOGOUT_CURRENT_USER
});

const receiveSigninErrors = (errors) => ({
type: RECEIVE_SIGNIN_ERRORS,
errors
});

const receiveSignupErrors = (errors) => ({
type: RECEIVE_SIGNUP_ERRORS,
errors
});

export const signup = user => dispatch => {
return SessionApiUtil.signup(user)
.then(user => dispatch(receiveCurrentUser(user)),
Expand Down
22 changes: 22 additions & 0 deletions frontend/components/App.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import { Route, Redirect, Switch } from 'react-router-dom';
import { AuthRoute, ProtectedRoute } from '../util/route_util';

import MainContentContainer from './main/main_content_container';
import Splash from './session/splash';

const App = (props) => {
const splashOrMain = Boolean(props.store.getState().session.currentUserId) ? (
<ProtectedRoute path="/" component={MainContentContainer} />
) : (
<AuthRoute path="/" component={Splash} />
)

return (
<div className="page">
{splashOrMain}
</div>
)
};

export default App;
Empty file.
14 changes: 14 additions & 0 deletions frontend/components/root.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { Provider } from 'react-redux';
import App from './App';
import { HashRouter } from 'react-router-dom';

const Root = ({store}) => (
<Provider store={store} >
<HashRouter>
<App store={store} />
</HashRouter>
</Provider>
);

export default Root;
Empty file.
4 changes: 4 additions & 0 deletions frontend/index.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import React from 'react';
import ReactDOM from 'react-dom';
import configureStore from './store/store';

document.addEventListener("DOMContentLoaded", () => {
const store = configureStore();
window.getState = store.getState;
window.dispatch = store.dispatch;
const root = document.getElementById('root');
ReactDOM.render(<h1>HELLO</h1>, root);
});
6 changes: 6 additions & 0 deletions frontend/reducers/entities/entities_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { combineReducers } from 'redux';
import usersReducer from './users_reducer';

export default combineReducers({
users: usersReducer
});
18 changes: 18 additions & 0 deletions frontend/reducers/entities/users_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RECEIVE_CURRENT_USER, RECEIVE_USER} from '../../actions/session_actions';

const usersReducer = (state = {}, action) => {
Object.freeze(state);

switch(action.type) {
case RECEIVE_CURRENT_USER:
const currentUser = {[action.user.id]: action.user}
return Object.assign({}, state, currentUser);
case RECEIVE_USER:
const newUser = {[action.user.id]: action.user}
return Object.assign({}, state, newUser)
default:
return state
}
}

export default usersReducer;
10 changes: 10 additions & 0 deletions frontend/reducers/errors/errors_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { combineReducers } from 'redux';
import sessionErrorsReducer from './session_errors_reducer';
import userErrorsReducer from './user_errors_reducer';

const errorsReducer = combineReducers({
session: sessionErrorsReducer,
user: userErrorsReducer
});

export default errorsReducer;
14 changes: 14 additions & 0 deletions frontend/reducers/errors/session_errors_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import {
RECEIVE_SIGNIN_ERRORS
} from '../../actions/session_actions';

const sessionErrorsReducer = (state = [], action) => {
switch(action.type) {
case RECEIVE_SIGNIN_ERRORS:
return action.errors;
default:
return state;
}
}

export default sessionErrorsReducer;
14 changes: 14 additions & 0 deletions frontend/reducers/errors/user_errors_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { RECEIVE_SIGNUP_ERRORS } from '../../actions/session_actions';

const userErrorsReducer = (state = [], action) => {
Object.freeze(state);

switch(action.type) {
case RECEIVE_SIGNUP_ERRORS:
return action.errors;
default:
return state;
}
}

export default userErrorsReducer;
28 changes: 14 additions & 14 deletions frontend/reducers/root_reducer.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// import { combineReducers } from 'redux';
// import entitiesReducer from './entities/entities_reducer';
// import sessionReducer from './session/session_reducer';
// import errorsReducer from './errors/errors_reducer';
// import uiReducer from './ui/ui_reducer';
//
// const rootReducer = combineReducers({
// entities: entitiesReducer,
// session: sessionReducer,
// errors: errorsReducer,
// ui: uiReducer
// });
//
// export default rootReducer;
import { combineReducers } from 'redux';
import entitiesReducer from './entities/entities_reducer';
import sessionReducer from './session/session_reducer';
import errorsReducer from './errors/errors_reducer';
import uiReducer from './ui/ui_reducer';

const rootReducer = combineReducers({
entities: entitiesReducer,
session: sessionReducer,
errors: errorsReducer,
ui: uiReducer
});

export default rootReducer;
18 changes: 18 additions & 0 deletions frontend/reducers/session/session_reducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RECEIVE_CURRENT_USER, LOGOUT_CURRENT_USER} from '../../actions/session_actions';

const empty = { currentUserId: null }

const sessionReducer = (state = empty, action) => {
Object.freeze(state);

switch(action.type) {
case RECEIVE_CURRENT_USER:
return {currentUserId: action.user.id};
case LOGOUT_CURRENT_USER:
return empty;
default:
return state;
}
};

export default sessionReducer;
Empty file.
14 changes: 14 additions & 0 deletions frontend/store/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { createStore, applyMiddleware } from 'redux';
import rootReducer from '../reducers/root_reducer';
import logger from 'redux-logger';
import thunk from 'redux-thunk';

const configureStore = (preloadedState = {}) => {
return createStore(
rootReducer,
preloadedState,
applyMiddleware(thunk, logger)
);
};

export default configureStore;
30 changes: 30 additions & 0 deletions frontend/util/route_util.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Route, Redirect, withRouter } from 'react-router-dom';
import { connect } from 'react-redux';
import React from 'react';

const Auth = ( { component: Component, path, exact, loggedIn}) => (
<Route path={path} exact={exact} render={(props) => (
loggedIn ? (
<Redirect to="/" />
) : (
<Component {...props} />
)
)} />
);

const Protected = ( { component: Component, path, exact, loggedIn}) => (
<Route path={path} exact={exact} render={(props) => (
loggedIn ? (
<Component {...props} />
) : (
<Redirect to="/" />
)
)} />
);

const mapStateToProps = state => ({
loggedIn: Boolean(state.session.currentUserId)
});

export const AuthRoute = withRouter(connect(mapStateToProps, null)(Auth));
export const ProtectedRoute = withRouter(connect(mapStateToProps)(Protected));
Loading

0 comments on commit 57ce763

Please sign in to comment.