mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Localize interval
This commit is contained in:
parent
524d1b6574
commit
934a05cffa
3 changed files with 37 additions and 14 deletions
|
@ -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<IProps> = ({ open, title, onClose, onSub
|
|||
|
||||
const timeOfDayOptions = useMemo(() => getTimeOfDayOptions(dateFnsLocale), [dateFnsLocale]);
|
||||
|
||||
const intervalOptions = useMemo(() => getIntervalOptions(dateFnsLocale), [dateFnsLocale]);
|
||||
|
||||
const onTriggerTypeChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
|
||||
setTriggerType(e.target.value);
|
||||
}, []);
|
||||
|
@ -124,20 +126,12 @@ const NewTriggerForm: FunctionComponent<IProps> = ({ open, title, onClose, onSub
|
|||
name='Interval'
|
||||
select
|
||||
fullWidth
|
||||
defaultValue={'9000000000'}
|
||||
defaultValue={intervalOptions[0].value}
|
||||
label={globalize.translate('LabelEveryXMinutes')}
|
||||
>
|
||||
<MenuItem value='9000000000'>15 minutes</MenuItem>
|
||||
<MenuItem value='18000000000'>30 minutes</MenuItem>
|
||||
<MenuItem value='27000000000'>45 minutes</MenuItem>
|
||||
<MenuItem value='36000000000'>1 hour</MenuItem>
|
||||
<MenuItem value='72000000000'>2 hours</MenuItem>
|
||||
<MenuItem value='108000000000'>3 hours</MenuItem>
|
||||
<MenuItem value='144000000000'>4 hours</MenuItem>
|
||||
<MenuItem value='216000000000'>6 hours</MenuItem>
|
||||
<MenuItem value='288000000000'>8 hours</MenuItem>
|
||||
<MenuItem value='432000000000'>12 hours</MenuItem>
|
||||
<MenuItem value='864000000000'>24 hours</MenuItem>
|
||||
{intervalOptions.map((option) => {
|
||||
return <MenuItem key={option.value} value={option.value}>{option.name}</MenuItem>;
|
||||
})}
|
||||
</TextField>
|
||||
)}
|
||||
|
||||
|
|
|
@ -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
|
||||
];
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue