fix(ui): fix duration minute decrease handling

Negative adjustment needs a different logic than positive one
This commit is contained in:
Łukasz Mierzwa
2018-08-29 23:38:14 +01:00
parent e7b17f5326
commit ec16a1cbce

View File

@@ -107,8 +107,8 @@ const TabContentEnd = observer(({ silenceFormStore }) => {
);
});
// calculate value for duration increase and decrease buttons using a goal step
const CalculateChangeValue = (currentValue, step) => {
// calculate value for duration increase button using a goal step
const CalculateChangeValueUp = (currentValue, step) => {
// if current value is less than step (but >0) then use 1
if (currentValue > 0 && currentValue < step) {
return 1;
@@ -117,6 +117,16 @@ const CalculateChangeValue = (currentValue, step) => {
return step - (currentValue % step) || step;
};
// calculate value for duration decrease button using a goal step
const CalculateChangeValueDown = (currentValue, step) => {
// if current value is less than step (but >0) then use 1
if (currentValue > 0 && currentValue < step) {
return 1;
}
// otherwise use step or a value that moves current value to the next step
return currentValue % step || step;
};
const TabContentDuration = observer(({ silenceFormStore }) => {
return (
<div className="d-flex flex-sm-row flex-column justify-content-around mt-2 mx-3">
@@ -137,12 +147,15 @@ const TabContentDuration = observer(({ silenceFormStore }) => {
value={silenceFormStore.data.toDuration.minutes}
onInc={() =>
silenceFormStore.data.incEnd(
CalculateChangeValue(silenceFormStore.data.toDuration.minutes, 5)
CalculateChangeValueUp(silenceFormStore.data.toDuration.minutes, 5)
)
}
onDec={() =>
silenceFormStore.data.decEnd(
CalculateChangeValue(silenceFormStore.data.toDuration.minutes, 5)
CalculateChangeValueDown(
silenceFormStore.data.toDuration.minutes,
5
)
)
}
/>