mirror of
https://github.com/massbug/judge4c.git
synced 2025-05-19 08:06:33 +00:00
refactor(ResetButton): replace useCodeEditorStore with useProblemEditor
This commit is contained in:
parent
0ae01d35bc
commit
00f83d69f1
@ -8,29 +8,12 @@ import {
|
|||||||
} from "@/components/ui/tooltip";
|
} from "@/components/ui/tooltip";
|
||||||
import { RotateCcw } from "lucide-react";
|
import { RotateCcw } from "lucide-react";
|
||||||
import { Button } from "@/components/ui/button";
|
import { Button } from "@/components/ui/button";
|
||||||
import { EditorLanguage } from "@prisma/client";
|
import { useProblemEditor } from "@/hooks/use-problem-editor";
|
||||||
import { useCodeEditorStore } from "@/store/useCodeEditorStore";
|
|
||||||
|
|
||||||
interface ResetButtonProps {
|
export function ResetButton() {
|
||||||
templates: { language: EditorLanguage; template: string }[];
|
const { editor, currentTemplate } = useProblemEditor();
|
||||||
}
|
|
||||||
|
|
||||||
export default function ResetButton({
|
const handleReset = () => {
|
||||||
templates,
|
|
||||||
}: ResetButtonProps) {
|
|
||||||
const { editor, language } = useCodeEditorStore();
|
|
||||||
|
|
||||||
const currentTemplate = templates.find((t) => t.language === language)?.template ?? "";
|
|
||||||
|
|
||||||
return (
|
|
||||||
<TooltipProvider delayDuration={0}>
|
|
||||||
<Tooltip>
|
|
||||||
<TooltipTrigger asChild>
|
|
||||||
<Button
|
|
||||||
variant="outline"
|
|
||||||
size="icon"
|
|
||||||
aria-label="Reset Code"
|
|
||||||
onClick={() => {
|
|
||||||
if (editor) {
|
if (editor) {
|
||||||
const model = editor.getModel();
|
const model = editor.getModel();
|
||||||
if (model) {
|
if (model) {
|
||||||
@ -46,7 +29,18 @@ export default function ResetButton({
|
|||||||
editor.pushUndoStop();
|
editor.pushUndoStop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}}
|
};
|
||||||
|
|
||||||
|
return (
|
||||||
|
<TooltipProvider delayDuration={0}>
|
||||||
|
<Tooltip>
|
||||||
|
<TooltipTrigger asChild>
|
||||||
|
<Button
|
||||||
|
variant="outline"
|
||||||
|
size="icon"
|
||||||
|
aria-label="Reset Code"
|
||||||
|
onClick={handleReset}
|
||||||
|
disabled={!editor}
|
||||||
className="h-6 w-6 px-1.5 py-0.5 border-none shadow-none hover:bg-muted"
|
className="h-6 w-6 px-1.5 py-0.5 border-none shadow-none hover:bg-muted"
|
||||||
>
|
>
|
||||||
<RotateCcw size={16} strokeWidth={2} aria-hidden="true" />
|
<RotateCcw size={16} strokeWidth={2} aria-hidden="true" />
|
||||||
|
Loading…
Reference in New Issue
Block a user