mirror of
https://github.com/ajnart/homarr.git
synced 2025-11-09 15:05:48 +01:00
🐛 Fix locale for calendar and clock (#1330)
This commit is contained in:
@@ -57,7 +57,7 @@ function App(
|
||||
) {
|
||||
const { Component, pageProps } = props;
|
||||
// TODO: make mapping from our locales to moment locales
|
||||
const language = getLanguageByCode(pageProps.locale);
|
||||
const language = getLanguageByCode(pageProps.session?.user?.language ?? 'en');
|
||||
require(`dayjs/locale/${language.locale}.js`);
|
||||
dayjs.locale(language.locale);
|
||||
|
||||
|
||||
@@ -3,7 +3,6 @@ import { Calendar } from '@mantine/dates';
|
||||
import { IconCalendarTime } from '@tabler/icons-react';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/router';
|
||||
import { getLanguageByCode } from '~/tools/language';
|
||||
import { RouterOutputs, api } from '~/utils/api';
|
||||
|
||||
@@ -64,7 +63,6 @@ interface CalendarTileProps {
|
||||
}
|
||||
|
||||
function CalendarTile({ widget }: CalendarTileProps) {
|
||||
const { locale } = useRouter();
|
||||
const { colorScheme, radius } = useMantineTheme();
|
||||
const { name: configName } = useConfigContext();
|
||||
const [month, setMonth] = useState(new Date());
|
||||
@@ -74,8 +72,7 @@ function CalendarTile({ widget }: CalendarTileProps) {
|
||||
enabled: !!sessionData?.user,
|
||||
});
|
||||
|
||||
const language = getLanguageByCode(locale ?? 'en');
|
||||
require(`dayjs/locale/${language.locale}.js`);
|
||||
const language = getLanguageByCode(userWithSettings?.settings.language ?? 'en');
|
||||
|
||||
const { data: medias } = api.calendar.medias.useQuery(
|
||||
{
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import { Stack, Text, createStyles } from '@mantine/core';
|
||||
import { useElementSize } from '@mantine/hooks';
|
||||
import { IconClock } from '@tabler/icons-react';
|
||||
import { useRouter } from 'next/router';
|
||||
import dayjs from 'dayjs';
|
||||
import timezones from 'dayjs/plugin/timezone';
|
||||
import utc from 'dayjs/plugin/utc';
|
||||
import { useSession } from 'next-auth/react';
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
import { getLanguageByCode } from '~/tools/language';
|
||||
import { api } from '~/utils/api';
|
||||
import dayjs from 'dayjs';
|
||||
import timezones from 'dayjs/plugin/timezone'
|
||||
import utc from 'dayjs/plugin/utc'
|
||||
|
||||
import { useSetSafeInterval } from '../../hooks/useSetSafeInterval';
|
||||
import { defineWidget } from '../helper';
|
||||
@@ -138,12 +138,16 @@ const useDateState = (location?: { latitude: number; longitude: number }) => {
|
||||
const { data: timezone } = api.timezone.at.useQuery(location!, {
|
||||
enabled: location !== undefined,
|
||||
});
|
||||
const { locale } = useRouter();
|
||||
const { data: sessionData } = useSession();
|
||||
const { data: userWithSettings } = api.user.withSettings.useQuery(undefined, {
|
||||
enabled: !!sessionData?.user,
|
||||
});
|
||||
const userLanguage = userWithSettings?.settings.language;
|
||||
const [date, setDate] = useState(getNewDate(timezone));
|
||||
const setSafeInterval = useSetSafeInterval();
|
||||
const timeoutRef = useRef<NodeJS.Timeout>(); // reference for initial timeout until first minute change
|
||||
useEffect(() => {
|
||||
const language = getLanguageByCode(locale ?? 'en');
|
||||
const language = getLanguageByCode(userLanguage ?? 'en');
|
||||
dayjs.locale(language.locale);
|
||||
setDate(getNewDate(timezone));
|
||||
timeoutRef.current = setTimeout(
|
||||
@@ -158,7 +162,7 @@ const useDateState = (location?: { latitude: number; longitude: number }) => {
|
||||
1000 * 60 - (1000 * dayjs().second() + dayjs().millisecond())
|
||||
);
|
||||
return () => timeoutRef.current && clearTimeout(timeoutRef.current);
|
||||
}, [timezone, locale]);
|
||||
}, [timezone, userLanguage]);
|
||||
|
||||
return date;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user