Skip to content

Commit aa94726

Browse files
committed
feat: 准备部署
1 parent 405031b commit aa94726

File tree

8 files changed

+144
-16
lines changed

8 files changed

+144
-16
lines changed

.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
VITE_BASE_URL=/ai-coding-prompt-builder/

.github/workflows/deploy.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: Deploy to GitHub Pages
2+
3+
on:
4+
push:
5+
branches:
6+
- main # 触发分支
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout
12+
uses: actions/checkout@v3
13+
14+
- name: Set up Node.js
15+
uses: actions/setup-node@v3
16+
with:
17+
node-version: 20
18+
19+
- name: Install dependencies
20+
run: npm ci
21+
22+
- name: Build
23+
run: npm run build
24+
25+
- name: Deploy to GitHub Pages
26+
uses: peaceiris/actions-gh-pages@v3
27+
with:
28+
github_token: ${{ secrets.GITHUB_TOKEN }}
29+
publish_dir: ./dist
30+
publish_branch: gh-pages

src/pages/About.tsx

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,63 @@
1-
import React from "react";
1+
import React, { useState } from "react";
2+
import Button from '@mui/material/Button';
3+
import Dialog from '@mui/material/Dialog';
4+
import DialogTitle from '@mui/material/DialogTitle';
5+
import DialogContent from '@mui/material/DialogContent';
6+
import DialogActions from '@mui/material/DialogActions';
7+
import CloseIcon from '@mui/icons-material/Close';
28

39
export default function About() {
10+
const [openWeChat, setOpenWeChat] = useState(false);
11+
412
return (
513
<div className="page-container">
614
<h1>About Page</h1>
715
<p>This is the about page description</p>
816
<p>Built with React {React.version}</p>
17+
18+
<div style={{ marginTop: '20px', display: 'flex', gap: '10px' }}>
19+
<Button
20+
variant="contained"
21+
color="primary"
22+
href="https://github.com/your-repo"
23+
target="_blank"
24+
>
25+
GitHub Repository
26+
</Button>
27+
<Button
28+
variant="contained"
29+
color="secondary"
30+
onClick={() => setOpenWeChat(true)}
31+
>
32+
Join WeChat Group
33+
</Button>
34+
</div>
35+
36+
<Dialog open={openWeChat} onClose={() => setOpenWeChat(false)}>
37+
<DialogTitle>
38+
Scan QR Code
39+
<CloseIcon
40+
style={{
41+
position: 'absolute',
42+
right: '8px',
43+
top: '8px',
44+
cursor: 'pointer'
45+
}}
46+
onClick={() => setOpenWeChat(false)}
47+
/>
48+
</DialogTitle>
49+
<DialogContent>
50+
<img
51+
src="/wechat-qr.png"
52+
alt="WeChat QR Code"
53+
style={{ width: '256px', height: '256px' }}
54+
/>
55+
<p>Scan the QR code to join the technical exchange group.</p>
56+
</DialogContent>
57+
<DialogActions>
58+
<Button onClick={() => setOpenWeChat(false)}>Close</Button>
59+
</DialogActions>
60+
</Dialog>
961
</div>
1062
);
1163
}

src/pages/CopyButton.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Alert from '@mui/material/Alert';
66

77
interface CopyButtonProps {
88
content: string;
9-
files: Array<{ name: string; content: string }>;
9+
files: Array<{ path: string; content: string }>;
1010
}
1111

1212
const CopyButton: React.FC<CopyButtonProps> = ({ content, files }) => {
@@ -18,7 +18,7 @@ const CopyButton: React.FC<CopyButtonProps> = ({ content, files }) => {
1818

1919
const handleCopy = async () => {
2020
const filesContent = files.map(file =>
21-
`\`\`\`${file.name}\n${file.content}\n\`\`\``
21+
`\`\`\`${file.path}\n${file.content}\n\`\`\``
2222
).join('\n\n');
2323

2424
const fullContent = `${content}\n\n# 相关参考文件:\n${filesContent}`;

src/pages/FileUpload.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const FileUpload: React.FC<FileUploadProps> = ({onFilesUploaded}) => {
1515
reader.onload = (e) => {
1616
resolve({
1717
name: file.name,
18+
path: (file as any).path || file.name, // 获取完整路径
1819
size: file.size,
1920
extension: file.name.split('.').pop() || '',
2021
content: e.target?.result as string
@@ -54,7 +55,7 @@ const FileUpload: React.FC<FileUploadProps> = ({onFilesUploaded}) => {
5455
onChange={handleFileSelect}
5556
className="file-input"
5657
/>
57-
<p>拖放文件到这里或点击选择文件</p>
58+
<p>拖放AI参考代码文件到这里或点击此处选择文件(参考上下文越完整,AI推理结果越好)</p>
5859
</div>
5960
);
6061
};

src/pages/Home.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ export default function Home() {
3333
<div className="home-container">
3434
{/* 标题区域 */}
3535
<header className="home-header">
36-
<h1>任务</h1>
37-
<p>支持文件拖拽上传与内容合并复制</p>
36+
<h1>AI辅助写代码提示词构造器</h1>
37+
<p>支持文件拖拽上传</p>
3838
</header>
3939

4040
{/* 功能区域 */}
@@ -44,25 +44,39 @@ export default function Home() {
4444
<TextField
4545
fullWidth
4646
multiline
47-
rows={4}
47+
minRows={4}
48+
maxRows={10}
4849
value={roleContent}
4950
onChange={(e) => setRoleContent(e.target.value)}
5051
label="角色信息(Markdown格式)"
5152
variant="outlined"
52-
sx={{marginBottom: 2}}
53+
sx={{
54+
marginBottom: 2,
55+
'& .MuiInputBase-root': {
56+
overflow: 'hidden',
57+
transition: 'height 0.2s ease-out'
58+
}
59+
}}
5360
/>
5461
</div>
5562

5663
<div className="rule-input-section">
5764
<TextField
5865
fullWidth
5966
multiline
60-
rows={4}
67+
minRows={4}
68+
maxRows={10}
6169
value={ruleContent}
6270
onChange={(e) => setRuleContent(e.target.value)}
6371
label="规则内容(Markdown格式)"
6472
variant="outlined"
65-
sx={{marginBottom: 2}}
73+
sx={{
74+
marginBottom: 2,
75+
'& .MuiInputBase-root': {
76+
overflow: 'hidden',
77+
transition: 'height 0.2s ease-out'
78+
}
79+
}}
6680
/>
6781
</div>
6882

src/pages/MarkdownEditor.tsx

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// MarkdownEditor.tsx
2-
import React, { useEffect, useState } from 'react';
2+
import React, { useEffect, useState, useRef } from 'react';
33
import FileUpload from './FileUpload';
44
import CopyButton from './CopyButton';
55
import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
@@ -11,6 +11,7 @@ import './styles.css';
1111

1212
interface FileInfo {
1313
name: string;
14+
path: string;
1415
size: number;
1516
extension: string;
1617
content: string;
@@ -29,6 +30,7 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
2930
const [files, setFiles] = useState<FileInfo[]>([]);
3031
const [previewFile, setPreviewFile] = useState<FileInfo | null>(null);
3132
const [isDialogOpen, setIsDialogOpen] = useState(false);
33+
const previewContentRef = useRef<HTMLDivElement>(null);
3234

3335
useEffect(() => {
3436
const timer = setTimeout(() => {
@@ -37,6 +39,16 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
3739
return () => clearTimeout(timer);
3840
}, [markdownContent]);
3941

42+
useEffect(() => {
43+
if (previewFile && previewContentRef.current) {
44+
const savedScrollTop = parseInt(
45+
localStorage.getItem(`scrollPosition:${previewFile.name}`) || '0',
46+
10
47+
);
48+
previewContentRef.current.scrollTop = savedScrollTop;
49+
}
50+
}, [previewFile]);
51+
4052
const handleFilesUploaded = (newFiles: FileInfo[]) => {
4153
setFiles(prev => [...prev, ...newFiles]);
4254
};
@@ -72,7 +84,7 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
7284
</SyntaxHighlighter>
7385
);
7486

75-
const combinedContent = `# 角色\n${roleContent}\n\n# 任务\n${markdownContent}\n\n# 规则\n${ruleContent}`;
87+
const combinedContent = `# 角色\n${roleContent}\n\n# 规则\n${ruleContent}\n\n# 任务\n${markdownContent}`;
7688

7789
return (
7890
<div className="editor-container">
@@ -93,7 +105,7 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
93105
}}
94106
>
95107
<Typography variant="subtitle1">
96-
{file.name}
108+
{file.path}
97109
</Typography>
98110
<Typography variant="caption">
99111
{formatFileSize(file.size)} - {file.extension}
@@ -121,15 +133,25 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
121133
fullWidth
122134
>
123135
<DialogTitle>
124-
{previewFile?.name}
136+
{previewFile?.path}
125137
<IconButton
126138
onClick={() => setIsDialogOpen(false)}
127139
sx={{ position: 'absolute', right: 8, top: 8 }}
128140
>
129141
<CloseIcon />
130142
</IconButton>
131143
</DialogTitle>
132-
<DialogContent dividers>
144+
<DialogContent
145+
dividers
146+
ref={previewContentRef}
147+
onScroll={(e) => {
148+
if (previewFile) {
149+
const scrollTop = e.currentTarget.scrollTop;
150+
localStorage.setItem(`scrollPosition:${previewFile.name}`, scrollTop.toString());
151+
}
152+
}}
153+
sx={{ overflow: 'auto' }}
154+
>
133155
{previewFile && (
134156
<CodePreview
135157
content={previewFile.content}
@@ -143,12 +165,19 @@ const MarkdownEditor: React.FC<MarkdownEditorProps> = ({ ruleContent, roleConten
143165
<TextField
144166
fullWidth
145167
multiline
146-
rows={10}
168+
minRows={10}
169+
maxRows={20}
147170
value={markdownContent}
148171
onChange={(e) => setMarkdownContent(e.target.value)}
149172
label="执行任务(Markdown格式)"
150173
variant="outlined"
151174
className="markdown-editor"
175+
sx={{
176+
'& .MuiInputBase-root': {
177+
overflow: 'hidden',
178+
transition: 'height 0.2s ease-out'
179+
}
180+
}}
152181
/>
153182
</div>
154183

vite.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import react from '@vitejs/plugin-react'
33

44
// https://vite.dev/config/
55
export default defineConfig({
6+
base: process.env.NODE_ENV === 'production' ? '/ai-coding-prompt-builder/' : '/',
67
plugins: [react()],
78
})

0 commit comments

Comments
 (0)