Skip to content

Commit 60130b8

Browse files
committed
feat: Adjust lang button position
1 parent 7926040 commit 60130b8

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

‎src/App.css

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
height: 30px;
3636
}
3737
.guide-wrapper {
38-
display: flex;
38+
display: inline-flex;
3939
}
4040
.ant-layout-sider {
4141
background: none;

‎src/App.js

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { useState, Suspense, useEffect } from "react";
1+
import React, { useState, Suspense } from "react";
22
import { Button, Table, Empty, Tabs, Image } from "antd";
33

44
import "highlight.js/styles/github.css";
@@ -23,6 +23,7 @@ import CodeTemplates from "./codeTemplates/codeTemplate";
2323
import ComplexityRating from "./complexityRating/index";
2424
import SolutionTemplate from "./solutionTemplate/index";
2525
import { t, initLang, setLang, lang } from "./locales";
26+
2627
// import { data as a } from "./db/binary-tree";
2728

2829
const DataStrutureVis = isInExtension()
@@ -82,6 +83,7 @@ const columns = [
8283
},
8384
];
8485
const initialTab = getUrlParameter("tab") || "code-template";
86+
const isDev = process.env.NODE_ENV === "development";
8587
function App() {
8688
// eslint-disable-next-line
8789
chrome &&
@@ -91,6 +93,7 @@ function App() {
9193
console.log("[leetcode 插件打印]:chrome.tabs.query", tabs);
9294
const currentUrl = tabs[0].url;
9395
initLang(currentUrl);
96+
setLangReady(true);
9497
const match = currentUrl.match(/problems\/(.+?)\//);
9598
const problemId = match && match[1];
9699
setProblemId(problemId);
@@ -106,20 +109,15 @@ function App() {
106109
// setHasSolution(!!problems[problemId]);
107110
// }, 1000);
108111

109-
const [langReady, setLangReady] = useState(false);
112+
// 开发环境不需要��赖 chrome 插件 query 函数
113+
const [langReady, setLangReady] = useState(isDev);
110114
const [problemId, setProblemId] = useState("");
111115

112116
const [hasSolution, setHasSolution] = useState(false);
113117
const [inSelected, setInSelected] = useState(false); // 是否被精选题解(其实就是合集)收录
114118
const [page, setPage] = useState("");
115119
const [tab, setTab] = useState(initialTab);
116120

117-
useEffect(() => {
118-
process.env.NODE_ENV === "development" && initLang();
119-
setLangReady(true);
120-
}, []);
121-
122-
123121
// const [inLeetCode, setInLeetCode] = useState(true);
124122

125123
// if (!inLeetCode) return window.open(LEETCODE_CN_URL + "/problemset/all/");
@@ -156,6 +154,14 @@ function App() {
156154
<div>{/* <pre>{a}</pre> */}</div>
157155
<canvas width="1000" height="1000" id="canvas"></canvas>
158156
</div>
157+
<Button
158+
type="primary"
159+
onClick={changeLang}
160+
size="small"
161+
style={{ marginBottom: "8px", padding: "0 4px" }}
162+
>
163+
{t("app.changeLang")}
164+
</Button>
159165
{isInExtension() && (
160166
<>
161167
<div className="guide-wrapper">
@@ -284,11 +290,6 @@ function App() {
284290
<Image src="https://p.ipic.vip/h9nm77.jpg"></Image>
285291
</div>
286292
</TabPane>
287-
<TabPane key="changeLang" tab={t("app.setLang")} onClick={changeLang}>
288-
<Button type="primary" onClick={changeLang}>
289-
{t("app.changeLang")}
290-
</Button>
291-
</TabPane>
292293
</Tabs>
293294
)}
294295
</div>

‎src/locales/en.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export const en = {
22
app: {
33
setLang: "Set Language",
4-
changeLang: "Switch to Chinese",
4+
changeLang: "中文",
55
copy: "copy",
66
copySuccess: "Copy successfully~",
77
article: "article",

‎src/locales/zh.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ export const cn = {
22

33
app: {
44
setLang: "设置语言",
5-
changeLang: "切换为英文",
5+
changeLang: "English",
66
copy: "复制",
77
copySuccess: "复制成功~",
88
article: "文章",

0 commit comments

Comments
 (0)