"use client"; import React, { useEffect, useState } from "react"; import { compileCode } from "./compiler"; import { v4 as uuid } from "uuid"; import { CodeEditor } from "./code-editor"; import { ErrorBoundary } from "react-error-boundary"; import PreviewErrorFallback from "./preview-error-fallback"; import { ResizableHandle, ResizablePanel, ResizablePanelGroup, } from "@/components/ui/resizable"; import { ThemeDropdown } from "./theme-dropdown"; import LanguagesDropdown from "./languages-dropdown"; import Output from "./output"; import { tutorialData } from "@/constants/tutorial-data"; import { notFound, useRouter } from "next/navigation"; import { defineTheme } from "@/utils/define-theme"; import Preview from "./preview"; import { MyComponents } from "./my-components"; import { cn } from "@/lib/utils"; export default function EditorWindow({ activeMobileView: activeMobileView, language: lang, step, }: { activeMobileView: "tutorial" | "code" | "output"; language: string; step: number; }) { const [componentName, setComponentName] = useState(""); const [theme, setTheme] = useState("cobalt"); // const [language, setLanguage] = useState(languageOptions[0]); // const [language, setLanguage] = useState("react"); // const [defaultCode, setDefaultCode] = useState(""); const [codeValue, setCodeValue] = useState(""); const router = useRouter(); const handleCodeChange = (code: string | undefined) => { try { setCodeValue(code || ""); const func = compileCode(code || ""); const id = uuid(); MyComponents[id] = func(React); setComponentName(id); } catch (err) { console.log(err); // setComponentName("error"); } }; useEffect(() => { defineTheme("cobalt").then((_) => setTheme("cobalt")); }, []); function handleThemeChange(th: string) { const themee = th; // console.log("theme...", theme); if (["light", "vs-dark"].includes(themee)) { setTheme(themee); } else { defineTheme(themee).then((_) => setTheme(themee)); } } const handleLanguageChange = (lang: string) => { router.push(`/dashboard/task/${lang}/1`); // try { // if (lang === "react") { // const func = compileCode(CODE_SNIPPETS[lang]); // const id = uuid(); // MyComponents[id] = func(React); // setComponentName(id); // } // setLanguage(lang); // // @ts-ignore // setCodeValue(CODE_SNIPPETS[lang]); // // @ts-ignore // // setDefaultCode(CODE_SNIPPETS[language]); // } catch (error) { // // console.log(error); // } }; const tutorial = tutorialData .find((t) => t.language === lang) ?.tutorial.find((t) => t.id === step); if (!tutorial) { notFound(); } // console.log(tutorial); return ( <>
{/* */}
{/* */}
{/*
*/} {/* */} {/* */}
{lang === "react" ? ( ) : ( )}
{/*
*/} {/*
*/}
{/* */}
{lang === "react" ? ( ) : ( )}
); }