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/App.module.css | 4 ---- src/App.tsx | 22 ---------------------- src/Editor.module.css | 12 ++++++++++++ src/Editor.tsx | 40 +++++++++++++++++++++++++++++++++++++++- src/Tutorial.tsx | 2 +- 5 files changed, 52 insertions(+), 28 deletions(-) (limited to 'src') diff --git a/src/App.module.css b/src/App.module.css index 3b75e8c..74f3339 100644 --- a/src/App.module.css +++ b/src/App.module.css @@ -34,10 +34,6 @@ color: var(--red) } -.examples { - margin-bottom: 20px; -} - .editor { margin-bottom: 40px; } diff --git a/src/App.tsx b/src/App.tsx index 905149e..9e78af3 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,28 +1,9 @@ -import { useExamples } from "./api" import styles from "./App.module.css" import Editor from "./Editor" import Tutorial from "./Tutorial" import icon from "./favicon.png" const App = () => { - const examples = useExamples() - - 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": - return examples.data.map((example) => -
{example.title}
, - ) - } - } - return (
@@ -34,9 +15,6 @@ const App = () => { A Mere Stack Language
-
- {renderExamples()} -
diff --git a/src/Editor.module.css b/src/Editor.module.css index 2116903..e0bb076 100644 --- a/src/Editor.module.css +++ b/src/Editor.module.css @@ -5,3 +5,15 @@ .error { color: var(--red) } + +.examples { + margin-bottom: 20px; +} + +:global(.ace_gutter) { + z-index: 0; +} + +:global(#react-select-3-listbox) { + color: var(--dark-grey); +} 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 ( +