diff --git a/src/app/runs/[runId]/components/Editor.tsx b/src/app/runs/[runId]/components/Editor.tsx index 82ccf7b..dc9b865 100644 --- a/src/app/runs/[runId]/components/Editor.tsx +++ b/src/app/runs/[runId]/components/Editor.tsx @@ -43,7 +43,10 @@ function getLanguageExtension(lang: Language) { export default function Editor({ run }: { run: LiveRun | null | undefined }) { const [editorView, setEditorView] = useState(); - const [moves] = useActionOnce(getLiveRunMoves, [run]); + const [moves] = useActionOnce( + async () => (run ? (await getLiveRunMoves(run.id)) || [] : []), + [run], + ); useEffect(() => { if (!editorView || !moves) return; diff --git a/src/modules/live-run/actions.ts b/src/modules/live-run/actions.ts index df15010..55b95a6 100644 --- a/src/modules/live-run/actions.ts +++ b/src/modules/live-run/actions.ts @@ -11,38 +11,6 @@ export async function getLiveRun(id: string): Promise { return Core.getLiveRun(id); } -export async function getLiveRunMoves() { - const code = `// Import the necessary React library features -import { createRoot } from 'react-dom/client'; - -// Define a functional component named "App" -// Component names must start with a capital letter -function App() { - // Components return JSX markup - return ( -

Hello, world!

- ); -} - -// Target a DOM element in your HTML (e.g.,
) -const domNode = document.getElementById('root'); - -// Create a root and render your component into the DOM -const root = createRoot(domNode); -root.render();`.repeat(3); - - const chunks = []; - for (let i = 0; i < code.length; i += 4) { - chunks.push(code.slice(i, i + 4)); - } - - return chunks.map((chunk, index) => ({ - latency: 120, // 100ms per chunk - cursor: index * 4, // approximate cursor position - changes: { - from: index * 4, - to: index * 4, - insert: chunk, - }, - })); +export async function getLiveRunMoves(id: string) { + return Core.getLiveRunMoves(id); }