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) {