From 1251d35b94d64b7f34d5dd16eab8e7493b0c966c Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Mon, 7 Feb 2022 21:13:03 +0200 Subject: Add tests, do things --- src/Editor.tsx | 61 +++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 45 insertions(+), 16 deletions(-) (limited to 'src/Editor.tsx') diff --git a/src/Editor.tsx b/src/Editor.tsx index 5548586..1d4b45a 100644 --- a/src/Editor.tsx +++ b/src/Editor.tsx @@ -1,7 +1,7 @@ import AceEditor from "react-ace" import "ace-builds/src-noconflict/mode-java" import "ace-builds/src-noconflict/theme-github" -import { useState } from "react" +import { useEffect, useState } from "react" import styles from "./Editor.module.css" import { SubmitResult, submitSource, useExamples } from "./api" import Select from "react-select" @@ -18,7 +18,11 @@ const Editor = () => { const examples = useExamples() const [sourceText, setSourceText] = useState(defaultSourceText) const [result, setResult] = useState({ type: "not_yet_requested" }) - const onChange = setSourceText + const [sourceDirty, setSourceDirty] = useState(false) + const onChange = (text: string) => { + setSourceText(text) + setSourceDirty(true) + } const executeCode = async (text: string) => { const result = await submitSource(text) @@ -29,7 +33,7 @@ const Editor = () => { switch (examples.type) { case "not_yet_requested": case "loading": - return
Loading examples...
+ return
Loading examples...
case "failed": return
An unexpected error occurred while loading examples. See console for details. @@ -51,9 +55,19 @@ const Editor = () => { } return (