forked from Nutlope/llamacoder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode-runner-server-action.tsx
More file actions
43 lines (39 loc) · 1.19 KB
/
Copy pathcode-runner-server-action.tsx
File metadata and controls
43 lines (39 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
"use client";
import PlayIcon from "@/components/icons/play-icon";
import Spinner from "@/components/spinner";
import { useActionState } from "react";
export default function CodeRunnerServerAction({
code,
runCodeAction,
}: {
code: string;
runCodeAction: (v: string) => Promise<string>;
}) {
const [state, action, isPending] = useActionState(async () => {
return runCodeAction(code);
}, null);
return (
<div>
{state === null ? (
<div className="flex flex-col items-center justify-center">
<p>Run the code to generate an output</p>
<form action={action} className="mt-4">
<button
disabled={isPending}
className="inline-flex rounded border border-gray-300 px-2.5 py-1 text-sm text-gray-600 transition enabled:hover:bg-gray-100 disabled:opacity-75"
>
<Spinner loading={isPending}>
<span className="inline-flex items-center gap-1">
<PlayIcon className="size-4" />
Run Code
</span>
</Spinner>
</button>
</form>
</div>
) : (
<div>{state}</div>
)}
</div>
);
}