Skip to content
Snippets Groups Projects
Commit 5c5a9d47 authored by Anthony's avatar Anthony
Browse files

Fix binding HMSInput / slider

parent 845e2cbf
Branches
No related tags found
1 merge request!10Draft: MigratingAnnotationCreation to MUI5.
Pipeline #1670 failed
...@@ -26,13 +26,15 @@ const StyledRoot = styled('div')({ ...@@ -26,13 +26,15 @@ const StyledRoot = styled('div')({
function HMSInput({ seconds, onChange }) { function HMSInput({ seconds, onChange }) {
const [hms, setHms] = useState(secondsToHMSarray(seconds)); const [hms, setHms] = useState(secondsToHMSarray(seconds));
console.log('hms', secondsToHMSarray(seconds));
console.log('seconds', seconds);
useEffect(() => { useEffect(() => {
setHms(secondsToHMSarray(seconds)); setHms(secondsToHMSarray(seconds));
}, [seconds]); }, [seconds]);
const someChange = (ev) => { const someChange = (ev) => {
const newState = { ...hms, [ev.target.name]: Number(ev.target.value) }; const newState = secondsToHMSarray(Number(ev.target.value));
setHms(newState); setHms(newState);
onChange(newState.hours * 3600 + newState.minutes * 60 + newState.seconds); onChange(newState.hours * 3600 + newState.minutes * 60 + newState.seconds);
}; };
......
...@@ -19,5 +19,9 @@ export function secondsToHMS(secs) { ...@@ -19,5 +19,9 @@ export function secondsToHMS(secs) {
/** Split a second to [hours, minutes, seconds] */ /** Split a second to [hours, minutes, seconds] */
export function secondsToHMSarray(secs) { export function secondsToHMSarray(secs) {
const h = Math.floor(secs / 3600); const h = Math.floor(secs / 3600);
return [h, Math.floor(secs / 60) - h * 60, secs % 60]; return {
hours: h,
minutes: Math.floor(secs / 60) - h * 60,
seconds: secs % 60,
};
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment