From f863f2f76367b5ad951df4403c2ec8e3e9676dff Mon Sep 17 00:00:00 2001 From: Akhileshrangani4 Date: Sat, 12 Oct 2024 17:55:49 -0400 Subject: [PATCH] feat: add preview panel button --- frontend/components/editor/index.tsx | 21 +++++++++++++------- frontend/components/editor/preview/index.tsx | 9 ++++----- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/frontend/components/editor/index.tsx b/frontend/components/editor/index.tsx index 415b552..39af65a 100644 --- a/frontend/components/editor/index.tsx +++ b/frontend/components/editor/index.tsx @@ -145,7 +145,7 @@ export default function CodeEditor({ const generateRef = useRef(null) const suggestionRef = useRef(null) const generateWidgetRef = useRef(null) - const previewPanelRef = useRef(null) + const { previewPanelRef } = usePreview(); const editorPanelRef = useRef(null) const previewWindowRef = useRef<{ refreshIframe: () => void }>(null) @@ -827,6 +827,16 @@ export default function CodeEditor({ }) } + const togglePreviewPanel = () => { + if (isPreviewCollapsed) { + previewPanelRef.current?.expand(); + setIsPreviewCollapsed(false); + } else { + previewPanelRef.current?.collapse(); + setIsPreviewCollapsed(true); + } + }; + // On disabled access for shared users, show un-interactable loading placeholder + info modal if (disableAccess.isDisabled) return ( @@ -1061,7 +1071,7 @@ export default function CodeEditor({ setIsPreviewCollapsed(false)} > { - usePreview().previewPanelRef.current?.expand() - setIsPreviewCollapsed(false) - }} + open={togglePreviewPanel} collapsed={isPreviewCollapsed} src={previewURL} ref={previewWindowRef} @@ -1116,4 +1123,4 @@ const defaultCompilerOptions: monaco.languages.typescript.CompilerOptions = { module: monaco.languages.typescript.ModuleKind.ESNext, moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs, target: monaco.languages.typescript.ScriptTarget.ESNext, -} +} \ No newline at end of file diff --git a/frontend/components/editor/preview/index.tsx b/frontend/components/editor/preview/index.tsx index 1c32c6a..089e26f 100644 --- a/frontend/components/editor/preview/index.tsx +++ b/frontend/components/editor/preview/index.tsx @@ -4,6 +4,7 @@ import { Link, RotateCw, TerminalSquare, + UnfoldVertical, } from "lucide-react" import { useEffect, useRef, useState, useImperativeHandle, forwardRef } from "react" import { toast } from "sonner" @@ -40,16 +41,14 @@ ref: React.Ref<{
Preview
{collapsed ? ( - { }}> - + + ) : ( <> - {/* Removed the unfoldvertical button since we have the same thing via the run button. - - */} + {