feat: add preview panel button

This commit is contained in:
Akhileshrangani4 2024-10-12 17:55:49 -04:00
parent 6ea86afc70
commit f863f2f763
2 changed files with 18 additions and 12 deletions

View File

@ -145,7 +145,7 @@ export default function CodeEditor({
const generateRef = useRef<HTMLDivElement>(null)
const suggestionRef = useRef<HTMLDivElement>(null)
const generateWidgetRef = useRef<HTMLDivElement>(null)
const previewPanelRef = useRef<ImperativePanelHandle>(null)
const { previewPanelRef } = usePreview();
const editorPanelRef = useRef<ImperativePanelHandle>(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({
<ResizablePanel defaultSize={40}>
<ResizablePanelGroup direction="vertical">
<ResizablePanel
ref={usePreview().previewPanelRef}
ref={previewPanelRef}
defaultSize={4}
collapsedSize={4}
minSize={25}
@ -1071,10 +1081,7 @@ export default function CodeEditor({
onExpand={() => setIsPreviewCollapsed(false)}
>
<PreviewWindow
open={() => {
usePreview().previewPanelRef.current?.expand()
setIsPreviewCollapsed(false)
}}
open={togglePreviewPanel}
collapsed={isPreviewCollapsed}
src={previewURL}
ref={previewWindowRef}

View File

@ -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<{
<div className="text-xs">Preview</div>
<div className="flex space-x-1 translate-x-1">
{collapsed ? (
<PreviewButton disabled onClick={() => { }}>
<TerminalSquare className="w-4 h-4" />
<PreviewButton onClick={open}>
<UnfoldVertical className="w-4 h-4" />
</PreviewButton>
) : (
<>
{/* Removed the unfoldvertical button since we have the same thing via the run button.
<PreviewButton onClick={open}>
<UnfoldVertical className="w-4 h-4" />
</PreviewButton> */}
</PreviewButton>
<PreviewButton
onClick={() => {