@@ -3,6 +3,7 @@ import { Tabs, Tag, Button, Table, Empty, message } from "antd";
3
3
4
4
import { copy } from "./utils" ;
5
5
import db from "./db/db" ;
6
+ import { LEETCODE_CN_URL , LEETCODE_URL } from "./constant/index" ;
6
7
7
8
import "antd/dist/antd.css" ;
8
9
import "./App.css" ;
@@ -11,13 +12,17 @@ const { TabPane } = Tabs;
11
12
const { problems } = db ;
12
13
const dataSource = Object . values ( problems ) ;
13
14
15
+ function inLeetCodeWebsite ( url ) {
16
+ return [ LEETCODE_CN_URL , LEETCODE_URL ] . some ( ( u ) => url . includes ( u ) ) ;
17
+ }
18
+
14
19
function TagOrLink ( { link, text, style, color } ) {
15
20
return link !== null ? (
16
- < a className = "link" href = { link } rel = "noopener noreferrer" target = "_blank" >
17
- < Button type = "link" > { text } </ Button >
18
- </ a >
21
+ < Button type = "link" href = { link } target = "_blank" >
22
+ { text }
23
+ </ Button >
19
24
) : (
20
- < div style = { style } >
25
+ < div style = { { display : "inline-block" , ... style } } >
21
26
< Tag color = { color } > { text } </ Tag >
22
27
</ div >
23
28
) ;
@@ -30,16 +35,13 @@ const columns = [
30
35
width : "300" ,
31
36
align : "center" ,
32
37
render : ( name , row ) => (
33
- < a
34
- className = "link"
35
- href = { `https://leetcode-cn.com/problems/${ name } /` }
36
- rel = "noopener noreferrer"
38
+ < Button
39
+ type = "link"
40
+ href = { `${ LEETCODE_CN_URL } /problems/${ name } /` }
37
41
target = "_blank"
38
42
>
39
- < Button type = "link" >
40
- { row . id } .{ name }
41
- </ Button >
42
- </ a >
43
+ { row . id } .{ name }
44
+ </ Button >
43
45
) ,
44
46
} ,
45
47
{
@@ -77,35 +79,49 @@ function App() {
77
79
const match = currentUrl . match ( / p r o b l e m s \/ ( .+ ?) \/ / ) ;
78
80
const problemId = match && match [ 1 ] ;
79
81
setProblemId ( problemId ) ;
80
- setShow ( ! ! problems [ problemId ] ) ;
82
+ setHasSolution ( ! ! problems [ problemId ] ) ;
83
+ setInLeetCode ( inLeetCodeWebsite ( currentUrl ) ) ;
81
84
} ) ;
82
85
83
86
const [ problemId , setProblemId ] = useState ( "" ) ;
84
- const [ show , setShow ] = useState ( false ) ;
87
+ const [ hasSolution , setHasSolution ] = useState ( false ) ;
88
+ const [ inLeetCode , setInLeetCode ] = useState ( false ) ;
89
+
90
+ if ( ! inLeetCode )
91
+ return (
92
+ < div className = "container" style = { { textAlign : "center" } } >
93
+ < div > 快打开力扣,开始刷题吧~</ div >
94
+ < Button type = "link" href = { LEETCODE_CN_URL } target = "_blank" >
95
+ 力扣中国
96
+ </ Button >
97
+ < Button type = "link" href = { LEETCODE_URL } target = "_blank" >
98
+ 力扣国际
99
+ </ Button >
100
+ </ div >
101
+ ) ;
85
102
86
103
return (
87
104
< div className = "container" >
88
- { show ? (
105
+ { hasSolution ? (
89
106
< Tabs defaultActiveKey = "0" >
90
107
< TabPane tab = "前置知识" key = "0" >
91
- { problems [ problemId ] . pre . map ( ( { id, link, text, tag } ) => (
92
- < TagOrLink key = { id } text = { text } link = { link } color = { tag . color } />
108
+ { problems [ problemId ] . pre . map ( ( { id, link, text, color } ) => (
109
+ < TagOrLink key = { id } text = { text } link = { link } color = { color } />
93
110
) ) }
94
111
</ TabPane >
95
112
< TabPane tab = "关键点" key = "1" >
96
- { problems [ problemId ] . keyPoints . map ( ( { id, link, text, tag } ) => (
97
- < TagOrLink key = { text } text = { text } link = { link } color = { tag . color } />
113
+ { problems [ problemId ] . keyPoints . map ( ( { id, link, text, color } ) => (
114
+ < TagOrLink key = { text } text = { text } link = { link } color = { color } />
98
115
) ) }
99
116
</ TabPane >
100
117
< TabPane tab = "题解" key = "2" >
101
- < a
102
- className = "link nav "
118
+ < Button
119
+ type = "link"
103
120
href = { problems [ problemId ] . solution }
104
- rel = "noopener noreferrer"
105
121
target = "_blank"
106
122
>
107
- < Button type = "link" > 前往题解</ Button >
108
- </ a >
123
+ 前往题解
124
+ </ Button >
109
125
</ TabPane >
110
126
< TabPane tab = "代码" key = "3" >
111
127
< div className = "code-block" >
0 commit comments