Skip to content

Commit 3b442fa

Browse files
author
CodeJudge
committed
feat: 新手引导教程
1 parent bca79c8 commit 3b442fa

3 files changed

Lines changed: 94 additions & 3 deletions

File tree

frontend/src/App.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import Navbar from './components/Navbar';
44
import Footer from './components/Footer';
55
import ErrorBoundary from './components/ErrorBoundary';
66
import KeyboardShortcuts from './components/KeyboardShortcuts';
7+
import TutorialOverlay from './components/TutorialOverlay';
78

89
const Home = lazy(() => import('./pages/Home'));
910
const Login = lazy(() => import('./pages/Login'));
@@ -50,7 +51,8 @@ export default function App() {
5051
</ErrorBoundary>
5152
<Footer />
5253
</main>
53-
<KeyboardShortcuts />
54-
</div>
54+
<KeyboardShortcuts />
55+
<TutorialOverlay />
56+
</div>
5557
);
5658
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { useState, useEffect } from 'react';
2+
import { X, Code2, ListChecks, PenLine, ArrowRight } from 'lucide-react';
3+
4+
const STEPS = [
5+
{ icon: <Code2 className="w-6 h-6 text-blue-400" />, title: '刷编程题', desc: '在线编写 JavaScript 或 Python 代码,实时判题反馈' },
6+
{ icon: <ListChecks className="w-6 h-6 text-violet-400" />, title: '做选择题', desc: '从四个选项中选择正确答案,即时评分' },
7+
{ icon: <PenLine className="w-6 h-6 text-cyan-400" />, title: '填填空题', desc: '输入答案,支持多个可接受答案匹配' },
8+
];
9+
10+
export default function TutorialOverlay() {
11+
const [visible, setVisible] = useState(false);
12+
const [step, setStep] = useState(0);
13+
14+
useEffect(() => {
15+
const seen = localStorage.getItem('cj_tutorial_seen');
16+
if (!seen) {
17+
setTimeout(() => setVisible(true), 500);
18+
}
19+
}, []);
20+
21+
const dismiss = () => {
22+
localStorage.setItem('cj_tutorial_seen', 'true');
23+
setVisible(false);
24+
};
25+
26+
if (!visible) return null;
27+
28+
return (
29+
<div className="fixed inset-0 z-[200] flex items-center justify-center bg-black/70 backdrop-blur-sm" onClick={dismiss}>
30+
<div className="bg-dark-800 border border-dark-600 rounded-2xl p-8 max-w-md w-full mx-4 shadow-2xl" onClick={e => e.stopPropagation()}>
31+
<div className="flex justify-between items-center mb-4">
32+
<h2 className="text-xl font-bold text-white">欢迎来到 CodeJudge</h2>
33+
<button onClick={dismiss} className="text-dark-400 hover:text-white p-1"><X className="w-5 h-5" /></button>
34+
</div>
35+
36+
{step === 0 && (
37+
<div className="text-center py-4">
38+
<p className="text-dark-300 mb-6">一个平台搞定三种题型</p>
39+
<div className="grid gap-4">
40+
{STEPS.map(s => (
41+
<div key={s.title} className="flex items-start gap-3 p-3 rounded-lg bg-dark-700/50">
42+
{s.icon}
43+
<div className="text-left">
44+
<p className="text-white font-medium text-sm">{s.title}</p>
45+
<p className="text-dark-400 text-xs">{s.desc}</p>
46+
</div>
47+
</div>
48+
))}
49+
</div>
50+
</div>
51+
)}
52+
53+
{step === 1 && (
54+
<div className="py-4">
55+
<p className="text-dark-300 mb-4 text-center">预置账户</p>
56+
<div className="space-y-3">
57+
<div className="p-3 rounded-lg bg-dark-700/50">
58+
<p className="text-white text-sm mb-1">管理员</p>
59+
<p className="text-dark-400 text-xs font-mono">admin@oj.com / admin123</p>
60+
</div>
61+
<div className="p-3 rounded-lg bg-dark-700/50">
62+
<p className="text-white text-sm mb-1">学生</p>
63+
<p className="text-dark-400 text-xs font-mono">test@oj.com / test123</p>
64+
</div>
65+
</div>
66+
</div>
67+
)}
68+
69+
<div className="flex items-center justify-between mt-6 pt-4 border-t border-dark-700">
70+
<div className="flex gap-1.5">
71+
{[0, 1].map(i => (
72+
<div key={i} className={`w-2 h-2 rounded-full ${step === i ? 'bg-primary-500' : 'bg-dark-600'}`} />
73+
))}
74+
</div>
75+
<div className="flex gap-2">
76+
<button onClick={dismiss} className="btn-ghost text-xs px-3 py-1.5">跳过</button>
77+
{step < 1 ? (
78+
<button onClick={() => setStep(s => s + 1)} className="btn-primary text-xs inline-flex items-center gap-1">
79+
下一步 <ArrowRight className="w-3.5 h-3.5" />
80+
</button>
81+
) : (
82+
<button onClick={dismiss} className="btn-primary text-xs px-4">开始使用</button>
83+
)}
84+
</div>
85+
</div>
86+
</div>
87+
</div>
88+
);
89+
}

frontend/tsconfig.tsbuildinfo

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"root":["./src/app.tsx","./src/main.tsx","./src/components/choicequestion.tsx","./src/components/codeeditor.tsx","./src/components/errorboundary.tsx","./src/components/fillblankquestion.tsx","./src/components/footer.tsx","./src/components/gamificationsection.tsx","./src/components/keyboardshortcuts.tsx","./src/components/markdownrenderer.tsx","./src/components/navbar.tsx","./src/components/problemcard.tsx","./src/components/submissionstatus.tsx","./src/context/authcontext.tsx","./src/context/bookmarkcontext.tsx","./src/hooks/usedocumenttitle.ts","./src/pages/admin.tsx","./src/pages/adminproblemform.tsx","./src/pages/apidocs.tsx","./src/pages/home.tsx","./src/pages/leaderboard.tsx","./src/pages/login.tsx","./src/pages/notfound.tsx","./src/pages/problemdetail.tsx","./src/pages/problems.tsx","./src/pages/profile.tsx","./src/pages/register.tsx","./src/pages/submissions.tsx","./src/pages/systemhealth.tsx","./src/services/api.ts","./src/types/index.ts"],"version":"5.9.3"}
1+
{"root":["./src/app.tsx","./src/main.tsx","./src/components/choicequestion.tsx","./src/components/codeeditor.tsx","./src/components/errorboundary.tsx","./src/components/fillblankquestion.tsx","./src/components/footer.tsx","./src/components/gamificationsection.tsx","./src/components/keyboardshortcuts.tsx","./src/components/markdownrenderer.tsx","./src/components/navbar.tsx","./src/components/problemcard.tsx","./src/components/submissionstatus.tsx","./src/components/tutorialoverlay.tsx","./src/context/authcontext.tsx","./src/context/bookmarkcontext.tsx","./src/hooks/usedocumenttitle.ts","./src/pages/admin.tsx","./src/pages/adminproblemform.tsx","./src/pages/apidocs.tsx","./src/pages/home.tsx","./src/pages/leaderboard.tsx","./src/pages/login.tsx","./src/pages/notfound.tsx","./src/pages/problemdetail.tsx","./src/pages/problems.tsx","./src/pages/profile.tsx","./src/pages/register.tsx","./src/pages/submissions.tsx","./src/pages/systemhealth.tsx","./src/services/api.ts","./src/types/index.ts"],"version":"5.9.3"}

0 commit comments

Comments
 (0)