Spaces:
Sleeping
Sleeping
Commit ·
01916fc
1
Parent(s): 0bfc239
fix: 添加错误边界和调试日志,更新页面标题为 ClareCourseWare
Browse filesCo-authored-by: Cursor <cursoragent@cursor.com>
- web/index.html +1 -1
- web/src/App.tsx +51 -5
- web/vite.config.ts +1 -0
web/index.html
CHANGED
|
@@ -7,7 +7,7 @@
|
|
| 7 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
| 10 |
-
<title>
|
| 11 |
</head>
|
| 12 |
|
| 13 |
<body>
|
|
|
|
| 7 |
<link rel="preconnect" href="https://fonts.googleapis.com">
|
| 8 |
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
|
| 9 |
<link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700;800&display=swap" rel="stylesheet">
|
| 10 |
+
<title>ClareCourseWare - AI 智能建课助手</title>
|
| 11 |
</head>
|
| 12 |
|
| 13 |
<body>
|
web/src/App.tsx
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
// web/src/App.tsx - 教师专用版本(ClareCourseWare)
|
| 2 |
-
import React, { useState, useEffect } from "react";
|
| 3 |
import { LoginScreen } from "./components/LoginScreen";
|
| 4 |
import { TeacherDashboard } from "./components/TeacherDashboard";
|
| 5 |
import { Toaster } from "./components/ui/sonner";
|
|
@@ -9,6 +9,50 @@ export interface User {
|
|
| 9 |
email: string;
|
| 10 |
}
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
// ✅ localStorage helpers for user profile
|
| 13 |
function profileStorageKey(email: string) {
|
| 14 |
return `teacher_profile::${email}`;
|
|
@@ -48,10 +92,12 @@ function App() {
|
|
| 48 |
|
| 49 |
// ✅ 教师专用:只显示 TeacherDashboard,移除所有学生界面
|
| 50 |
return (
|
| 51 |
-
<
|
| 52 |
-
<
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
| 55 |
);
|
| 56 |
}
|
| 57 |
|
|
|
|
| 1 |
// web/src/App.tsx - 教师专用版本(ClareCourseWare)
|
| 2 |
+
import React, { useState, useEffect, ErrorInfo, Component } from "react";
|
| 3 |
import { LoginScreen } from "./components/LoginScreen";
|
| 4 |
import { TeacherDashboard } from "./components/TeacherDashboard";
|
| 5 |
import { Toaster } from "./components/ui/sonner";
|
|
|
|
| 9 |
email: string;
|
| 10 |
}
|
| 11 |
|
| 12 |
+
// ✅ Error Boundary for catching React errors
|
| 13 |
+
class ErrorBoundary extends Component<
|
| 14 |
+
{ children: React.ReactNode },
|
| 15 |
+
{ hasError: boolean; error: Error | null }
|
| 16 |
+
> {
|
| 17 |
+
constructor(props: { children: React.ReactNode }) {
|
| 18 |
+
super(props);
|
| 19 |
+
this.state = { hasError: false, error: null };
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
static getDerivedStateFromError(error: Error) {
|
| 23 |
+
return { hasError: true, error };
|
| 24 |
+
}
|
| 25 |
+
|
| 26 |
+
componentDidCatch(error: Error, errorInfo: ErrorInfo) {
|
| 27 |
+
console.error("React Error:", error, errorInfo);
|
| 28 |
+
}
|
| 29 |
+
|
| 30 |
+
render() {
|
| 31 |
+
if (this.state.hasError) {
|
| 32 |
+
return (
|
| 33 |
+
<div className="fixed inset-0 flex items-center justify-center bg-background p-4">
|
| 34 |
+
<div className="max-w-md text-center">
|
| 35 |
+
<h1 className="text-2xl font-bold text-destructive mb-4">应用错误</h1>
|
| 36 |
+
<p className="text-muted-foreground mb-4">
|
| 37 |
+
{this.state.error?.message || "未知错误"}
|
| 38 |
+
</p>
|
| 39 |
+
<button
|
| 40 |
+
onClick={() => {
|
| 41 |
+
this.setState({ hasError: false, error: null });
|
| 42 |
+
window.location.reload();
|
| 43 |
+
}}
|
| 44 |
+
className="px-4 py-2 bg-primary text-primary-foreground rounded-md"
|
| 45 |
+
>
|
| 46 |
+
重新加载
|
| 47 |
+
</button>
|
| 48 |
+
</div>
|
| 49 |
+
</div>
|
| 50 |
+
);
|
| 51 |
+
}
|
| 52 |
+
return this.props.children;
|
| 53 |
+
}
|
| 54 |
+
}
|
| 55 |
+
|
| 56 |
// ✅ localStorage helpers for user profile
|
| 57 |
function profileStorageKey(email: string) {
|
| 58 |
return `teacher_profile::${email}`;
|
|
|
|
| 92 |
|
| 93 |
// ✅ 教师专用:只显示 TeacherDashboard,移除所有学生界面
|
| 94 |
return (
|
| 95 |
+
<ErrorBoundary>
|
| 96 |
+
<div className="fixed inset-0 w-full bg-background overflow-hidden">
|
| 97 |
+
<Toaster />
|
| 98 |
+
<TeacherDashboard onBack={() => setUser(null)} />
|
| 99 |
+
</div>
|
| 100 |
+
</ErrorBoundary>
|
| 101 |
);
|
| 102 |
}
|
| 103 |
|
web/vite.config.ts
CHANGED
|
@@ -53,6 +53,7 @@
|
|
| 53 |
build: {
|
| 54 |
target: 'esnext',
|
| 55 |
outDir: 'build',
|
|
|
|
| 56 |
},
|
| 57 |
server: {
|
| 58 |
port: 3000,
|
|
|
|
| 53 |
build: {
|
| 54 |
target: 'esnext',
|
| 55 |
outDir: 'build',
|
| 56 |
+
assetsDir: 'assets',
|
| 57 |
},
|
| 58 |
server: {
|
| 59 |
port: 3000,
|