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

[WIP] Redux store #927

Open
wants to merge 20 commits into
base: dev
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
69 changes: 65 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,21 @@
"ajv": "6.5.4",
"chart.js": "2.7.2",
"highcharts": "^6.2.0",
"immutable": "^3.8.2",
"lodash": "4.17.10",
"moment": "2.22.1",
"react": "16.3.2",
"react-chartjs-2": "2.7.2",
"react-dom": "16.3.2",
"react-helmet": "5.2.0",
"react-immutable-proptypes": "^2.1.0",
"react-jsx-highcharts": "^3.3.1-alpha.1",
"react-redux": "^5.0.7",
"react-router": "4.2.0",
"react-router-dom": "4.2.2",
"react-scripts": "1.1.5",
"redux": "^4.0.1",
"redux-immutable": "^4.0.0",
"semantic-ui-css": "2.2.12",
"semantic-ui-react": "0.75.1"
},
Expand Down
138 changes: 138 additions & 0 deletions src/actions/client.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
export const SET_CLIENT_VALUE = 'SET_CLIENT_VALUE';

export const setClientValue = ({ time, route, value }) => {
return {
type: SET_CLIENT_VALUE,
payload: {
time,
route,
value,
},
};
};

export const REMOVE_MEMBER = 'REMOVE_MEMBER';

export const removeMember = ({ time = 'current', index }) => {
return {
type: REMOVE_MEMBER,
payload: {
time,
index,
},
};
};

export const ADD_MEMBER = 'ADD_MEMBER';

export const addMember = ({ time = 'current', member }) => {
return {
type: ADD_MEMBER,
payload: {
time,
member,
},
};
};

export const SET_MEMBER_IS_DISABLED = 'SET_MEMBER_IS_DISABLED';

export const setMemberIsDisabled = ({ time = 'current', index, isDisabled }) => {
return {
type: SET_MEMBER_IS_DISABLED,
payload: {
time,
index,
isDisabled: !!isDisabled,
},
};
};

export const SET_MEMBER_ROLE = 'SET_MEMBER_ROLE';

export const setMemberRole = ({ time = 'current', index, role }) => {
return {
type: SET_MEMBER_ROLE,
payload: {
time,
index,
role,
},
};
};

export const SET_MEMBER_AGE = 'SET_MEMBER_AGE';

export const setMemberAge = ({ time = 'current', index, age }) => {
return {
type: SET_MEMBER_AGE,
payload: {
time,
index,
age,
},
};
};

export const SET_CASH_VALUE = 'SET_CASH_VALUE';

export const setCashValue = ({ time, name, value }) => {
return {
type: SET_CASH_VALUE,
payload: {
time,
name,
value,
},
};
};

export const SET_HOUSING_TYPE = 'SET_HOUSING_TYPE';

export const setHousingType = ({ time, housingType }) => {
return {
type: SET_HOUSING_TYPE,
payload: {
time,
housingType,
},
};
};

export const SET_PAYS_UTILITY = 'SET_PAYS_UTILITY';

export const setPaysUtility = ({ time, utility, paysUtility }) => {
return {
type: SET_PAYS_UTILITY,
payload: {
time,
utility,
paysUtility,
},
};
};

export const SET_GETS_FUEL_ASSISTANCE = 'SET_GETS_FUEL_ASSISTANCE';

export const setGetsFuelAssistance = ({ time, getsAssistance }) => {
return {
type: SET_GETS_FUEL_ASSISTANCE,
payload: {
time,
getsAssistance,
},
};
};

export const SET_HAS_BENEFIT = 'SET_HAS_BENEFIT';

export const setHasBenefit = ({ time, benefit, value }) => {
return {
type: SET_HAS_BENEFIT,
payload: {
time,
benefit,
value: !!value,
},
};
};
8 changes: 8 additions & 0 deletions src/actions/geography.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SET_US_STATE = 'SET_US_STATE';

export const setUSState = ({ state }) => {
return {
type: SET_US_STATE,
payload: { state },
};
};
3 changes: 3 additions & 0 deletions src/actions/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './geography';
export * from './localization';
export * from './client';
8 changes: 8 additions & 0 deletions src/actions/localization.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export const SET_LANGUAGE = 'SET_LANGUAGE';

export const setLanguage = ({ language }) => {
return {
type: SET_LANGUAGE,
payload: { language },
};
};
27 changes: 16 additions & 11 deletions src/App.js → src/components/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ import {
} from 'react-router-dom';
import { Helmet } from 'react-helmet';

import { Confirmer } from './utils/getUserConfirmation';
import { Confirmer } from '../utils/getUserConfirmation';

// CUSTOM COMPONENTS
import HomePage from './containers/HomePage';
import AboutPage from './containers/AboutPage';
import VisitPage from './containers/VisitPage';
import Footer from './components/Footer';
import Header from './components/Header';
import HomePage from '../containers/HomePage';
import AboutPage from '../containers/AboutPage';
import VisitPage from '../containers/VisitPage';
import Footer from './Footer';
import Header from './Header';

// Development HUD
import { DevSwitch } from './containers/DevSwitch';
import { DevHud } from './components/dev/DevHud';
import { DevSwitch } from '../containers/DevSwitch';
import { DevHud } from './dev/DevHud';

// Object Manipulation
import { cloneDeep } from 'lodash';
import { CLIENT_DEFAULTS } from './utils/CLIENT_DEFAULTS';
import { CLIENT_DEFAULTS } from '../utils/CLIENT_DEFAULTS';

// LOCALIZATION
import { getTextForLanguage } from './utils/getTextForLanguage';
import { getTextForLanguage } from '../utils/getTextForLanguage';



/**
* Main top-level component of the app. Contains the router that controls access
Expand Down Expand Up @@ -88,6 +90,9 @@ class App extends Component {
},
distrustConfirmed: false,
};

this.props.setLanguage({ language: this.state.langCode });
this.props.setUSState({ state: 'MA' });
}; // End constructor()

/**
Expand All @@ -101,6 +106,7 @@ class App extends Component {
setLanguage = (evnt, inputProps) => {
let snippets = getTextForLanguage(inputProps.value);
this.setState({ language: inputProps.value, snippets: snippets });
this.props.setLanguage({ language: inputProps.value });
};

/** Set the value of a specified key in the app state's devProps.
Expand Down Expand Up @@ -277,5 +283,4 @@ class App extends Component {
}; // End render()
}


export default App;
31 changes: 31 additions & 0 deletions src/configure-store.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/* global module, process */

import { createStore, compose } from 'redux';
import { Map } from 'immutable';
import createReducer from './reducers';


export default function configureStore(initialState = Map()) {
// If Redux DevTools Extension is installed use it, otherwise use Redux compose
const composeEnhancers = process.env.NODE_ENV !== 'production' &&
typeof window === 'object' &&
window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__({})
: compose;

const store = createStore(
createReducer(),
initialState,
composeEnhancers()
);

// Make reducers hot reloadable, see http://mxs.is/googmo
/* istanbul ignore next */
if (module.hot) {
module.hot.accept('./reducers', () => {
store.replaceReducer(createReducer());
});
}

return store;
}
Loading