Spaces:
Running
Running
Upload 8 files
Browse files- src/main.js +7 -0
- src/views/StudentView.js +6 -1
src/main.js
CHANGED
|
@@ -26,6 +26,13 @@ function navigateTo(view) {
|
|
| 26 |
renderStudentView().then(html => {
|
| 27 |
app.innerHTML = html;
|
| 28 |
setupStudentEvents();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
});
|
| 30 |
break;
|
| 31 |
case 'admin':
|
|
|
|
| 26 |
renderStudentView().then(html => {
|
| 27 |
app.innerHTML = html;
|
| 28 |
setupStudentEvents();
|
| 29 |
+
}).catch(err => {
|
| 30 |
+
console.error("Student View Load Error:", err);
|
| 31 |
+
app.innerHTML = `<div class="p-10 text-center text-red-500">
|
| 32 |
+
<h2 class="text-xl font-bold mb-2">載入失敗</h2>
|
| 33 |
+
<p class="mb-4">${err.message}</p>
|
| 34 |
+
<button onclick="window.location.reload()" class="bg-gray-700 text-white px-4 py-2 rounded">重新整理</button>
|
| 35 |
+
</div>`;
|
| 36 |
});
|
| 37 |
break;
|
| 38 |
case 'admin':
|
src/views/StudentView.js
CHANGED
|
@@ -9,7 +9,12 @@ export async function renderStudentView() {
|
|
| 9 |
|
| 10 |
// Fetch challenges if empty
|
| 11 |
if (cachedChallenges.length === 0) {
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
// Group by Level (optional, but good for UI organization if we wanted headers)
|
|
|
|
| 9 |
|
| 10 |
// Fetch challenges if empty
|
| 11 |
if (cachedChallenges.length === 0) {
|
| 12 |
+
try {
|
| 13 |
+
cachedChallenges = await getChallenges();
|
| 14 |
+
} catch (e) {
|
| 15 |
+
console.error("Failed to fetch challenges", e);
|
| 16 |
+
throw new Error("無法讀取題目列表,請檢查網路連線 (Error: " + e.message + ")");
|
| 17 |
+
}
|
| 18 |
}
|
| 19 |
|
| 20 |
// Group by Level (optional, but good for UI organization if we wanted headers)
|