Skip to content

Commit fac33ee

Browse files
committed
修改Pull Request提交流程:使用指导弹窗替代自动跳转
1 parent a08f45a commit fac33ee

File tree

3 files changed

+51
-42
lines changed

3 files changed

+51
-42
lines changed

src/components/ChallengeContributePage/components/YamlPreviewSection.tsx

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as React from 'react';
2-
import { Button, Modal, Space, message } from 'antd';
3-
import { CopyOutlined, GithubOutlined } from '@ant-design/icons';
2+
import { Button, Modal, Space, message, Typography } from 'antd';
3+
import { CopyOutlined, GithubOutlined, QuestionCircleOutlined } from '@ant-design/icons';
44
import { Light as SyntaxHighlighter } from 'react-syntax-highlighter';
55
import yaml from 'react-syntax-highlighter/dist/esm/languages/hljs/yaml';
66
import { vs } from 'react-syntax-highlighter/dist/esm/styles/hljs';
@@ -13,7 +13,7 @@ const GITHUB_REPO = 'JSREP/crawler-leetcode';
1313
const GITHUB_BASE_URL = `https://github.com/${GITHUB_REPO}`;
1414

1515
// YAML长度限制(超过此长度需要手动提交)
16-
const YAML_LENGTH_LIMIT = 1000;
16+
const YAML_LENGTH_LIMIT = 10000;
1717

1818
// 自定义高亮主题
1919
const highlightTheme = {
@@ -40,6 +40,7 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
4040
}) => {
4141
const [isModalVisible, setIsModalVisible] = React.useState<boolean>(false);
4242
const [isLengthWarningVisible, setIsLengthWarningVisible] = React.useState<boolean>(false);
43+
const [isPrGuideVisible, setIsPrGuideVisible] = React.useState<boolean>(false);
4344
const [currentAction, setCurrentAction] = React.useState<'PR' | 'Issue' | null>(null);
4445
const [pendingAction, setPendingAction] = React.useState<'PR' | 'Issue' | null>(null);
4546

@@ -153,22 +154,10 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
153154
// 使用navigator.clipboard API复制YAML到剪贴板
154155
navigator.clipboard.writeText(yamlOutput)
155156
.then(() => {
156-
message.success('YAML已复制到剪贴板,请在GitHub中粘贴');
157-
158-
// 准备PR标题和基本说明
159-
const title = encodeURIComponent(`新增题目: ${challengeName}`);
160-
const body = encodeURIComponent(
161-
`## 新增题目\n\n` +
162-
`提交一个新的挑战题目。\n\n` +
163-
`### YAML代码\n\n` +
164-
`\`\`\`yaml\n${yamlOutput}\n\`\`\``
165-
);
157+
message.success('YAML已复制到剪贴板');
166158

167-
// 构建PR创建URL
168-
const prUrl = `${GITHUB_BASE_URL}/compare/main...?quick_pull=1&title=${title}&body=${body}`;
169-
170-
// 在新标签页中打开
171-
window.open(prUrl, '_blank');
159+
// 显示PR引导弹窗
160+
setIsPrGuideVisible(true);
172161
})
173162
.catch((error) => {
174163
console.error('复制YAML失败:', error);
@@ -218,6 +207,11 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
218207
checkYamlLengthAndProceed('Issue');
219208
};
220209

210+
// 关闭PR引导弹窗
211+
const handlePrGuideCancel = () => {
212+
setIsPrGuideVisible(false);
213+
};
214+
221215
return (
222216
<>
223217
{/* 显示操作按钮 */}
@@ -308,6 +302,38 @@ const YamlPreviewSection: React.FC<YamlPreviewSectionProps> = ({
308302
</ol>
309303
</div>
310304
</Modal>
305+
306+
{/* PR引导对话框 */}
307+
<Modal
308+
title="如何提交Pull Request"
309+
open={isPrGuideVisible}
310+
onCancel={handlePrGuideCancel}
311+
footer={[
312+
<Button key="close" onClick={handlePrGuideCancel}>
313+
关闭
314+
</Button>,
315+
]}
316+
>
317+
<div style={{ padding: '16px 0' }}>
318+
<Typography.Title level={5}>提交Pull Request的步骤</Typography.Title>
319+
<ol style={{ paddingLeft: '20px' }}>
320+
<li>访问项目仓库:<Typography.Link href={GITHUB_BASE_URL} target="_blank">{GITHUB_BASE_URL}</Typography.Link></li>
321+
<li>点击仓库页面右上角的"Fork"按钮创建自己的分支</li>
322+
<li>在Fork后的仓库中,创建一个新的分支</li>
323+
<li>在新分支中,导航到challenges文件夹</li>
324+
<li>点击"Add file" &gt; "Create new file"</li>
325+
<li>为文件命名,格式为:challenges/[题目ID].yaml</li>
326+
<li>将已复制的YAML内容粘贴到文件编辑器中</li>
327+
<li>点击"Commit new file"提交更改</li>
328+
<li>回到仓库主页,点击"Pull requests" &gt; "New pull request"</li>
329+
<li>确认更改并点击"Create pull request"</li>
330+
<li>填写PR标题和描述,然后点击"Create pull request"完成提交</li>
331+
</ol>
332+
<Typography.Paragraph>
333+
<QuestionCircleOutlined /> 提示:YAML内容已自动复制到剪贴板,您可以直接粘贴。
334+
</Typography.Paragraph>
335+
</div>
336+
</Modal>
311337
</>
312338
);
313339
};

src/locales/en.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ export default {
33
home: 'Home',
44
challenges: 'Challenges',
55
about: 'About',
6+
user: 'User',
7+
system: 'System',
68
contribute: 'Contribute'
79
},
810
home: {
@@ -198,17 +200,5 @@ export default {
198200
filterByTag: 'Click to filter challenges by this tag',
199201
filterByDifficulty: 'Click to filter challenges by this difficulty level',
200202
filterByPlatform: 'Click to filter challenges by this platform'
201-
},
202-
contribute: {
203-
title: 'Contribute Challenge',
204-
inDevelopment: {
205-
title: 'Feature in Development',
206-
description: 'The challenge contribution feature is under development. Stay tuned!'
207-
},
208-
instructions: {
209-
intro: 'You can contribute challenges through the following methods:',
210-
method1: 'Submit a Pull Request on GitHub to add a challenge YAML file',
211-
method2: 'Submit a challenge suggestion through GitHub Issues'
212-
}
213203
}
214204
}

src/locales/zh.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ const zhTranslations = {
33
home: '首页',
44
challenges: '挑战列表',
55
about: '关于',
6+
user: '用户',
7+
system: '系统',
68
contribute: '贡献题目'
79
},
810
home: {
@@ -199,18 +201,9 @@ const zhTranslations = {
199201
filterByDifficulty: '点击可按此难度筛选题目',
200202
filterByPlatform: '点击可按此平台筛选题目'
201203
},
202-
contribute: {
203-
title: '题目贡献',
204-
inDevelopment: {
205-
title: '功能开发中',
206-
description: '题目贡献功能正在开发中,敬请期待!'
207-
},
208-
instructions: {
209-
intro: '您可以通过以下方式贡献题目:',
210-
method1: '在GitHub上提交Pull Request添加题目YAML文件',
211-
method2: '通过GitHub Issues提交题目建议'
212-
}
213-
}
204+
user: '用户',
205+
system: '系统',
206+
contribute: '贡献题目'
214207
};
215208

216209
export default zhTranslations;

0 commit comments

Comments
 (0)