Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

changed app and homepage to redux components added set up reducers and actions #41

Open
wants to merge 5 commits into
base: redux
Choose a base branch
from
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ node_modules
web/src/theme\.css

web/build/

#secrets
.env
4 changes: 2 additions & 2 deletions config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"production": false,
"db": {
"host": "localhost",
"user": "myrmey",
"user": "postgres",
"password": "",
"database": "myrmey",
"database": "postgres",
"port": "5432"
},
"watchlist": {
Expand Down
5 changes: 4 additions & 1 deletion web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
"react-big-calendar": "^0.17.0",
"react-dom": "^16.0.0",
"react-notification-system": "^0.2.16",
"react-scripts": "1.0.14"
"react-redux": "^5.0.6",
"react-scripts": "1.0.14",
"redux": "^3.7.2",
"redux-thunk": "^2.2.0"
},
"scripts": {
"build-css": "node-sass-chokidar src/theme.scss -o src/",
Expand Down
9 changes: 8 additions & 1 deletion web/src/App.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import update from 'immutability-helper';
import NotificationSystem from 'react-notification-system';

Expand Down Expand Up @@ -382,6 +383,8 @@ class App extends Component {
data: this.state[this.state.currScreen]
}

console.log(this.props.user);

return (
<div className="App">
<HomePage user={this.state.user} schedule={this.state.schedule} removePlannedCourse={this.removePlannedCourse} screen={screen} openLogin={this.openLogin} popScreen={this.state.history.length > 0 ? this.popScreen : undefined} />
Expand All @@ -392,4 +395,8 @@ class App extends Component {
}
}

export default App;
export default connect((store) => {
return {
user: store.userState.user,
}
})(App);
7 changes: 6 additions & 1 deletion web/src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import App from './App';
import store from './redux/store.js';
import registerServiceWorker from './registerServiceWorker';
import './theme.css';

ReactDOM.render(<App />, document.getElementById('root'));
ReactDOM.render(
<Provider store = { store }>
<App />
</Provider>, document.getElementById('root'));
registerServiceWorker();
8 changes: 7 additions & 1 deletion web/src/pages/home/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, { Component } from 'react';
import { connect } from 'react-redux';
import Schedule from '../../components/Schedule';
import Inspector from '../../components/Inspector';
import './style.css';
import myrmey from '../../assets/myrmey.svg';

class HomePage extends Component {
render() {
console.log(this.props.user.user);
return (
<div>
<nav className="navbar is-light">
Expand Down Expand Up @@ -48,4 +50,8 @@ class HomePage extends Component {
}
}

export default HomePage;
export default connect((store) => {
return {
user: store.userState.user,
}
})(HomePage);
6 changes: 6 additions & 0 deletions web/src/redux/actions/actionCreators.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export function setUser(data) {
return {
type:'SET_USER',
data:data,
}
}
6 changes: 6 additions & 0 deletions web/src/redux/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { combineReducers } from 'redux';
import userState from './userReducer.js';

export default combineReducers({
userState,
})
20 changes: 20 additions & 0 deletions web/src/redux/reducers/userReducer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
const initialState = {
user: false,
}

function userReducer (state = initialState, action) {
switch(action.type){
case 'TEST':
return Object.assign({}, state, {
user: {
myrmeyid: '1234',
studentInfo: 'i love league',
advice: 'go to school',
courses: 'noobstomping 101',
}, });
default:
return state;
}
}

export default userReducer;
8 changes: 8 additions & 0 deletions web/src/redux/store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { createStore, applyMiddleware } from 'redux';
import reducer from './reducers/index.js';
import thunk from 'redux-thunk';

var middleWare = applyMiddleware(thunk);
var store = createStore(reducer, middleWare);

export default store;