mirror of
https://litchi.icu/ngc2207/judge.git
synced 2025-05-18 19:36:43 +00:00
feat(playground): add loading skeleton to editor panel for improved user experience
This commit is contained in:
parent
ededbe8f1b
commit
f58b7a5eb4
@ -1,10 +1,12 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useEffect } from "react";
|
import { useEffect, useState } from "react";
|
||||||
import { useEditorStore } from "@/store/useEditorStore";
|
import { useEditorStore } from "@/store/useEditorStore";
|
||||||
|
import { Skeleton } from "@/components/ui/skeleton";
|
||||||
|
|
||||||
export default function EditorPanel() {
|
export default function EditorPanel() {
|
||||||
const { setLanguage, setCode } = useEditorStore();
|
const { setLanguage, setCode } = useEditorStore();
|
||||||
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const handleMessage = (event: MessageEvent) => {
|
const handleMessage = (event: MessageEvent) => {
|
||||||
@ -23,5 +25,34 @@ export default function EditorPanel() {
|
|||||||
};
|
};
|
||||||
}, [setLanguage, setCode]);
|
}, [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>
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
15
src/components/ui/skeleton.tsx
Normal file
15
src/components/ui/skeleton.tsx
Normal 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 }
|
Loading…
Reference in New Issue
Block a user