Fix default i18n load

This commit is contained in:
Paulo Gustavo Veiga 2022-02-09 16:48:33 -08:00
parent 67fb3bbc35
commit be727e3c4b
3 changed files with 17 additions and 17 deletions

View File

@ -37,7 +37,7 @@ declare global {
} }
export type EditorPropsType = { export type EditorPropsType = {
initCallback?: () => void; initCallback?: (locale: string) => void;
mapId?: number; mapId?: number;
isTryMode: boolean; isTryMode: boolean;
readOnlyMode: boolean; readOnlyMode: boolean;
@ -60,7 +60,7 @@ const loadLocaleData = (locale: string) => {
} }
} }
const initMindplot = () => { const initMindplot = (locale: string) => {
// Change page title ... // Change page title ...
document.title = `${global.mapTitle} | WiseMapping `; document.title = `${global.mapTitle} | WiseMapping `;
@ -95,7 +95,7 @@ const initMindplot = () => {
(global.userOptions?.zoom != undefined (global.userOptions?.zoom != undefined
? Number.parseFloat(global.userOptions.zoom as string) ? Number.parseFloat(global.userOptions.zoom as string)
: 0.8), : 0.8),
locale: global.locale, locale: locale,
}); });
// Build designer ... // Build designer ...
@ -119,11 +119,11 @@ const Editor = ({
onAction, onAction,
}: EditorPropsType): React.ReactElement => { }: EditorPropsType): React.ReactElement => {
React.useEffect(() => { React.useEffect(() => {
initCallback(); initCallback(locale);
}, []); }, []);
return ( return (
<IntlProvider locale={locale} defaultLocale="en" messages={loadLocaleData(locale)}> <IntlProvider locale={locale} messages={loadLocaleData(locale)}>
<Toolbar <Toolbar
isTryMode={isTryMode} isTryMode={isTryMode}
onAction={onAction} onAction={onAction}

View File

@ -14,6 +14,7 @@ const EditorPage = ({ mapId, ...props }: EditorPropsType): React.ReactElement =>
// Load user locale ... // Load user locale ...
const userLocale = AppI18n.getUserLocale(); const userLocale = AppI18n.getUserLocale();
console.log("Locale:" + userLocale.code);
return <> return <>
<Editor {...props} onAction={setActiveDialog} locale={userLocale.code} /> <Editor {...props} onAction={setActiveDialog} locale={userLocale.code} />

View File

@ -2,7 +2,7 @@ import React, { useEffect, CSSProperties } from 'react';
import { useStyles } from './styled'; import { useStyles } from './styled';
import { useSelector } from 'react-redux'; import { useSelector } from 'react-redux';
import { activeInstance, fetchAccount } from '../../../redux/clientSlice'; import { activeInstance } from '../../../redux/clientSlice';
import { useMutation, useQuery, useQueryClient } from 'react-query'; import { useMutation, useQuery, useQueryClient } from 'react-query';
import Client, { ErrorInfo, Label, MapInfo } from '../../../classes/client'; import Client, { ErrorInfo, Label, MapInfo } from '../../../classes/client';
import ActionChooser, { ActionType } from '../action-chooser'; import ActionChooser, { ActionType } from '../action-chooser';
@ -37,6 +37,7 @@ import { AddLabelButton } from './add-label-button';
import relativeTime from 'dayjs/plugin/relativeTime'; import relativeTime from 'dayjs/plugin/relativeTime';
import { LabelsCell } from './labels-cell'; import { LabelsCell } from './labels-cell';
import LocalizedFormat from 'dayjs/plugin/localizedFormat'; import LocalizedFormat from 'dayjs/plugin/localizedFormat';
import AppI18n from '../../../classes/app-i18n';
dayjs.extend(LocalizedFormat) dayjs.extend(LocalizedFormat)
dayjs.extend(relativeTime); dayjs.extend(relativeTime);
@ -58,9 +59,9 @@ function getComparator<Key extends keyof any>(
order: Order, order: Order,
orderBy: Key orderBy: Key
): ( ): (
a: { [key in Key]: number | string | boolean | Label[] | undefined }, a: { [key in Key]: number | string | boolean | Label[] | undefined },
b: { [key in Key]: number | string | Label[] | boolean } b: { [key in Key]: number | string | Label[] | boolean }
) => number { ) => number {
return order === 'desc' return order === 'desc'
? (a, b) => descendingComparator(a, b, orderBy) ? (a, b) => descendingComparator(a, b, orderBy)
: (a, b) => -descendingComparator(a, b, orderBy); : (a, b) => -descendingComparator(a, b, orderBy);
@ -251,10 +252,8 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
const queryClient = useQueryClient(); const queryClient = useQueryClient();
// Configure locale ... // Configure locale ...
const account = fetchAccount(); const userLocale = AppI18n.getUserLocale();
if (account) { dayjs.locale(userLocale.code);
dayjs.locale(account.locale.code);
}
useEffect(() => { useEffect(() => {
setSelected([]); setSelected([]);
@ -385,7 +384,7 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
}); });
}; };
const removeLabelMultation = useMutation<void, ErrorInfo, { mapId: number, labelId: number}, number>( const removeLabelMultation = useMutation<void, ErrorInfo, { mapId: number, labelId: number }, number>(
({ mapId, labelId }) => { ({ mapId, labelId }) => {
return client.deleteLabelFromMap(labelId, mapId); return client.deleteLabelFromMap(labelId, mapId);
}, },
@ -409,7 +408,7 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
if (!label.id) { if (!label.id) {
label.id = await client.createLabel(label.title, label.color); label.id = await client.createLabel(label.title, label.color);
} }
if (checked){ if (checked) {
const toAdd = selectedMaps.filter((m) => !m.labels.find((l) => l.id === label.id)); const toAdd = selectedMaps.filter((m) => !m.labels.find((l) => l.id === label.id));
await Promise.all(toAdd.map((m) => client.addLabelToMap(label.id, m.id))); await Promise.all(toAdd.map((m) => client.addLabelToMap(label.id, m.id)));
} else { } else {
@ -471,9 +470,9 @@ export const MapsList = (props: MapsListProps): React.ReactElement => {
</Tooltip> </Tooltip>
)} )}
{selected.length > 0 && <AddLabelButton {selected.length > 0 && <AddLabelButton
onChange={handleChangesInLabels} onChange={handleChangesInLabels}
maps={mapsInfo.filter(m => isSelected(m.id))} maps={mapsInfo.filter(m => isSelected(m.id))}
/>} />}
</div> </div>