Permalink
Browse files

Implement logic to set the unit color from a ColorPicker

  • Loading branch information...
markerikson committed Jul 16, 2017
1 parent 2bfcd6e commit c0baa2f2843d0c023901fbd355a3a1aae8e93a3e
@@ -7,7 +7,7 @@ import {
} from "semantic-ui-react";
import {selectUnitInfo} from "../unitInfoSelectors";
import {updateUnitInfo} from "../unitInfoActions";
import {updateUnitInfo, setUnitColor} from "../unitInfoActions";
import {showColorPicker} from "common/components/ColorPicker/colorPickerActions";
import {getValueFromEvent} from "common/utils/clientUtils";
@@ -49,7 +49,9 @@ class UnitInfo extends Component {
}
onColorClicked = () => {
this.props.showColorPicker(this.props.unitInfo.color);
const onColorPickedAction = setUnitColor();
this.props.showColorPicker(this.props.unitInfo.color, onColorPickedAction);
}
@@ -1,8 +1,18 @@
import {UNIT_INFO_UPDATE} from "./unitInfoConstants";
import {
UNIT_INFO_UPDATE,
UNIT_INFO_SET_COLOR,
} from "./unitInfoConstants";
export function updateUnitInfo(values) {
return {
type : UNIT_INFO_UPDATE,
payload : values,
};
}
export function setUnitColor(color) {
return {
type : UNIT_INFO_SET_COLOR,
payload : {color}
};
}
@@ -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";
@@ -1,7 +1,10 @@
import {createReducer} from "common/utils/reducerUtils";
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 = {
name : "N/A",
@@ -22,7 +25,17 @@ function updateUnitInfo(state, payload) {
};
}
function setUnitColor(state, payload) {
const {color} = payload;
return {
...state,
color
};
}
export default createReducer(initialState, {
[DATA_LOADED] : dataLoaded,
[UNIT_INFO_UPDATE] : updateUnitInfo,
[UNIT_INFO_SET_COLOR] : setUnitColor,
});

0 comments on commit c0baa2f

Please sign in to comment.