mirror of
https://github.com/jellyfin/jellyfin-web
synced 2025-03-30 19:56:21 +00:00
Add date filter to activity table
This commit is contained in:
parent
aaa116d218
commit
07bb315bb3
5 changed files with 105 additions and 48 deletions
40
src/hooks/useLocale.tsx
Normal file
40
src/hooks/useLocale.tsx
Normal file
|
@ -0,0 +1,40 @@
|
|||
import type { Locale } from 'date-fns';
|
||||
import enUS from 'date-fns/locale/en-US';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
|
||||
import { getDefaultLanguage, normalizeLocaleName } from 'lib/globalize';
|
||||
import { fetchLocale, normalizeLocale } from 'utils/dateFnsLocale';
|
||||
|
||||
import { useUserSettings } from './useUserSettings';
|
||||
|
||||
export function useLocale() {
|
||||
const { dateTimeLocale: dateTimeSetting, language } = useUserSettings();
|
||||
const [ dateFnsLocale, setDateFnsLocale ] = useState<Locale>(enUS);
|
||||
|
||||
const locale = useMemo(() => (
|
||||
normalizeLocaleName(language || getDefaultLanguage())
|
||||
), [ language ]);
|
||||
|
||||
const dateTimeLocale = useMemo(() => (
|
||||
dateTimeSetting ? normalizeLocaleName(dateTimeSetting) : locale
|
||||
), [ dateTimeSetting, locale ]);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchDateFnsLocale = async () => {
|
||||
try {
|
||||
const dfLocale = await fetchLocale(normalizeLocale(dateTimeLocale));
|
||||
setDateFnsLocale(dfLocale);
|
||||
} catch (err) {
|
||||
console.warn('[useLocale] failed to fetch dateFns locale', err);
|
||||
}
|
||||
};
|
||||
|
||||
void fetchDateFnsLocale();
|
||||
}, [ dateTimeLocale ]);
|
||||
|
||||
return {
|
||||
locale,
|
||||
dateTimeLocale,
|
||||
dateFnsLocale
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue