From 88be54943033ee512db9db8dda87b22e8437412a Mon Sep 17 00:00:00 2001 From: fly6516 Date: Fri, 16 May 2025 13:55:36 +0800 Subject: [PATCH] =?UTF-8?q?refactor(app):=20=E9=87=8D=E6=9E=84=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E9=A1=B5=E9=9D=A2=E5=B9=B6=E6=B7=BB=E5=8A=A0=20AI=20?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 重构了问题页面的布局和组件 - 添加了 AI 优化代码的功能和相关组件 - 更新了 Dockview 配置,移除了 AI 优化相关的冗余代码 - 优化了代码结构,提高了组件的可复用性和可维护性 --- src/app/(app)/problems/[id]/@Code/page.tsx | 27 ++- src/app/(app)/problems/[id]/page.tsx | 268 +++++++++------------ 2 files changed, 133 insertions(+), 162 deletions(-) diff --git a/src/app/(app)/problems/[id]/@Code/page.tsx b/src/app/(app)/problems/[id]/@Code/page.tsx index 9885a41..f150484 100644 --- a/src/app/(app)/problems/[id]/@Code/page.tsx +++ b/src/app/(app)/problems/[id]/@Code/page.tsx @@ -1,11 +1,30 @@ -import { ProblemEditor } from "@/components/problem-editor"; +import { AIProblemEditor } from "@/components/ai-optimized-editor"; +import { useParams } from "next/navigation"; export default function CodePage() { + const params = useParams(); + const problemId = params.id as string; + + const handleOptimize = async () => { + // 这里实现调用AI优化逻辑 + console.log("Optimizing code for problem", problemId); + }; + return (
-
- +
+
+ +
+
); -} +} \ No newline at end of file diff --git a/src/app/(app)/problems/[id]/page.tsx b/src/app/(app)/problems/[id]/page.tsx index 81343f9..3524e9f 100644 --- a/src/app/(app)/problems/[id]/page.tsx +++ b/src/app/(app)/problems/[id]/page.tsx @@ -11,10 +11,8 @@ import { import { Locale } from "@/config/i18n"; import { useEffect, useState } from "react"; import { useTranslations } from "next-intl"; -import { usePathname } from "next/navigation"; import Dockview from "@/components/dockview"; import { useDockviewStore } from "@/stores/dockview"; -import { AIProblemEditor } from "@/components/ai-optimized-editor"; interface ProblemPageProps { locale: Locale; @@ -28,169 +26,123 @@ interface ProblemPageProps { } export default function ProblemPage({ - locale, - Description, - Solutions, - Submissions, - Details, - Code, - Testcase, - Bot, -}: ProblemPageProps) { + locale, + Description, + Solutions, + Submissions, + Details, + Code, + Testcase, + Bot, + }: ProblemPageProps) { const [key, setKey] = useState(0); const { setApi } = useDockviewStore(); const t = useTranslations("ProblemPage"); - const pathname = usePathname(); - const problemId = pathname.split("/").pop(); // 从URL提取problemId - - // AI优化相关状态 - const [showAIEditor, setShowAIEditor] = useState(false); - const [userCode, setUserCode] = useState(`function example() { - // 初始代码 - return "Hello World"; -}`); - - // 修改Code面板内容以包含切换功能 - const CodeWithToggle = ( -
-
- - - {showAIEditor && ( - - )} -
- - {showAIEditor ? ( - - ) : ( - // 原始Code组件保持不变 -
- {Code} -
- )} -
- ); useEffect(() => { setKey((prevKey) => prevKey + 1); }, [locale]); - // 修改Dockview配置:更新Code面板引用 return ( - + ); -} +} \ No newline at end of file