From 319cb3ab02a9b9e1d4b45f3724b717cf33dbdcf9 Mon Sep 17 00:00:00 2001
From: cv <34649812+cpvalente@users.noreply.github.com>
Date: Tue, 13 Apr 2021 09:33:08 +0200
Subject: [PATCH] delay input
- temporary fix due to issues with slider component
---
client/src/common/input/TimeInput.jsx | 46 ++++++++++++++++
client/src/common/input/TimeInput.module.css | 9 ++++
.../src/features/editors/list/DelayBlock.jsx | 54 +++++--------------
3 files changed, 69 insertions(+), 40 deletions(-)
create mode 100644 client/src/common/input/TimeInput.jsx
create mode 100644 client/src/common/input/TimeInput.module.css
diff --git a/client/src/common/input/TimeInput.jsx b/client/src/common/input/TimeInput.jsx
new file mode 100644
index 000000000..f62b60370
--- /dev/null
+++ b/client/src/common/input/TimeInput.jsx
@@ -0,0 +1,46 @@
+import { Editable, EditableInput, EditablePreview } from '@chakra-ui/react';
+import { useEffect, useState } from 'react';
+import style from './TimeInput.module.css';
+
+const inputProps = {
+ width: 20,
+ backgroundColor: '#fff5',
+ placeholder: '-',
+ textAlign: 'center',
+};
+
+export default function TimeInput(props) {
+ const [value, setValue] = useState(props.value);
+
+ useEffect(() => {
+ if (props.value === null) return;
+ setValue(props.value);
+ }, [props.value]);
+
+ const handleChange = (val) => {
+ if (val <= 999) setValue(val);
+ };
+
+ const handleSubmit = (val) => {
+ if (val === props.value) return;
+ if (val === '') setValue(0);
+ if (val > 0 && val < 60) {
+ props.submitHandler(val);
+ }
+ };
+
+ return (
+
+ handleChange(v)}
+ onSubmit={(v) => handleSubmit(v)}
+ >
+
+
+
+ {'(min)'}
+
+ );
+}
diff --git a/client/src/common/input/TimeInput.module.css b/client/src/common/input/TimeInput.module.css
new file mode 100644
index 000000000..c0654b99b
--- /dev/null
+++ b/client/src/common/input/TimeInput.module.css
@@ -0,0 +1,9 @@
+.timeInput {
+ display: flex;
+ font-size: 15px;
+}
+
+.label {
+ color: #0005;
+ padding-left: 0.8em;
+}
diff --git a/client/src/features/editors/list/DelayBlock.jsx b/client/src/features/editors/list/DelayBlock.jsx
index 0bd4a591f..ce458872a 100644
--- a/client/src/features/editors/list/DelayBlock.jsx
+++ b/client/src/features/editors/list/DelayBlock.jsx
@@ -1,58 +1,32 @@
-import { Box } from '@chakra-ui/layout';
-import {
- Slider,
- SliderFilledTrack,
- SliderThumb,
- SliderTrack,
-} from '@chakra-ui/slider';
import { useEffect, useState } from 'react';
import AddIconBtn from '../../../common/components/buttons/AddIconBtn';
import DeleteIconBtn from '../../../common/components/buttons/DeleteIconBtn';
+import { millisToMinutes } from '../../../common/dateConfig';
+import TimeInput from '../../../common/input/TimeInput';
import style from './Block.module.css';
export default function DelayBlock(props) {
- const [delay, setDelay] = useState(0);
- const { data, eventsHandler, index, updateData } = props;
+ const { data, eventsHandler, index } = props;
- // update delay value in parent
- const populateDelay = (value) => {
- // check if value has changed
- if (data.timerDuration !== value) {
- // create object with new field
- const newData = { ...data, timerDuration: delay };
-
- // request update in parent
- updateData(index, newData);
- }
- };
-
- // update delay value in state
- useEffect(() => {
- setDelay(data.timerDuration);
- }, [data]);
const addHandler = () => {
+ eventsHandler('add', { type: 'event', order: index + 1 });
};
+
+ const submitHandler = (value) => {
+ // convert to ms and patch
+ eventsHandler('patch', { id: data.id, duration: value * 1000 * 60 });
+ };
+
const deleteHandler = () => {
eventsHandler('delete', data.id);
};
return (
-
{`${delay} min`}
-
setDelay(value)}
- onChangeEnd={(value) => populateDelay(value)}
- >
-
-
-
-
-
-
+