Skip to content

Commit

Permalink
Implement logic to set the unit color from a ColorPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
markerikson committed Jul 20, 2017
1 parent 2bfcd6e commit c0baa2f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
6 changes: 4 additions & 2 deletions src/features/unitInfo/UnitInfo/UnitInfo.jsx
Expand Up @@ -7,7 +7,7 @@ import {
} from "semantic-ui-react"; } from "semantic-ui-react";


import {selectUnitInfo} from "../unitInfoSelectors"; import {selectUnitInfo} from "../unitInfoSelectors";
import {updateUnitInfo} from "../unitInfoActions"; import {updateUnitInfo, setUnitColor} from "../unitInfoActions";
import {showColorPicker} from "common/components/ColorPicker/colorPickerActions"; import {showColorPicker} from "common/components/ColorPicker/colorPickerActions";
import {getValueFromEvent} from "common/utils/clientUtils"; import {getValueFromEvent} from "common/utils/clientUtils";


Expand Down Expand Up @@ -49,7 +49,9 @@ class UnitInfo extends Component {
} }


onColorClicked = () => { onColorClicked = () => {
this.props.showColorPicker(this.props.unitInfo.color); const onColorPickedAction = setUnitColor();

this.props.showColorPicker(this.props.unitInfo.color, onColorPickedAction);
} }




Expand Down
12 changes: 11 additions & 1 deletion src/features/unitInfo/unitInfoActions.js
@@ -1,8 +1,18 @@
import {UNIT_INFO_UPDATE} from "./unitInfoConstants"; import {
UNIT_INFO_UPDATE,
UNIT_INFO_SET_COLOR,
} from "./unitInfoConstants";


export function updateUnitInfo(values) { export function updateUnitInfo(values) {
return { return {
type : UNIT_INFO_UPDATE, type : UNIT_INFO_UPDATE,
payload : values, payload : values,
}; };
}

export function setUnitColor(color) {
return {
type : UNIT_INFO_SET_COLOR,
payload : {color}
};
} }
3 changes: 2 additions & 1 deletion src/features/unitInfo/unitInfoConstants.js
@@ -1 +1,2 @@
export const UNIT_INFO_UPDATE = "UNIT_INFO_UPDATE"; export const UNIT_INFO_UPDATE = "UNIT_INFO_UPDATE";
export const UNIT_INFO_SET_COLOR = "UNIT_INFO_SET_COLOR";
15 changes: 14 additions & 1 deletion src/features/unitInfo/unitInfoReducer.js
@@ -1,7 +1,10 @@
import {createReducer} from "common/utils/reducerUtils"; import {createReducer} from "common/utils/reducerUtils";


import {DATA_LOADED} from "features/tools/toolConstants"; import {DATA_LOADED} from "features/tools/toolConstants";
import {UNIT_INFO_UPDATE} from "./unitInfoConstants"; import {
UNIT_INFO_UPDATE,
UNIT_INFO_SET_COLOR,
} from "./unitInfoConstants";


const initialState = { const initialState = {
name : "N/A", name : "N/A",
Expand All @@ -22,7 +25,17 @@ function updateUnitInfo(state, payload) {
}; };
} }


function setUnitColor(state, payload) {
const {color} = payload;

return {
...state,
color
};
}

export default createReducer(initialState, { export default createReducer(initialState, {
[DATA_LOADED] : dataLoaded, [DATA_LOADED] : dataLoaded,
[UNIT_INFO_UPDATE] : updateUnitInfo, [UNIT_INFO_UPDATE] : updateUnitInfo,
[UNIT_INFO_SET_COLOR] : setUnitColor,
}); });

0 comments on commit c0baa2f

Please sign in to comment.