feat(playground): add loading skeleton to editor panel for improved user experience

This commit is contained in:
ngc2207 2025-01-11 08:29:25 +08:00
parent ededbe8f1b
commit f58b7a5eb4
2 changed files with 48 additions and 2 deletions

View File

@ -1,10 +1,12 @@
"use client";
import { useEffect } from "react";
import { useEffect, useState } from "react";
import { useEditorStore } from "@/store/useEditorStore";
import { Skeleton } from "@/components/ui/skeleton";
export default function EditorPanel() {
const { setLanguage, setCode } = useEditorStore();
const [loading, setLoading] = useState(true);
useEffect(() => {
const handleMessage = (event: MessageEvent) => {
@ -23,5 +25,34 @@ export default function EditorPanel() {
};
}, [setLanguage, setCode]);
return <iframe src="https://editor.litchi.icu" className="w-full h-full" />;
const handleLoad = () => {
setLoading(false);
};
return (
<div className="relative w-full h-full">
{loading && (
<div className="absolute inset-0 flex flex-col bg-[#282c34]">
<div className="flex-initial p-4 border-b border-[#3e4452] flex justify-between items-center">
<div className="space-x-2 flex items-center">
<Skeleton className="h-8 w-24 rounded-md" />
<Skeleton className="h-8 w-24 rounded-md" />
</div>
<div className="space-x-2 flex items-center">
<Skeleton className="h-8 w-24 rounded-md" />
<Skeleton className="h-8 w-24 rounded-md" />
</div>
</div>
<div className="flex-grow p-4">
<Skeleton className="w-full h-full rounded-md" />
</div>
</div>
)}
<iframe
src="https://editor.litchi.icu"
className="w-full h-full"
onLoad={handleLoad}
/>
</div>
);
}

View File

@ -0,0 +1,15 @@
import { cn } from "@/lib/utils"
function Skeleton({
className,
...props
}: React.HTMLAttributes<HTMLDivElement>) {
return (
<div
className={cn("animate-pulse rounded-md bg-primary/10", className)}
{...props}
/>
)
}
export { Skeleton }