From f7271130ceebe1fd2d184298fc2d1e892ab7d64f Mon Sep 17 00:00:00 2001 From: Jan Tuomi Date: Sat, 5 Feb 2022 23:17:25 +0200 Subject: More things --- src/Editor.tsx | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) (limited to 'src/Editor.tsx') diff --git a/src/Editor.tsx b/src/Editor.tsx index 41bf9ff..afce380 100644 --- a/src/Editor.tsx +++ b/src/Editor.tsx @@ -3,7 +3,8 @@ import "ace-builds/src-noconflict/mode-java" import "ace-builds/src-noconflict/theme-github" import { useState } from "react" import styles from "./Editor.module.css" -import { APIResult, submitSource } from "./api" +import { APIResult, submitSource, useExamples } from "./api" +import Select from "react-select" const defaultSourceText = `define times2 dup + @@ -14,6 +15,7 @@ const defaultSourceText = `define times2 ` const Editor = () => { + const examples = useExamples() const [sourceText, setSourceText] = useState(defaultSourceText) const [result, setResult] = useState>({ type: "not_yet_requested" }) const onChange = setSourceText @@ -23,6 +25,39 @@ const Editor = () => { setResult(result) } + const renderExamples = () => { + switch (examples.type) { + case "not_yet_requested": + case "loading": + return
Loading examples...
+ case "failed": + return
+ An unexpected error occurred while loading examples. See console for details. +
+ case "success": { + const options = examples.data.map(example => ({ value: example.content, label: example.title })) + const customStyles = { + option: (styles: any) => ({ + ...styles, + cursor: "pointer", + }), + control: (styles: any) => ({ + ...styles, + cursor: "pointer", + }), + } + return ( +