From 9e771a2f2433a4f22c99e9dedd2d6768ec2762db Mon Sep 17 00:00:00 2001 From: Brian Rodgers Date: Sun, 29 Mar 2026 15:51:14 -0500 Subject: [PATCH] refactor: format times in editor based on project time format --- .../components/input/time-input/TimeInput.tsx | 13 ++++++++++--- apps/client/src/common/utils/time.ts | 2 +- .../panel/settings-panel/GeneralSettings.tsx | 2 +- .../app-settings/quick-start/QuickStart.tsx | 2 +- .../client/src/features/overview/EditorOverview.tsx | 12 ++++++------ .../features/rundown/entry-editor/GroupEditor.tsx | 7 ++++--- .../entry-editor/composite/EventEditorTimes.tsx | 7 +++---- .../features/rundown/rundown-group/RundownGroup.tsx | 10 +++++----- .../rundown/time-input-flow/TimeInputFlow.tsx | 2 ++ .../time-input-flow/TimeInputGroup.module.scss | 2 +- 10 files changed, 34 insertions(+), 25 deletions(-) diff --git a/apps/client/src/common/components/input/time-input/TimeInput.tsx b/apps/client/src/common/components/input/time-input/TimeInput.tsx index 9ce94785d..98136c402 100644 --- a/apps/client/src/common/components/input/time-input/TimeInput.tsx +++ b/apps/client/src/common/components/input/time-input/TimeInput.tsx @@ -1,7 +1,8 @@ import { millisToString, parseUserTime } from 'ontime-utils'; -import { FocusEvent, KeyboardEvent, useCallback, useEffect, useRef, useState } from 'react'; +import { FocusEvent, KeyboardEvent, useCallback, useEffect, useMemo, useRef, useState } from 'react'; import { cx } from '../../../utils/styleUtils'; +import { formatTime, getFormatFromSettings } from '../../../utils/time'; import Input from '../input/Input'; import style from './TimeInput.module.scss'; @@ -16,6 +17,7 @@ interface TimeInputProps { align?: 'left' | 'center'; delayed?: boolean; className?: string; + shouldFormat?: boolean; } export default function TimeInput({ @@ -28,10 +30,12 @@ export default function TimeInput({ align = 'center', delayed, className, + shouldFormat, }: TimeInputProps) { const inputRef = useRef(null); const [value, setValue] = useState(''); const ignoreChange = useRef(false); + const formatAs12Hr = useMemo(() => shouldFormat && getFormatFromSettings() === '12', [shouldFormat]); /** * @description Resets input value to given @@ -39,10 +43,12 @@ export default function TimeInput({ const resetValue = useCallback(() => { if (typeof time !== 'number' || isNaN(time)) { setValue('00:00:00'); + } else if (shouldFormat) { + setValue(formatTime(time)); } else { setValue(millisToString(time)); } - }, [time]); + }, [time, shouldFormat]); /** * @description Selects input text on focus @@ -139,9 +145,10 @@ export default function TimeInput({ onBlur={onBlurHandler} onKeyDown={onKeyDownHandler} value={value} - maxLength={8} + maxLength={formatAs12Hr ? 11 : 8} style={{ textAlign: align, + width: formatAs12Hr ? '7.5em' : '6.5em', }} /> ); diff --git a/apps/client/src/common/utils/time.ts b/apps/client/src/common/utils/time.ts index 392ab6320..0dce7c63a 100644 --- a/apps/client/src/common/utils/time.ts +++ b/apps/client/src/common/utils/time.ts @@ -42,7 +42,7 @@ function getFormatFromParams() { * Gets the format options from the applicaton settings * @returns a string equivalent to the format, ie: hh:mm:ss a or HH:mm:ss */ -function getFormatFromSettings(): TimeFormat { +export function getFormatFromSettings(): TimeFormat { const settings: Settings | undefined = ontimeQueryClient.getQueryData(APP_SETTINGS); return settings?.timeFormat ?? '24'; } diff --git a/apps/client/src/features/app-settings/panel/settings-panel/GeneralSettings.tsx b/apps/client/src/features/app-settings/panel/settings-panel/GeneralSettings.tsx index 5478d9e0e..1f402581c 100644 --- a/apps/client/src/features/app-settings/panel/settings-panel/GeneralSettings.tsx +++ b/apps/client/src/features/app-settings/panel/settings-panel/GeneralSettings.tsx @@ -94,7 +94,7 @@ export default function GeneralSettings() { {submitError && {submitError}} - Changes to the time format and views language do not affect the editor view + Changes to the views language does not affect the editor view diff --git a/apps/client/src/features/app-settings/quick-start/QuickStart.tsx b/apps/client/src/features/app-settings/quick-start/QuickStart.tsx index 991fbf748..a6e3dcfa9 100644 --- a/apps/client/src/features/app-settings/quick-start/QuickStart.tsx +++ b/apps/client/src/features/app-settings/quick-start/QuickStart.tsx @@ -69,7 +69,7 @@ export default function QuickStart({ isOpen, onClose }: QuickStartProps) {