1
- import React , { useState , Suspense , useEffect } from "react" ;
1
+ import React , { useState , Suspense } from "react" ;
2
2
import { Button , Table , Empty , Tabs , Image } from "antd" ;
3
3
4
4
import "highlight.js/styles/github.css" ;
@@ -23,6 +23,7 @@ import CodeTemplates from "./codeTemplates/codeTemplate";
23
23
import ComplexityRating from "./complexityRating/index" ;
24
24
import SolutionTemplate from "./solutionTemplate/index" ;
25
25
import { t , initLang , setLang , lang } from "./locales" ;
26
+
26
27
// import { data as a } from "./db/binary-tree";
27
28
28
29
const DataStrutureVis = isInExtension ( )
@@ -82,6 +83,7 @@ const columns = [
82
83
} ,
83
84
] ;
84
85
const initialTab = getUrlParameter ( "tab" ) || "code-template" ;
86
+ const isDev = process . env . NODE_ENV === "development" ;
85
87
function App ( ) {
86
88
// eslint-disable-next-line
87
89
chrome &&
@@ -91,6 +93,7 @@ function App() {
91
93
console . log ( "[leetcode 插件打印]:chrome.tabs.query" , tabs ) ;
92
94
const currentUrl = tabs [ 0 ] . url ;
93
95
initLang ( currentUrl ) ;
96
+ setLangReady ( true ) ;
94
97
const match = currentUrl . match ( / p r o b l e m s \/ ( .+ ?) \/ / ) ;
95
98
const problemId = match && match [ 1 ] ;
96
99
setProblemId ( problemId ) ;
@@ -106,20 +109,15 @@ function App() {
106
109
// setHasSolution(!!problems[problemId]);
107
110
// }, 1000);
108
111
109
- const [ langReady , setLangReady ] = useState ( false ) ;
112
+ // 开发环境不需要��赖 chrome 插件 query 函数
113
+ const [ langReady , setLangReady ] = useState ( isDev ) ;
110
114
const [ problemId , setProblemId ] = useState ( "" ) ;
111
115
112
116
const [ hasSolution , setHasSolution ] = useState ( false ) ;
113
117
const [ inSelected , setInSelected ] = useState ( false ) ; // 是否被精选题解(其实就是合集)收录
114
118
const [ page , setPage ] = useState ( "" ) ;
115
119
const [ tab , setTab ] = useState ( initialTab ) ;
116
120
117
- useEffect ( ( ) => {
118
- process . env . NODE_ENV === "development" && initLang ( ) ;
119
- setLangReady ( true ) ;
120
- } , [ ] ) ;
121
-
122
-
123
121
// const [inLeetCode, setInLeetCode] = useState(true);
124
122
125
123
// if (!inLeetCode) return window.open(LEETCODE_CN_URL + "/problemset/all/");
@@ -156,6 +154,14 @@ function App() {
156
154
< div > { /* <pre>{a}</pre> */ } </ div >
157
155
< canvas width = "1000" height = "1000" id = "canvas" > </ canvas >
158
156
</ 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 >
159
165
{ isInExtension ( ) && (
160
166
< >
161
167
< div className = "guide-wrapper" >
@@ -284,11 +290,6 @@ function App() {
284
290
< Image src = "https://p.ipic.vip/h9nm77.jpg" > </ Image >
285
291
</ div >
286
292
</ 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 >
292
293
</ Tabs >
293
294
) }
294
295
</ div >
0 commit comments