From 5c5a9d472ce220e9c9df127ddc895ddce6171252 Mon Sep 17 00:00:00 2001
From: Anthony Geourjon <anthony.geourjon@tetras-libre.fr>
Date: Wed, 3 Jan 2024 14:41:14 +0100
Subject: [PATCH] Fix binding HMSInput / slider

---
 src/HMSInput.js | 4 +++-
 src/utils.js    | 6 +++++-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/HMSInput.js b/src/HMSInput.js
index 8270c58..84d0eed 100644
--- a/src/HMSInput.js
+++ b/src/HMSInput.js
@@ -26,13 +26,15 @@ const StyledRoot = styled('div')({
 
 function HMSInput({ seconds, onChange }) {
   const [hms, setHms] = useState(secondsToHMSarray(seconds));
+  console.log('hms', secondsToHMSarray(seconds));
+  console.log('seconds', seconds);
 
   useEffect(() => {
     setHms(secondsToHMSarray(seconds));
   }, [seconds]);
 
   const someChange = (ev) => {
-    const newState = { ...hms, [ev.target.name]: Number(ev.target.value) };
+    const newState = secondsToHMSarray(Number(ev.target.value));
     setHms(newState);
     onChange(newState.hours * 3600 + newState.minutes * 60 + newState.seconds);
   };
diff --git a/src/utils.js b/src/utils.js
index 4984a53..1b79b86 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -19,5 +19,9 @@ export function secondsToHMS(secs) {
 /** Split a second to [hours, minutes, seconds]  */
 export function secondsToHMSarray(secs) {
   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,
+  };
 }
-- 
GitLab