feat: increment

This commit is contained in:
cha0s 2020-06-21 21:33:12 -05:00
parent 8202e27202
commit 370e04e005
3 changed files with 42 additions and 4 deletions

View File

@ -10,6 +10,10 @@ const decorate = compose(
);
const Number = ({
dispatchers: {
onChange = () => {},
onIncrement = () => {},
},
options,
value,
}) => (
@ -26,14 +30,24 @@ const Number = ({
: (
<>
<input
onChange={(event) => onChange(event.target.value)}
// onWheel={(e) => (e.preventDefault(), false)}
readOnly
type="text"
value={value}
/>
<div className="controls">
<button type="button">+</button>
<button type="button">-</button>
<button
onClick={() => onIncrement(1)}
type="button"
>
+
</button>
<button
onClick={() => onIncrement(-1)}
type="button"
>
-
</button>
</div>
</>
)

View File

@ -67,6 +67,22 @@ const slice = createSlice({
name: 'entities',
initialState: adapter.getInitialState({uris: {}}),
reducers: {
incrementTraitProperty: (state, {
payload: {
target,
trait,
type,
key,
value,
},
}) => {
const {traits} = state.entities[target];
traits[trait] = traits[trait] || {};
traits[trait][type] = traits[trait][type] || {};
traits[trait][type][key] = traits[trait][type][key] || 0;
traits[trait][type][key] += parseFloat(value);
state.entities[target].traits = traits;
},
setTraitProperty: (state, {
payload: {
target,
@ -94,6 +110,7 @@ const slice = createSlice({
});
export const {
incrementTraitProperty,
setTraitProperty,
} = slice.actions;

View File

@ -7,7 +7,7 @@ import {useDispatch} from 'react-redux';
import Value from '~/client/value';
import {setTraitProperty} from './state';
import {incrementTraitProperty, setTraitProperty} from './state';
let TraitComponents;
const ensureTraitComponents = () => {
@ -52,6 +52,13 @@ const makePane = (context, dispatch, target, type) => (trait) => {
key,
value,
})),
onIncrement: (value) => dispatch(incrementTraitProperty({
target,
trait: type,
type: traitHalf,
key,
value,
})),
}}
options={options}
value={values[key]}