Skip to content

Commit d733258

Browse files
committed
commit final changes
1 parent 6846aec commit d733258

File tree

4 files changed

+651
-40
lines changed

4 files changed

+651
-40
lines changed

packages/hedgehog-lab/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"react-monaco-editor": "^0.43.0",
2626
"react-plotly.js": "^2.4.0",
2727
"react-query": "^2.5.6",
28-
"react-resize-detector": "^6.6.4",
28+
"react-resize-detector": "^6.7.2",
2929
"worker-loader": "^2.0.0"
3030
},
3131
"devDependencies": {

packages/hedgehog-lab/src/components/Header/Header.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ const Header: React.FC<HeaderProps> = (props: HeaderProps) => {
190190
size="small"
191191
startIcon={<ShareIcon />}
192192
>
193-
Share your code
193+
Share
194194
</Button>
195195

196196
<Dialog onClose={handleClose} aria-labelledby="customized-dialog-title" open={dialogOpen}

packages/hedgehog-lab/src/components/YourCode/YourCode.tsx

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import React, { useState, Dispatch, SetStateAction } from 'react';
1+
import React, { Dispatch, SetStateAction, useState } from 'react';
22
import { Button, Card, CardContent, CardHeader } from '@material-ui/core';
3-
import MonacoEditor, { EditorDidMount } from 'react-monaco-editor';
3+
import { ControlledEditor, ControlledEditorOnChange } from '@monaco-editor/react';
44
import * as monacoEditor from 'monaco-editor/esm/vs/editor/editor.api';
5-
import ResizeObserver from 'react-resize-detector';
65
import { queryCache } from 'react-query';
6+
import ResizeObserver from 'react-resize-detector';
77

88
const COMPILE_AND_RUN_BUTTON_ID = 'compile-and-run-button-id';
99

@@ -16,10 +16,11 @@ interface YourCodeProps {
1616

1717
const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
1818
const { handleCompileAndRun, loading, setSource, source } = props;
19+
1920
const [editor, setEditor] = useState<monacoEditor.editor.IStandaloneCodeEditor | null>(null);
2021
const [monaco, setMonaco] = useState<typeof monacoEditor | null>(null);
2122

22-
const handleUploadSource = (v: string) => {
23+
const handleUploadSource: ControlledEditorOnChange = (e, v) => {
2324
setSource(v as string);
2425
};
2526

@@ -28,9 +29,9 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
2829
scrollBeyondLastLine: false
2930
};
3031

31-
const EditorDidMountHandle = (
32+
const handleEditorDidMount = (
33+
_: () => string,
3234
editor: monacoEditor.editor.IStandaloneCodeEditor,
33-
monaco: typeof monacoEditor
3435
) => {
3536
editor.addAction({
3637
id: COMPILE_AND_RUN_BUTTON_ID,
@@ -40,9 +41,7 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
4041
document.getElementById(COMPILE_AND_RUN_BUTTON_ID)?.click();
4142
}
4243
});
43-
4444
setEditor(editor);
45-
setMonaco(monaco);
4645
};
4746

4847
return (
@@ -57,8 +56,8 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
5756
color="secondary"
5857
style={{
5958
textTransform: 'none',
60-
width: 140
6159
}}
60+
size = "small"
6261
onClick={() => {
6362
// stop the web-worker
6463
queryCache.cancelQueries(['compiler']);
@@ -75,33 +74,36 @@ const YourCode: React.FC<YourCodeProps> = (props: YourCodeProps) => {
7574
id={COMPILE_AND_RUN_BUTTON_ID}
7675
variant="contained"
7776
color="primary"
77+
size = "small"
7878
onClick={(e) => handleCompileAndRun(e)}
7979
style={{
8080
textTransform: 'none'
8181
}}>
82-
Compile and run
82+
Run
8383
</Button>
8484
)}
8585
</div>
8686
}
87-
title="Your code:"
8887
/>
8988

9089
<CardContent>
91-
<div
92-
style={{
93-
height: 'calc(100vh - 160px)'
94-
}}>
90+
<ResizeObserver
91+
onResize={(width, height) => {
92+
if (editor) {
93+
editor.layout();
94+
}
95+
}}>
9596
<div
9697
style={{
97-
height: 'calc(100vh - 174px)'
98+
height: 'calc(100vh - 160px)'
9899
}}>
99-
<MonacoEditor
100+
<ControlledEditor
100101
language="javascript"
101102
value={source}
102103
onChange={handleUploadSource}
103104
options={options}
104-
editorDidMount={EditorDidMountHandle}
105+
editorDidMount={handleEditorDidMount}
106+
105107
/>
106108
</div>
107109
</ResizeObserver>

0 commit comments

Comments
 (0)