From c0baa2f2843d0c023901fbd355a3a1aae8e93a3e Mon Sep 17 00:00:00 2001 From: Mark Erikson Date: Sun, 16 Jul 2017 16:16:40 -0400 Subject: [PATCH] Implement logic to set the unit color from a ColorPicker --- src/features/unitInfo/UnitInfo/UnitInfo.jsx | 6 ++++-- src/features/unitInfo/unitInfoActions.js | 12 +++++++++++- src/features/unitInfo/unitInfoConstants.js | 3 ++- src/features/unitInfo/unitInfoReducer.js | 15 ++++++++++++++- 4 files changed, 31 insertions(+), 5 deletions(-) diff --git a/src/features/unitInfo/UnitInfo/UnitInfo.jsx b/src/features/unitInfo/UnitInfo/UnitInfo.jsx index 906e1a4..a833d6a 100644 --- a/src/features/unitInfo/UnitInfo/UnitInfo.jsx +++ b/src/features/unitInfo/UnitInfo/UnitInfo.jsx @@ -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); } diff --git a/src/features/unitInfo/unitInfoActions.js b/src/features/unitInfo/unitInfoActions.js index 501d511..4de457b 100644 --- a/src/features/unitInfo/unitInfoActions.js +++ b/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) { return { type : UNIT_INFO_UPDATE, payload : values, }; +} + +export function setUnitColor(color) { + return { + type : UNIT_INFO_SET_COLOR, + payload : {color} + }; } \ No newline at end of file diff --git a/src/features/unitInfo/unitInfoConstants.js b/src/features/unitInfo/unitInfoConstants.js index bb0164a..b06ee64 100644 --- a/src/features/unitInfo/unitInfoConstants.js +++ b/src/features/unitInfo/unitInfoConstants.js @@ -1 +1,2 @@ -export const UNIT_INFO_UPDATE = "UNIT_INFO_UPDATE"; \ No newline at end of file +export const UNIT_INFO_UPDATE = "UNIT_INFO_UPDATE"; +export const UNIT_INFO_SET_COLOR = "UNIT_INFO_SET_COLOR"; \ No newline at end of file diff --git a/src/features/unitInfo/unitInfoReducer.js b/src/features/unitInfo/unitInfoReducer.js index 8556ece..751fff0 100644 --- a/src/features/unitInfo/unitInfoReducer.js +++ b/src/features/unitInfo/unitInfoReducer.js @@ -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, }); \ No newline at end of file