2025-04-06 09:34:07 +00:00
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import {
|
2025-04-13 03:56:01 +00:00
|
|
|
|
BotIcon,
|
|
|
|
|
CircleCheckBigIcon,
|
|
|
|
|
FileTextIcon,
|
|
|
|
|
FlaskConicalIcon,
|
|
|
|
|
SquareCheckIcon,
|
|
|
|
|
SquarePenIcon,
|
|
|
|
|
} from "lucide-react";
|
2025-04-15 10:22:21 +00:00
|
|
|
|
import { Locale } from "@/config/i18n";
|
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
|
import { useTranslations } from "next-intl";
|
2025-04-13 03:56:01 +00:00
|
|
|
|
import Dockview from "@/components/dockview";
|
|
|
|
|
import { useDockviewStore } from "@/stores/dockview";
|
2025-05-15 18:40:07 +00:00
|
|
|
|
import { AIProblemEditor } from "@/components/ai-optimized-editor";
|
2025-04-13 03:56:01 +00:00
|
|
|
|
|
|
|
|
|
interface ProblemPageProps {
|
2025-04-15 10:22:21 +00:00
|
|
|
|
locale: Locale;
|
2025-04-13 03:56:01 +00:00
|
|
|
|
Description: React.ReactNode;
|
|
|
|
|
Solutions: React.ReactNode;
|
|
|
|
|
Submissions: React.ReactNode;
|
2025-04-13 14:42:08 +00:00
|
|
|
|
Details: React.ReactNode;
|
2025-04-13 03:56:01 +00:00
|
|
|
|
Code: React.ReactNode;
|
|
|
|
|
Testcase: React.ReactNode;
|
|
|
|
|
Bot: React.ReactNode;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default function ProblemPage({
|
2025-04-15 10:22:21 +00:00
|
|
|
|
locale,
|
2025-04-06 09:34:07 +00:00
|
|
|
|
Description,
|
|
|
|
|
Solutions,
|
|
|
|
|
Submissions,
|
2025-04-13 14:42:08 +00:00
|
|
|
|
Details,
|
2025-04-13 03:56:01 +00:00
|
|
|
|
Code,
|
2025-04-06 09:34:07 +00:00
|
|
|
|
Testcase,
|
2025-04-13 03:56:01 +00:00
|
|
|
|
Bot,
|
|
|
|
|
}: ProblemPageProps) {
|
2025-04-15 10:22:21 +00:00
|
|
|
|
const [key, setKey] = useState(0);
|
2025-04-12 02:47:23 +00:00
|
|
|
|
const { setApi } = useDockviewStore();
|
2025-04-15 10:22:21 +00:00
|
|
|
|
const t = useTranslations("ProblemPage");
|
2025-05-15 18:40:07 +00:00
|
|
|
|
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 = (
|
|
|
|
|
<div className="p-2">
|
|
|
|
|
<div className="flex justify-between items-center mb-2">
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setShowAIEditor(!showAIEditor)}
|
|
|
|
|
className="px-3 py-1 bg-primary text-primary-foreground rounded-md text-sm"
|
|
|
|
|
>
|
|
|
|
|
{showAIEditor ? "普通编辑器" : "AI优化编辑器"}
|
|
|
|
|
</button>
|
|
|
|
|
|
|
|
|
|
{showAIEditor && (
|
|
|
|
|
<button
|
|
|
|
|
onClick={() => setShowAIEditor(false)}
|
|
|
|
|
className="px-3 py-1 bg-secondary text-secondary-foreground rounded-md text-sm"
|
|
|
|
|
>
|
|
|
|
|
返回编辑
|
|
|
|
|
</button>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
{showAIEditor ? (
|
|
|
|
|
<AIProblemEditor
|
|
|
|
|
initialCode={userCode}
|
|
|
|
|
problemId={problemId}
|
|
|
|
|
onCodeChange={setUserCode}
|
|
|
|
|
/>
|
|
|
|
|
) : (
|
|
|
|
|
// 原始Code组件保持不变
|
|
|
|
|
<div className="h-[500px]">
|
|
|
|
|
{Code}
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
|
|
|
|
</div>
|
|
|
|
|
);
|
2025-04-15 10:22:21 +00:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setKey((prevKey) => prevKey + 1);
|
|
|
|
|
}, [locale]);
|
|
|
|
|
|
2025-05-15 18:40:07 +00:00
|
|
|
|
// 修改Dockview配置:更新Code面板引用
|
2025-04-06 09:34:07 +00:00
|
|
|
|
return (
|
2025-04-13 03:56:01 +00:00
|
|
|
|
<Dockview
|
2025-04-15 10:22:21 +00:00
|
|
|
|
key={key}
|
2025-04-06 09:34:07 +00:00
|
|
|
|
storageKey="dockview:problem"
|
2025-04-12 02:47:23 +00:00
|
|
|
|
onApiReady={setApi}
|
2025-04-13 03:56:01 +00:00
|
|
|
|
options={[
|
|
|
|
|
{
|
|
|
|
|
id: "Description",
|
|
|
|
|
component: "Description",
|
|
|
|
|
tabComponent: "Description",
|
|
|
|
|
params: {
|
|
|
|
|
icon: FileTextIcon,
|
|
|
|
|
content: Description,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Description"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Solutions",
|
|
|
|
|
component: "Solutions",
|
|
|
|
|
tabComponent: "Solutions",
|
|
|
|
|
params: {
|
|
|
|
|
icon: FlaskConicalIcon,
|
|
|
|
|
content: Solutions,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Solutions"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
referencePanel: "Description",
|
|
|
|
|
direction: "within",
|
|
|
|
|
},
|
|
|
|
|
inactive: true,
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Submissions",
|
|
|
|
|
component: "Submissions",
|
|
|
|
|
tabComponent: "Submissions",
|
|
|
|
|
params: {
|
|
|
|
|
icon: CircleCheckBigIcon,
|
|
|
|
|
content: Submissions,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Submissions"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
referencePanel: "Solutions",
|
|
|
|
|
direction: "within",
|
|
|
|
|
},
|
|
|
|
|
inactive: true,
|
|
|
|
|
},
|
2025-04-13 14:42:08 +00:00
|
|
|
|
{
|
|
|
|
|
id: "Details",
|
|
|
|
|
component: "Details",
|
|
|
|
|
tabComponent: "Details",
|
|
|
|
|
params: {
|
|
|
|
|
icon: CircleCheckBigIcon,
|
|
|
|
|
content: Details,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Details"),
|
2025-04-13 14:42:08 +00:00
|
|
|
|
autoAdd: false,
|
|
|
|
|
},
|
|
|
|
|
},
|
2025-04-13 03:56:01 +00:00
|
|
|
|
{
|
|
|
|
|
id: "Code",
|
|
|
|
|
component: "Code",
|
|
|
|
|
tabComponent: "Code",
|
|
|
|
|
params: {
|
|
|
|
|
icon: SquarePenIcon,
|
2025-05-15 18:40:07 +00:00
|
|
|
|
content: CodeWithToggle, // 替换为带切换功能的容器
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Code"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
referencePanel: "Submissions",
|
|
|
|
|
direction: "right",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Testcase",
|
|
|
|
|
component: "Testcase",
|
|
|
|
|
tabComponent: "Testcase",
|
|
|
|
|
params: {
|
|
|
|
|
icon: SquareCheckIcon,
|
|
|
|
|
content: Testcase,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Testcase"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
referencePanel: "Code",
|
|
|
|
|
direction: "below",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
id: "Bot",
|
|
|
|
|
component: "Bot",
|
|
|
|
|
tabComponent: "Bot",
|
|
|
|
|
params: {
|
|
|
|
|
icon: BotIcon,
|
|
|
|
|
content: Bot,
|
2025-04-19 04:53:39 +00:00
|
|
|
|
title: t("Bot"),
|
2025-04-13 03:56:01 +00:00
|
|
|
|
autoAdd: false,
|
|
|
|
|
},
|
|
|
|
|
position: {
|
|
|
|
|
direction: "right",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
]}
|
2025-04-06 09:34:07 +00:00
|
|
|
|
/>
|
|
|
|
|
);
|
|
|
|
|
}
|