diff --git a/src/app/api/error-items/[id]/geogebra/route.ts b/src/app/api/error-items/[id]/geogebra/route.ts index b97869e9e..19eb686c9 100644 --- a/src/app/api/error-items/[id]/geogebra/route.ts +++ b/src/app/api/error-items/[id]/geogebra/route.ts @@ -65,10 +65,18 @@ export async function POST( } const aiService = getAIService(); + + // Use frontend-provided data if available (more up-to-date), fall back to DB + const body = await req.json().catch(() => ({})); + const questionText = body.questionText || errorItem.questionText; + const answerText = body.answerText || errorItem.answerText || ""; + const previousErrors = body.previousErrors || ""; + const result = await aiService.analyzeForGeogebra( - errorItem.questionText, - errorItem.answerText || "", - errorItem.analysis || "" + questionText, + answerText, + errorItem.analysis || "", + previousErrors ); // If suitable, save the commands to the database diff --git a/src/app/error-items/[id]/page.tsx b/src/app/error-items/[id]/page.tsx index 23972da4c..66ff9782c 100644 --- a/src/app/error-items/[id]/page.tsx +++ b/src/app/error-items/[id]/page.tsx @@ -1,11 +1,11 @@ "use client"; -import { useEffect, useState } from "react"; +import { useEffect, useState, useRef } from "react"; import { useParams, useRouter } from "next/navigation"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; -import { ArrowLeft, CheckCircle, XCircle, RefreshCw, Trash2, Edit, Save, X, Box, Loader2 } from "lucide-react"; +import { ArrowLeft, CheckCircle, XCircle, RefreshCw, Trash2, Edit, Save, X, Box, Loader2, Eye, EyeOff, ImageIcon } from "lucide-react"; import { Textarea } from "@/components/ui/textarea"; import Link from "next/link"; import { useLanguage } from "@/contexts/LanguageContext"; @@ -37,6 +37,8 @@ interface ErrorItemDetail { tags: KnowledgeTag[]; // 新的标签关联 masteryLevel: number; originalImageUrl: string; + referenceImageUrl?: string | null; + wrongAnswerImageUrl?: string | null; userNotes: string | null; subjectId?: string | null; subject?: { @@ -68,6 +70,11 @@ export default function ErrorDetailPage() { const [isAnalyzingGeogebra, setIsAnalyzingGeogebra] = useState(false); const [geogebraError, setGeogebraError] = useState(null); + const [showQuestionImage, setShowQuestionImage] = useState(false); + const [showReferenceImage, setShowReferenceImage] = useState(false); + const [showOwnImage, setShowOwnImage] = useState(false); + const [showFloatingQuestion, setShowFloatingQuestion] = useState(false); + const questionRef = useRef(null); useEffect(() => { // Fetch user info for education stage @@ -128,6 +135,12 @@ export default function ErrorDetailPage() { } }; + const handleSaveGeogebraCommands = async (commands: string) => { + if (!item) return; + await apiClient.put(`/api/error-items/${item.id}`, { geogebraCommands: commands }); + setItem({ ...item, geogebraCommands: commands }); + }; + const toggleMastery = async () => { if (!item) return; @@ -394,6 +407,21 @@ export default function ErrorDetailPage() { } }; + useEffect(() => { + const handleScroll = () => { + if (!questionRef.current) return; + const rect = questionRef.current.getBoundingClientRect(); + if (rect.bottom < -50) { + setShowFloatingQuestion(true); + } else { + setShowFloatingQuestion(false); + } + }; + window.addEventListener("scroll", handleScroll, { passive: true }); + handleScroll(); + return () => window.removeEventListener("scroll", handleScroll); + }, []); + if (loading) return
{t.common.loading}
; if (!item) return
{t.detail.notFound || "Item not found"}
; @@ -460,494 +488,99 @@ export default function ErrorDetailPage() { -
- {/* Left Column: Question & Image */} -
- - -
- {t.detail.question} - {!isEditingQuestion && ( - - )} -
-
- - {item.originalImageUrl && ( -
setIsImageViewerOpen(true)} - title={t.detail?.clickToView || 'Click to view full image'} - > -

- {t.detail.originalProblem || "Original Problem"} -

- {t.detail.originalProblem -

- 💡 {t.detail?.clickToEnlarge || 'Click to enlarge'} -

-
- )} - - {isEditingQuestion ? ( -
-