Better types for useFormatDistance
This commit is contained in:
@@ -27,29 +27,30 @@ import {
|
|||||||
zhTW,
|
zhTW,
|
||||||
} from 'date-fns/locale'
|
} from 'date-fns/locale'
|
||||||
|
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
||||||
import {AppLanguage} from '#/locale/languages'
|
import {AppLanguage} from '#/locale/languages'
|
||||||
import {useLanguagePrefs} from '#/state/preferences'
|
import {useLanguagePrefs} from '#/state/preferences'
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link AppLanguage}
|
* {@link AppLanguage}
|
||||||
*/
|
*/
|
||||||
const locales: Record<string, Locale> = {
|
const locales: Record<AppLanguage, Locale | undefined> = {
|
||||||
|
en: undefined,
|
||||||
ca,
|
ca,
|
||||||
de,
|
de,
|
||||||
es,
|
es,
|
||||||
fi,
|
fi,
|
||||||
fr,
|
fr,
|
||||||
|
ga: undefined,
|
||||||
hi,
|
hi,
|
||||||
id,
|
id,
|
||||||
it,
|
it,
|
||||||
ja,
|
ja,
|
||||||
ko,
|
ko,
|
||||||
ptBR,
|
['pt-BR']: ptBR,
|
||||||
tr,
|
tr,
|
||||||
uk,
|
uk,
|
||||||
zhCN,
|
['zh-CN']: zhCN,
|
||||||
zhTW,
|
['zh-TW']: zhTW,
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +61,7 @@ export function useFormatDistance() {
|
|||||||
const {appLanguage} = useLanguagePrefs()
|
const {appLanguage} = useLanguagePrefs()
|
||||||
return React.useCallback<typeof formatDistance>(
|
return React.useCallback<typeof formatDistance>(
|
||||||
(date, baseDate, options) => {
|
(date, baseDate, options) => {
|
||||||
const locale = locales[appLanguage]
|
const locale = locales[appLanguage as AppLanguage]
|
||||||
return formatDistance(date, baseDate, {...options, locale: locale})
|
return formatDistance(date, baseDate, {...options, locale: locale})
|
||||||
},
|
},
|
||||||
[appLanguage],
|
[appLanguage],
|
||||||
|
|||||||
Reference in New Issue
Block a user