Spaces:
Runtime error
Runtime error
add refresh button + confirm modal
Browse filesFiles changed (4)
2 unmodified lines34567892 unmodified lines12131415161737 unmodified lines55565758596034 unmodified lines959697989910010129 unmodified lines1311321331341351361371381391401411421431441451461471482 unmodified linesimport Editor from "@monaco-editor/react";import classNames from "classnames";import { editor } from "monaco-editor";import { useMount, useUnmount } from "react-use";import { toast } from "react-toastify";import Header from "./header/header";2 unmodified linesimport Tabs from "./tabs/tabs";import AskAI from "./ask-ai/ask-ai";import { Auth } from "../utils/types";function App() {const preview = useRef<HTMLDivElement>(null);37 unmodified linesdocument.removeEventListener("mouseup", handleMouseUp);};useMount(() => {fetchMe();if (!editor.current || !preview.current) return;34 unmodified lines}}}><Tabs>{/* <Settings /> */}</Tabs><Editorlanguage="html"theme="vs-dark"29 unmodified linesref={resizer}className="bg-gray-700 hover:bg-blue-500 w-2 cursor-col-resize h-[calc(100dvh-54px)]"/><divref={preview}className="w-full border-l border-gray-900 bg-white h-[calc(100dvh-54px)]"><iframetitle="output"className={classNames("w-full h-full select-none", {"pointer-events-none": isResizing || isAiWorking,})}srcDoc={html}/></div></main><main className="lg:hidden p-5"><p className="p-5 bg-red-500/10 text-red-500 rounded-md text-base text-pretty">2 unmodified lines34567892 unmodified lines1213141516171837 unmodified lines5657585960616263646566676834 unmodified lines10310410510610710810929 unmodified lines1391401411421431441451461471481491502 unmodified linesimport Editor from "@monaco-editor/react";import classNames from "classnames";import { editor } from "monaco-editor";import { useMount, useUnmount, useEvent } from "react-use";import { toast } from "react-toastify";import Header from "./header/header";2 unmodified linesimport Tabs from "./tabs/tabs";import AskAI from "./ask-ai/ask-ai";import { Auth } from "../utils/types";import Preview from "./preview/preview";function App() {const preview = useRef<HTMLDivElement>(null);37 unmodified linesdocument.removeEventListener("mouseup", handleMouseUp);};useEvent("beforeunload", (e) => {if (isAiWorking || html !== defaultHTML) {e.preventDefault();return "";}});useMount(() => {fetchMe();if (!editor.current || !preview.current) return;34 unmodified lines}}}><Tabs /><Editorlanguage="html"theme="vs-dark"29 unmodified linesref={resizer}className="bg-gray-700 hover:bg-blue-500 w-2 cursor-col-resize h-[calc(100dvh-54px)]"/><Previewhtml={html}isResizing={isResizing}isAiWorking={isAiWorking}ref={preview}/></main><main className="lg:hidden p-5"><p className="p-5 bg-red-500/10 text-red-500 rounded-md text-base text-pretty">
20 unmodified lines21222324252630 unmodified lines57585960616234 unmodified lines97989910010110210320 unmodified lines}) {const [open, setOpen] = useState(false);const [prompt, setPrompt] = useState("");const callAi = async () => {if (isAiWorking) return;30 unmodified linestoast.success("AI responded successfully");setPrompt("");setisAiWorking(false);return;}34 unmodified linestype="text"disabled={isAiWorking}className="w-full bg-transparent outline-none pl-3 text-white placeholder:text-gray-500 font-code"placeholder="Ask AI anything..."value={prompt}onChange={(e) => setPrompt(e.target.value)}onKeyDown={(e) => {20 unmodified lines2122232425262730 unmodified lines5859606162636434 unmodified lines9910010110210310410510610720 unmodified lines}) {const [open, setOpen] = useState(false);const [prompt, setPrompt] = useState("");const [hasAsked, setHasAsked] = useState(false);const callAi = async () => {if (isAiWorking) return;30 unmodified linestoast.success("AI responded successfully");setPrompt("");setisAiWorking(false);setHasAsked(true);return;}34 unmodified linestype="text"disabled={isAiWorking}className="w-full bg-transparent outline-none pl-3 text-white placeholder:text-gray-500 font-code"placeholder={hasAsked ? "What do you want to ask AI next?" : "Ask AI anything..."}value={prompt}onChange={(e) => setPrompt(e.target.value)}onKeyDown={(e) => {
10 unmodified lines1112131415161710 unmodified lines{children}<a href="/api/login"><imgsrc="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-md-dark.svg"alt="Sign in with Hugging Face"className="mx-auto"/>10 unmodified lines1112131415161710 unmodified lines{children}<a href="/api/login"><imgsrc="https://huggingface.co/datasets/huggingface/badges/resolve/main/sign-in-with-huggingface-lg-dark.svg"alt="Sign in with Hugging Face"className="mx-auto"/>
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253import classNames from "classnames";import { useRef } from "react";import { TbReload } from "react-icons/tb";
function Preview({ html, isResizing, isAiWorking, ref,}: { html: string; isResizing: boolean; isAiWorking: boolean; ref: React.RefObject<HTMLDivElement | null>;}) { const iframeRef = useRef<HTMLIFrameElement | null>(null);
const handleRefreshIframe = () => { if (iframeRef.current) { const iframe = iframeRef.current; const content = iframe.srcdoc; iframe.srcdoc = ""; setTimeout(() => { iframe.srcdoc = content; }, 10); } };
return ( <div ref={ref} className="w-full border-l border-gray-900 bg-white h-[calc(100dvh-54px)] relative" > <iframe ref={iframeRef} title="output" className={classNames("w-full h-full select-none", { "pointer-events-none": isResizing || isAiWorking, })} srcDoc={html} /> <button className="bg-gray-900 shadow-md text-white text-sm font-medium absolute bottom-5 right-5 py-2 px-4 rounded-lg flex items-center gap-2 border border-gray-800 hover:brightness-150 transition-all duration-100 cursor-pointer" onClick={handleRefreshIframe} > <TbReload /> Refresh Preview </button> </div> );}
export default Preview;src/components/App.tsx+15-13
src/components/ask-ai/ask-ai.tsx+5-1
src/components/login/login.tsx+1-1
src/components/preview/preview.tsxAdded+53