Skip to content

Commit e97404a

Browse files
mod:tag标签固定颜色
2 parents 640ae0a + 23f0ad4 commit e97404a

11 files changed

+959
-1616
lines changed

‎.eslintrc

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": ["react-app"],
3+
"parserOptions": {
4+
"ecmaVersion": 7,
5+
"sourceType": "module"
6+
},
7+
"rules": {
8+
"quotes": ["error", "double"]
9+
}
10+
}

‎package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
"react-scripts": "3.4.1"
1616
},
1717
"scripts": {
18+
"lint": "eslint src",
1819
"start": "react-scripts start",
1920
"build": "react-scripts build",
2021
"test": "react-scripts test",
2122
"eject": "react-scripts eject",
2223
"crawl": "node scripts/curlleetcode.js && node scripts/generateleetcode.js"
2324
},
24-
"eslintConfig": {
25-
"extends": "react-app"
26-
},
2725
"browserslist": {
2826
"production": [
2927
">0.2%",

‎scripts/generateleetcode.js

+3-1
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,13 @@ const genertateLeetcodeToJson = () => {
5959

6060
preKnowledge.push({
6161
text: $1,
62+
link: null,
63+
color:'red'
6264
})
6365
})
6466

6567
markdown.replace(Utils.getSatelliteDataReg().keyPoints, (noUseMatch, $1) => {
66-
keyPoints = $1.replace(/\s/g, '').split('-').filter(s => (s && s !== '解析')).map(s => ({ text: s, link: null }))
68+
keyPoints = $1.replace(/\s/g, '').split('-').filter(s => (s && s !== '解析')).map(s => ({ text: s, link: null, color:'blue' }))
6769

6870
})
6971

‎src/App.css

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@
22
color: #000;
33
font-size: 15px;
44
padding: 10px;
5-
width: 400px;
5+
width: 500px;
66
}
77
.row {
88
margin: 0 0 10px 0;
99
}
10+
.link {
11+
display: block;
12+
}
1013

1114
.label {
1215
line-height: 20px;

‎src/App.js

+31-15
Original file line numberDiff line numberDiff line change
@@ -12,26 +12,30 @@ import "./App.css";
1212

1313
const { TabPane } = Tabs;
1414
const { Panel } = Collapse;
15-
const { problems, tags: tagMapper } = db;
16-
const dataSource = Object.values(problems);
1715

1816
const formatCodeToMarkDown = (code,lang) => `\`\`\`${lang}\n${code}\`\`\`\n`
1917

20-
function TagOrLink({ link, text }) {
18+
const { problems } = db;
19+
const dataSource = Object.values(problems);
20+
21+
function TagOrLink({ link, text, style, color }) {
2122
return link !== null ? (
2223
<a className="link" href={link} rel="noopener noreferrer" target="_blank">
2324
<Button type="link">{text}</Button>
2425
</a>
2526
) : (
26-
<Tag color="orange">{text}</Tag>
27+
<div style={style}>
28+
<Tag color={color}>{text}</Tag>
29+
</div>
2730
);
2831
}
2932

3033
const columns = [
3134
{
3235
title: "题目",
3336
dataIndex: "name",
34-
key: "name",
37+
width: "300",
38+
align: "center",
3539
render: (name, row) => (
3640
<a
3741
className="link"
@@ -48,13 +52,25 @@ const columns = [
4852
{
4953
title: "标签",
5054
dataIndex: "tags",
51-
key: "tags",
55+
align: "center",
5256
render: (tags) => (
53-
<>
57+
<div>
5458
{tags.map((tag) => {
55-
return <TagOrLink text={tagMapper[tag.id].text} link={tag.link} />;
59+
return (
60+
<TagOrLink
61+
style={{
62+
width: "100px",
63+
display: "inline-block",
64+
margin: "4px 0",
65+
}}
66+
key={tag.id}
67+
text={tag.text}
68+
link={tag.link}
69+
color={tag.color}
70+
/>
71+
);
5672
})}
57-
</>
73+
</div>
5874
),
5975
},
6076
];
@@ -80,13 +96,13 @@ function App() {
8096
{show ? (
8197
<Tabs defaultActiveKey="0">
8298
<TabPane tab="前置知识" key="0">
83-
{problems[problemId].pre.map(({ link, text }) => (
84-
<TagOrLink text={text} link={link} />
99+
{problems[problemId].pre.map(({ id, link, text, color }) => (
100+
<TagOrLink key={id} text={text} link={link} color={color} />
85101
))}
86102
</TabPane>
87103
<TabPane tab="关键点" key="1">
88-
{problems[problemId].keyPoints.map(({ link, text }) => (
89-
<TagOrLink text={text} link={link} />
104+
{problems[problemId].keyPoints.map(({ id, link, text, color }) => (
105+
<TagOrLink key={text} text={text} link={link} color={color} />
90106
))}
91107
</TabPane>
92108
<TabPane tab="题解" key="2">
@@ -103,8 +119,8 @@ function App() {
103119
<div className="code-block">
104120
<Collapse>
105121
{problems[problemId].code.map((c) => (
106-
<Panel header={
107-
<div className="row" style={{ marginTop: "10px" }}>
122+
<Panel>
123+
<div key={c.text} className="row" style={{ marginTop: "10px" }}>
108124
<span className="language language-js">{c.language}</span>
109125
<Button
110126
type="primary"

‎src/App.test.js

+13-7
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
1-
import React from 'react';
2-
import { render } from '@testing-library/react';
3-
import App from './App';
1+
// import React from "react";
2+
// import { render } from "@testing-library/react";
3+
// import App from "./App";
44

5-
test('renders learn react link', () => {
6-
const { getByText } = render(<App />);
7-
const linkElement = getByText(/learn react/i);
8-
expect(linkElement).toBeInTheDocument();
5+
test("#cold hello world", () => {
6+
expect(true).toBe(true);
7+
});
8+
9+
test("#hot hello world", () => {
10+
expect(false).toBe(false);
11+
});
12+
13+
test("#cold hello world", () => {
14+
expect(true).toBe(true);
915
});

‎src/db/db.js

+4
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,25 @@ const tags = {
1313
recursion: {
1414
id: "recursion",
1515
text: "递归",
16+
color: "#f50",
1617
link: null,
1718
},
1819
queue: {
1920
id: "queue",
2021
text: "队列",
22+
color: "#108ee9",
2123
link: null,
2224
},
2325

2426
stack: {
2527
id: "stack",
28+
color: "#87d068",
2629
text: "栈",
2730
link: null,
2831
},
2932
design: {
3033
id: "design",
34+
color: "#2db7f5",
3135
text: "设计题",
3236
link: null,
3337
},

0 commit comments

Comments
 (0)