diff --git a/src/apps/dashboard/features/tasks/components/NewTriggerForm.tsx b/src/apps/dashboard/features/tasks/components/NewTriggerForm.tsx index 53404885fc..53d7663f3b 100644 --- a/src/apps/dashboard/features/tasks/components/NewTriggerForm.tsx +++ b/src/apps/dashboard/features/tasks/components/NewTriggerForm.tsx @@ -11,7 +11,7 @@ import type { TaskTriggerInfo } from '@jellyfin/sdk/lib/generated-client/models/ import { TaskTriggerInfoType } from '@jellyfin/sdk/lib/generated-client/models/task-trigger-info-type'; import { DayOfWeek } from '@jellyfin/sdk/lib/generated-client/models/day-of-week'; import globalize from 'lib/globalize'; -import { getTimeOfDayOptions } from '../utils/edit'; +import { getIntervalOptions, getTimeOfDayOptions } from '../utils/edit'; import { useLocale } from 'hooks/useLocale'; type IProps = { @@ -27,6 +27,8 @@ const NewTriggerForm: FunctionComponent = ({ open, title, onClose, onSub const timeOfDayOptions = useMemo(() => getTimeOfDayOptions(dateFnsLocale), [dateFnsLocale]); + const intervalOptions = useMemo(() => getIntervalOptions(dateFnsLocale), [dateFnsLocale]); + const onTriggerTypeChange = useCallback((e: React.ChangeEvent) => { setTriggerType(e.target.value); }, []); @@ -124,20 +126,12 @@ const NewTriggerForm: FunctionComponent = ({ open, title, onClose, onSub name='Interval' select fullWidth - defaultValue={'9000000000'} + defaultValue={intervalOptions[0].value} label={globalize.translate('LabelEveryXMinutes')} > - 15 minutes - 30 minutes - 45 minutes - 1 hour - 2 hours - 3 hours - 4 hours - 6 hours - 8 hours - 12 hours - 24 hours + {intervalOptions.map((option) => { + return {option.name}; + })} )} diff --git a/src/apps/dashboard/features/tasks/constants/intervalDuration.ts b/src/apps/dashboard/features/tasks/constants/intervalDuration.ts new file mode 100644 index 0000000000..01bd6ca7f5 --- /dev/null +++ b/src/apps/dashboard/features/tasks/constants/intervalDuration.ts @@ -0,0 +1,13 @@ +export const INTERVAL_DURATION: number[] = [ + 9000000000, // 15 minutes + 18000000000, // 30 minutes + 27000000000, // 45 minutes + 36000000000, // 1 hour + 72000000000, // 2 hours + 108000000000, // 3 hours + 144000000000, // 4 hours + 216000000000, // 6 hours + 288000000000, // 8 hours + 432000000000, // 12 hours + 864000000000 // 24 hours +]; diff --git a/src/apps/dashboard/features/tasks/utils/edit.ts b/src/apps/dashboard/features/tasks/utils/edit.ts index 2637465710..e71f563a71 100644 --- a/src/apps/dashboard/features/tasks/utils/edit.ts +++ b/src/apps/dashboard/features/tasks/utils/edit.ts @@ -1,6 +1,7 @@ import type { TaskTriggerInfo } from '@jellyfin/sdk/lib/generated-client/models/task-trigger-info'; -import { format, Locale, parse } from 'date-fns'; +import { format, formatDistanceStrict, Locale, parse } from 'date-fns'; import globalize from 'lib/globalize'; +import { INTERVAL_DURATION } from '../constants/intervalDuration'; function getDisplayTime(ticks: number, locale: Locale) { const ms = ticks / 1e4; @@ -23,6 +24,21 @@ export function getTimeOfDayOptions(locale: Locale) { return options; } +export function getIntervalOptions(locale: Locale) { + const options = []; + + for (const ticksDuration of INTERVAL_DURATION) { + const durationMs = Math.floor(ticksDuration / 1e4); + const unit = durationMs < 36e5 ? 'minute' : 'hour'; + options.push({ + name: formatDistanceStrict(0, durationMs, { locale: locale, unit: unit }), + value: ticksDuration + }); + } + + return options; +} + function getIntervalTriggerTime(ticks: number) { const hours = ticks / 36e9;