preview changes
This commit is contained in:
parent
eb629835d2
commit
9d5f9c37cc
@ -56,7 +56,7 @@ import react from '@vitejs/plugin-react'
|
|||||||
export default defineConfig({
|
export default defineConfig({
|
||||||
plugins: [react()],
|
plugins: [react()],
|
||||||
server: {
|
server: {
|
||||||
port: 8000,
|
port: 3000,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
`,
|
`,
|
||||||
|
@ -4,10 +4,13 @@ import {
|
|||||||
ChevronLeft,
|
ChevronLeft,
|
||||||
ChevronRight,
|
ChevronRight,
|
||||||
Globe,
|
Globe,
|
||||||
|
Link,
|
||||||
RotateCw,
|
RotateCw,
|
||||||
TerminalSquare,
|
TerminalSquare,
|
||||||
UnfoldVertical,
|
UnfoldVertical,
|
||||||
} from "lucide-react";
|
} from "lucide-react";
|
||||||
|
import { useRef } from "react";
|
||||||
|
import { toast } from "sonner";
|
||||||
|
|
||||||
export default function PreviewWindow({
|
export default function PreviewWindow({
|
||||||
collapsed,
|
collapsed,
|
||||||
@ -18,6 +21,8 @@ export default function PreviewWindow({
|
|||||||
open: () => void;
|
open: () => void;
|
||||||
sandboxId: string;
|
sandboxId: string;
|
||||||
}) {
|
}) {
|
||||||
|
const ref = useRef<HTMLIFrameElement>(null);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<div
|
<div
|
||||||
@ -29,7 +34,7 @@ export default function PreviewWindow({
|
|||||||
<div className="text-xs">
|
<div className="text-xs">
|
||||||
Preview
|
Preview
|
||||||
<span className="inline-block ml-2 items-center font-mono text-muted-foreground">
|
<span className="inline-block ml-2 items-center font-mono text-muted-foreground">
|
||||||
localhost:8000
|
localhost:3000
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div className="flex space-x-1 translate-x-1">
|
<div className="flex space-x-1 translate-x-1">
|
||||||
@ -39,16 +44,28 @@ export default function PreviewWindow({
|
|||||||
</PreviewButton>
|
</PreviewButton>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
<PreviewButton onClick={() => console.log("Terminal")}>
|
{/* Todo, make this open inspector */}
|
||||||
|
<PreviewButton disabled onClick={() => {}}>
|
||||||
<TerminalSquare className="w-4 h-4" />
|
<TerminalSquare className="w-4 h-4" />
|
||||||
</PreviewButton>
|
</PreviewButton>
|
||||||
<PreviewButton onClick={() => console.log("Back")}>
|
|
||||||
<ChevronLeft className="w-4 h-4" />
|
<PreviewButton
|
||||||
|
onClick={() => {
|
||||||
|
navigator.clipboard.writeText(
|
||||||
|
`http://${sandboxId}.sandbox.ishaand.com`
|
||||||
|
);
|
||||||
|
toast.info("Copied preview link to clipboard");
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<Link className="w-4 h-4" />
|
||||||
</PreviewButton>
|
</PreviewButton>
|
||||||
<PreviewButton onClick={() => console.log("Forward")}>
|
<PreviewButton
|
||||||
<ChevronRight className="w-4 h-4" />
|
onClick={() => {
|
||||||
</PreviewButton>
|
if (ref.current) {
|
||||||
<PreviewButton onClick={() => console.log("Reload")}>
|
ref.current.contentWindow?.location.reload();
|
||||||
|
}
|
||||||
|
}}
|
||||||
|
>
|
||||||
<RotateCw className="w-3 h-3" />
|
<RotateCw className="w-3 h-3" />
|
||||||
</PreviewButton>
|
</PreviewButton>
|
||||||
</>
|
</>
|
||||||
@ -59,9 +76,10 @@ export default function PreviewWindow({
|
|||||||
{collapsed ? null : (
|
{collapsed ? null : (
|
||||||
<div className="w-full grow rounded-md overflow-hidden bg-foreground">
|
<div className="w-full grow rounded-md overflow-hidden bg-foreground">
|
||||||
<iframe
|
<iframe
|
||||||
|
ref={ref}
|
||||||
width={"100%"}
|
width={"100%"}
|
||||||
height={"100%"}
|
height={"100%"}
|
||||||
src={`http://${sandboxId}.s.ishaand.com`}
|
src={`http://${sandboxId}.sandbox.ishaand.com`}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
@ -71,14 +89,18 @@ export default function PreviewWindow({
|
|||||||
|
|
||||||
function PreviewButton({
|
function PreviewButton({
|
||||||
children,
|
children,
|
||||||
|
disabled = false,
|
||||||
onClick,
|
onClick,
|
||||||
}: {
|
}: {
|
||||||
children: React.ReactNode;
|
children: React.ReactNode;
|
||||||
|
disabled?: boolean;
|
||||||
onClick: () => void;
|
onClick: () => void;
|
||||||
}) {
|
}) {
|
||||||
return (
|
return (
|
||||||
<div
|
<div
|
||||||
className="p-0.5 h-5 w-5 ml-0.5 flex items-center justify-center transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm"
|
className={`${
|
||||||
|
disabled ? "pointer-events-none opacity-50" : ""
|
||||||
|
} p-0.5 h-5 w-5 ml-0.5 flex items-center justify-center transition-colors bg-transparent hover:bg-muted-foreground/25 cursor-pointer rounded-sm`}
|
||||||
onClick={onClick}
|
onClick={onClick}
|
||||||
>
|
>
|
||||||
{children}
|
{children}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user