Skip to content

Commit 6790121

Browse files
committed
Fix: Better handling of timestamp value
1 parent c4b8c00 commit 6790121

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

Resources/Private/Editor/Editors/Timestamp.jsx

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,10 @@ const styles = stylex.create({
4747

4848
function Timestamp({ id, value, commit, highlight, options, i18nRegistry, config, onEnterKey }) {
4949
const { disabled, readonly, min, max, subtractFromMax } = { ...defaultOptions, ...config, ...options };
50-
const [hours, setHours] = useState(0);
51-
const [minutes, setMinutes] = useState(0);
52-
const [seconds, setSeconds] = useState(0);
50+
const hms = secondsToHMS(value || 0);
51+
const [hours, setHours] = useState(hms.hours);
52+
const [minutes, setMinutes] = useState(hms.minutes);
53+
const [seconds, setSeconds] = useState(hms.seconds);
5354

5455
const updateHMS = (hms) => {
5556
if (hms.hours !== hours) {
@@ -63,17 +64,17 @@ function Timestamp({ id, value, commit, highlight, options, i18nRegistry, config
6364
}
6465
};
6566

66-
// Update on init
6767
useEffect(() => {
6868
updateHMS(secondsToHMS(value || 0));
69-
}, []);
69+
}, [value]);
7070

7171
useEffect(() => {
7272
const total = minMaxSeconds(getTotalSeconds(hours, minutes, seconds), min, max, subtractFromMax);
73-
updateHMS(secondsToHMS(total));
7473
if (total !== value) {
7574
commit(total);
75+
return;
7676
}
77+
updateHMS(secondsToHMS(total));
7778
}, [hours, minutes, seconds]);
7879

7980
const showMinutes = enableMinutes(value, min, max);

0 commit comments

Comments
 (0)