Skip to content

Commit e7d7c10

Browse files
committed
Fix minor bugs
1 parent 0ee0629 commit e7d7c10

File tree

7 files changed

+41
-14
lines changed

7 files changed

+41
-14
lines changed

src/frontend/components/App/index.jsx

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class App extends React.Component {
3636
workspaceWeights: [1, 2, 2],
3737
editorTabIndex: -1,
3838
};
39+
40+
this.codeEditorRef = React.createRef();
3941
}
4042

4143
componentDidMount() {
@@ -141,7 +143,7 @@ class App extends React.Component {
141143
contributors: undefined,
142144
}, {
143145
name: `code.${ext}`,
144-
content: language ? language.skeleton : '',
146+
content: language.skeleton,
145147
contributors: undefined,
146148
}],
147149
});
@@ -168,6 +170,7 @@ class App extends React.Component {
168170

169171
handleChangeWorkspaceWeights(workspaceWeights) {
170172
this.setState({ workspaceWeights });
173+
this.codeEditorRef.current.getWrappedInstance().handleResize();
171174
}
172175

173176
handleChangeEditorTabIndex(editorTabIndex) {
@@ -178,13 +181,15 @@ class App extends React.Component {
178181
}
179182

180183
handleAddFile() {
184+
const { ext } = this.props.env;
181185
const { files } = this.props.current;
182-
let name = 'untitled';
186+
let name = `code.${ext}`;
183187
let count = 0;
184-
while (files.some(file => file.name === name)) name = `untitled-${++count}`;
188+
while (files.some(file => file.name === name)) name = `code-${++count}.${ext}`;
189+
const language = languages.find(language => language.ext === ext);
185190
this.props.addFile({
186191
name,
187-
content: '',
192+
content: language.skeleton,
188193
contributors: undefined,
189194
});
190195
}
@@ -258,7 +263,7 @@ class App extends React.Component {
258263
<VisualizationViewer className={styles.visualization_viewer} />
259264
<TabContainer className={styles.editor_tab_container} titles={editorTitles} tabIndex={editorTabIndex}
260265
onChangeTabIndex={tabIndex => this.handleChangeEditorTabIndex(tabIndex)}>
261-
<CodeEditor file={file} onClickDelete={() => this.handleDeleteFile()} />
266+
<CodeEditor ref={this.codeEditorRef} file={file} onClickDelete={() => this.handleDeleteFile()} />
262267
</TabContainer>
263268
</ResizableContainer>
264269
<ToastContainer className={styles.toast_container} />

src/frontend/components/Button/index.jsx

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,10 @@ class Button extends React.Component {
1919
}
2020

2121
componentWillUnmount() {
22-
if (this.timeout) window.clearTimeout(this.timeout);
22+
if (this.timeout) {
23+
window.clearTimeout(this.timeout);
24+
this.timeout = undefined;
25+
}
2326
}
2427

2528
render() {
@@ -31,13 +34,22 @@ class Button extends React.Component {
3134
className = classes(styles.confirming, className);
3235
icon = faExclamationCircle;
3336
children = <Ellipsis key="text">Click to Confirm</Ellipsis>;
37+
const onClickOriginal = onClick;
38+
onClick = () => {
39+
if (onClickOriginal) onClickOriginal();
40+
if (this.timeout) {
41+
window.clearTimeout(this.timeout);
42+
this.timeout = undefined;
43+
this.setState({ confirming: false });
44+
}
45+
};
3446
} else {
3547
to = null;
3648
href = null;
3749
onClick = () => {
3850
this.setState({ confirming: true });
3951
this.timeout = window.setTimeout(() => {
40-
this.timeout = null;
52+
this.timeout = undefined;
4153
this.setState({ confirming: false });
4254
}, 2000);
4355
};

src/frontend/components/CodeEditor/index.jsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,24 @@ import { languages } from '/common/config';
1717
import { Button, Ellipsis } from '/components';
1818
import styles from './stylesheet.scss';
1919

20-
@connect(({ current, env, player }) => ({ current, env, player }), actions)
20+
@connect(({ current, env, player }) => ({ current, env, player }), actions, null, { withRef: true })
2121
class CodeEditor extends React.Component {
22+
constructor(props) {
23+
super(props);
24+
25+
this.aceEditorRef = React.createRef();
26+
}
27+
2228
handleChangeCode(code) {
2329
const { file } = this.props;
2430
this.props.modifyFile({ ...file, content: code });
2531
if (extension(file.name) === 'md') this.props.shouldBuild();
2632
}
2733

34+
handleResize() {
35+
this.aceEditorRef.current.editor.resize();
36+
}
37+
2838
render() {
2939
const { className, file, onClickDelete } = this.props;
3040
const { user } = this.props.env;
@@ -40,6 +50,7 @@ class CodeEditor extends React.Component {
4050
<div className={classes(styles.code_editor, className)}>
4151
<AceEditor
4252
className={styles.ace_editor}
53+
ref={this.aceEditorRef}
4354
mode={mode}
4455
theme="tomorrow_night_eighties"
4556
name="code_editor"
@@ -74,7 +85,7 @@ class CodeEditor extends React.Component {
7485
</Button>
7586
</div>
7687
</div>
77-
</div> // TODO: need resizing when parent resizes
88+
</div>
7889
);
7990
}
8091
}

src/frontend/components/Header/index.jsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,6 @@ class Header extends React.Component {
6262
.then(algorithm => this.props.setCurrent(categoryKey, algorithmKey, algorithm.gistId, algorithm.titles, algorithm.files))
6363
.then(this.props.loadScratchPapers)
6464
.catch(this.props.showErrorToast);
65-
// TODO: create a new gist in case of permission error
6665
}
6766

6867
deleteGist() {

src/frontend/components/Player/index.jsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ class Player extends React.Component {
103103

104104
pause() {
105105
if (this.timer) {
106-
window.clearInterval(this.timer);
107-
this.timer = null;
106+
window.clearTimeout(this.timer);
107+
this.timer = undefined;
108108
this.setState({ playing: false });
109109
}
110110
}

src/frontend/core/renderers/MarkdownRenderer/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MarkdownRenderer extends Renderer {
2222
} else {
2323
newSrc = src;
2424
}
25-
return <img src={newSrc} {...rest} />;
25+
return <img src={newSrc} style={{ maxWidth: '100%' }} {...rest} />;
2626
};
2727

2828
return (

src/frontend/reducers/current.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ const getNextState = (state, files) => ({
4040
lastTitles: [],
4141
lastFiles: [],
4242
}),
43-
files: files.map(file => ({ ...file, contributors: [] })),
43+
files: files.map(file => ({ ...file, contributors: undefined })),
4444
});
4545

4646
export default handleActions({

0 commit comments

Comments
 (0)