Skip to content

Commit

Permalink
perf: perf antd config provider i18n
Browse files Browse the repository at this point in the history
  • Loading branch information
rookie-luochao committed May 3, 2024
1 parent b2d4df1 commit 06534af
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/components/antd-config/index.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ConfigProvider /* , theme */ } from "antd";
import enUS from "antd/locale/en_US";
import zhCN from "antd/locale/zh_CN";
import { useTranslation } from "react-i18next";
import { useConfigInfoStore } from "../../core/store";
Expand All @@ -25,7 +26,7 @@ export function AntdConfigProviderWrap({ children }: { children: React.ReactNode

return (
<ConfigProvider
locale={i18n?.resolvedLanguage === LangType.zh ? zhCN : undefined}
locale={i18n?.resolvedLanguage === LangType.zh ? zhCN : enUS}
theme={{
// algorithm: theme.darkAlgorithm,
components: {
Expand Down
23 changes: 1 addition & 22 deletions src/components/change-lang/index.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { useTheme } from "@emotion/react";
import { Dropdown } from "antd";
import { useTranslation } from "react-i18next";
import { useLocation, useNavigate } from "react-router-dom";
import { parseQueryString, toQueryString } from "react-router-toolkit";
import { ITheme } from "../../core/style/defaultStyleConfig";
import { LangType } from "../../i18n/config";

Expand All @@ -18,27 +16,10 @@ const LangIcon = ({ size = "16", fill = "#333", ...other }) => {
);
};

export function ChangeLangComp({ isMainHead }: { isMainHead?: boolean }) {
const { pathname, search } = useLocation();
const query = parseQueryString(search);
const navigate = useNavigate();
export function ChangeLangComp() {
const { t, i18n } = useTranslation();
const theme = useTheme() as ITheme;

function avoidRefetchOpenApi() {
if (isMainHead && search) {
navigate(
`${pathname}${toQueryString({
...(query || {}),
logon: "yes",
})}`,
{
replace: true,
},
);
}
}

return (
<Dropdown
menu={{
Expand All @@ -51,7 +32,6 @@ export function ChangeLangComp({ isMainHead }: { isMainHead?: boolean }) {
return;
}
i18n.changeLanguage(LangType.en);
avoidRefetchOpenApi();
},
},
{
Expand All @@ -62,7 +42,6 @@ export function ChangeLangComp({ isMainHead }: { isMainHead?: boolean }) {
return;
}
i18n.changeLanguage(LangType.zh);
avoidRefetchOpenApi();
},
},
],
Expand Down
2 changes: 1 addition & 1 deletion src/components/head/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ export function Head() {
</a>
</Dropdown>
<SwitchTheme />
<ChangeLangComp isMainHead />
<ChangeLangComp />
{import.meta.env.MODE !== "package" && <GoToPostman />}
<GithubStar />
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export interface ICollapsed {

export const Logo = ({ isCollapsed }: ICollapsed) => {
const navigate = useNavigate();
const isPackage = import.meta.env.MODE === "package";

return (
<a
Expand All @@ -33,10 +34,10 @@ export const Logo = ({ isCollapsed }: ICollapsed) => {
display: "flex",
alignItems: "center",
marginLeft: 24,
cursor: import.meta.env.MODE === "package" ? "default" : "pointer",
cursor: isPackage ? "default" : "pointer",
}}
onClick={() => {
if (import.meta.env.MODE !== "package") {
if (!isPackage) {
navigate(loginModuleName);
}
}}
Expand Down

0 comments on commit 06534af

Please sign in to comment.