feat: add preview panel button
This commit is contained in:
parent
6ea86afc70
commit
f863f2f763
@ -145,7 +145,7 @@ export default function CodeEditor({
|
|||||||
const generateRef = useRef<HTMLDivElement>(null)
|
const generateRef = useRef<HTMLDivElement>(null)
|
||||||
const suggestionRef = useRef<HTMLDivElement>(null)
|
const suggestionRef = useRef<HTMLDivElement>(null)
|
||||||
const generateWidgetRef = useRef<HTMLDivElement>(null)
|
const generateWidgetRef = useRef<HTMLDivElement>(null)
|
||||||
const previewPanelRef = useRef<ImperativePanelHandle>(null)
|
const { previewPanelRef } = usePreview();
|
||||||
const editorPanelRef = useRef<ImperativePanelHandle>(null)
|
const editorPanelRef = useRef<ImperativePanelHandle>(null)
|
||||||
const previewWindowRef = useRef<{ refreshIframe: () => void }>(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
|
// On disabled access for shared users, show un-interactable loading placeholder + info modal
|
||||||
if (disableAccess.isDisabled)
|
if (disableAccess.isDisabled)
|
||||||
return (
|
return (
|
||||||
@ -1061,7 +1071,7 @@ export default function CodeEditor({
|
|||||||
<ResizablePanel defaultSize={40}>
|
<ResizablePanel defaultSize={40}>
|
||||||
<ResizablePanelGroup direction="vertical">
|
<ResizablePanelGroup direction="vertical">
|
||||||
<ResizablePanel
|
<ResizablePanel
|
||||||
ref={usePreview().previewPanelRef}
|
ref={previewPanelRef}
|
||||||
defaultSize={4}
|
defaultSize={4}
|
||||||
collapsedSize={4}
|
collapsedSize={4}
|
||||||
minSize={25}
|
minSize={25}
|
||||||
@ -1071,10 +1081,7 @@ export default function CodeEditor({
|
|||||||
onExpand={() => setIsPreviewCollapsed(false)}
|
onExpand={() => setIsPreviewCollapsed(false)}
|
||||||
>
|
>
|
||||||
<PreviewWindow
|
<PreviewWindow
|
||||||
open={() => {
|
open={togglePreviewPanel}
|
||||||
usePreview().previewPanelRef.current?.expand()
|
|
||||||
setIsPreviewCollapsed(false)
|
|
||||||
}}
|
|
||||||
collapsed={isPreviewCollapsed}
|
collapsed={isPreviewCollapsed}
|
||||||
src={previewURL}
|
src={previewURL}
|
||||||
ref={previewWindowRef}
|
ref={previewWindowRef}
|
||||||
@ -1116,4 +1123,4 @@ const defaultCompilerOptions: monaco.languages.typescript.CompilerOptions = {
|
|||||||
module: monaco.languages.typescript.ModuleKind.ESNext,
|
module: monaco.languages.typescript.ModuleKind.ESNext,
|
||||||
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
|
moduleResolution: monaco.languages.typescript.ModuleResolutionKind.NodeJs,
|
||||||
target: monaco.languages.typescript.ScriptTarget.ESNext,
|
target: monaco.languages.typescript.ScriptTarget.ESNext,
|
||||||
}
|
}
|
@ -4,6 +4,7 @@ import {
|
|||||||
Link,
|
Link,
|
||||||
RotateCw,
|
RotateCw,
|
||||||
TerminalSquare,
|
TerminalSquare,
|
||||||
|
UnfoldVertical,
|
||||||
} from "lucide-react"
|
} from "lucide-react"
|
||||||
import { useEffect, useRef, useState, useImperativeHandle, forwardRef } from "react"
|
import { useEffect, useRef, useState, useImperativeHandle, forwardRef } from "react"
|
||||||
import { toast } from "sonner"
|
import { toast } from "sonner"
|
||||||
@ -40,16 +41,14 @@ ref: React.Ref<{
|
|||||||
<div className="text-xs">Preview</div>
|
<div className="text-xs">Preview</div>
|
||||||
<div className="flex space-x-1 translate-x-1">
|
<div className="flex space-x-1 translate-x-1">
|
||||||
{collapsed ? (
|
{collapsed ? (
|
||||||
<PreviewButton disabled onClick={() => { }}>
|
<PreviewButton onClick={open}>
|
||||||
<TerminalSquare className="w-4 h-4" />
|
<UnfoldVertical className="w-4 h-4" />
|
||||||
</PreviewButton>
|
</PreviewButton>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
{/* Removed the unfoldvertical button since we have the same thing via the run button.
|
|
||||||
|
|
||||||
<PreviewButton onClick={open}>
|
<PreviewButton onClick={open}>
|
||||||
<UnfoldVertical className="w-4 h-4" />
|
<UnfoldVertical className="w-4 h-4" />
|
||||||
</PreviewButton> */}
|
</PreviewButton>
|
||||||
|
|
||||||
<PreviewButton
|
<PreviewButton
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user