From be727e3c4b30beb9071cb5c1e0d0fedfb791038b Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Wed, 9 Feb 2022 16:48:33 -0800 Subject: [PATCH] Fix default i18n load --- packages/editor/src/index.tsx | 10 ++++---- .../src/components/editor-page/index.tsx | 1 + .../components/maps-page/maps-list/index.tsx | 23 +++++++++---------- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/packages/editor/src/index.tsx b/packages/editor/src/index.tsx index f5ce16fb..7d4edc74 100644 --- a/packages/editor/src/index.tsx +++ b/packages/editor/src/index.tsx @@ -37,7 +37,7 @@ declare global { } export type EditorPropsType = { - initCallback?: () => void; + initCallback?: (locale: string) => void; mapId?: number; isTryMode: boolean; readOnlyMode: boolean; @@ -60,7 +60,7 @@ const loadLocaleData = (locale: string) => { } } -const initMindplot = () => { +const initMindplot = (locale: string) => { // Change page title ... document.title = `${global.mapTitle} | WiseMapping `; @@ -95,7 +95,7 @@ const initMindplot = () => { (global.userOptions?.zoom != undefined ? Number.parseFloat(global.userOptions.zoom as string) : 0.8), - locale: global.locale, + locale: locale, }); // Build designer ... @@ -119,11 +119,11 @@ const Editor = ({ onAction, }: EditorPropsType): React.ReactElement => { React.useEffect(() => { - initCallback(); + initCallback(locale); }, []); return ( - + // Load user locale ... const userLocale = AppI18n.getUserLocale(); + console.log("Locale:" + userLocale.code); return <> diff --git a/packages/webapp/src/components/maps-page/maps-list/index.tsx b/packages/webapp/src/components/maps-page/maps-list/index.tsx index 2caf2103..32dfb83d 100644 --- a/packages/webapp/src/components/maps-page/maps-list/index.tsx +++ b/packages/webapp/src/components/maps-page/maps-list/index.tsx @@ -2,7 +2,7 @@ import React, { useEffect, CSSProperties } from 'react'; import { useStyles } from './styled'; import { useSelector } from 'react-redux'; -import { activeInstance, fetchAccount } from '../../../redux/clientSlice'; +import { activeInstance } from '../../../redux/clientSlice'; import { useMutation, useQuery, useQueryClient } from 'react-query'; import Client, { ErrorInfo, Label, MapInfo } from '../../../classes/client'; import ActionChooser, { ActionType } from '../action-chooser'; @@ -37,6 +37,7 @@ import { AddLabelButton } from './add-label-button'; import relativeTime from 'dayjs/plugin/relativeTime'; import { LabelsCell } from './labels-cell'; import LocalizedFormat from 'dayjs/plugin/localizedFormat'; +import AppI18n from '../../../classes/app-i18n'; dayjs.extend(LocalizedFormat) dayjs.extend(relativeTime); @@ -58,9 +59,9 @@ function getComparator( order: Order, orderBy: Key ): ( - a: { [key in Key]: number | string | boolean | Label[] | undefined }, - b: { [key in Key]: number | string | Label[] | boolean } -) => number { + a: { [key in Key]: number | string | boolean | Label[] | undefined }, + b: { [key in Key]: number | string | Label[] | boolean } + ) => number { return order === 'desc' ? (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(); // Configure locale ... - const account = fetchAccount(); - if (account) { - dayjs.locale(account.locale.code); - } + const userLocale = AppI18n.getUserLocale(); + dayjs.locale(userLocale.code); useEffect(() => { setSelected([]); @@ -385,7 +384,7 @@ export const MapsList = (props: MapsListProps): React.ReactElement => { }); }; - const removeLabelMultation = useMutation( + const removeLabelMultation = useMutation( ({ mapId, labelId }) => { return client.deleteLabelFromMap(labelId, mapId); }, @@ -409,7 +408,7 @@ export const MapsList = (props: MapsListProps): React.ReactElement => { if (!label.id) { 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)); await Promise.all(toAdd.map((m) => client.addLabelToMap(label.id, m.id))); } else { @@ -471,9 +470,9 @@ export const MapsList = (props: MapsListProps): React.ReactElement => { )} - {selected.length > 0 && 0 && isSelected(m.id))} + maps={mapsInfo.filter(m => isSelected(m.id))} />}