Skip to content

Commit 4213730

Browse files
glennslchenglou
authored andcommitted
Various playground fixes (#186)
* fix exampleMenu ul/li css reset * shrink header and playground toolbar when short on height * fix #123 - capture and display playground warnings
1 parent d724e3a commit 4213730

File tree

3 files changed

+74
-9
lines changed

3 files changed

+74
-9
lines changed

src/components/Header.js

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,41 @@ export default ({inverted}) => (
1010
flexDirection: 'row',
1111
justifyContent: 'space-between',
1212
alignItems: 'center',
13-
padding: '10px 10px',
13+
padding: 10,
1414
paddingLeft: '2em',
1515
// height: 100,
16+
'@media(max-height: 770px)': {
17+
paddingLeft: '1em'
18+
},
1619
'@media(max-width: 400px)': {
1720
paddingLeft: 10,
1821
height: 'auto',
19-
}
22+
},
2023
}}>
21-
<div style={{alignSelf: 'flex-start' }} >
22-
<Link to="/" style={{textDecoration: 'none', color: 'currentColor'}} >
23-
<img style={{display: 'block', width: 50, maxWidth: 50, margin: 0, border: `2px solid ${gray}`, boxSizing: 'content-box'}} src={icon} width={50} alt="Reason"/>
24+
<div style={{alignSelf: 'flex-start' }}>
25+
<Link to="/" style={styles.link}>
26+
<img css={styles.logo} src={icon} width={50} alt="Reason"/>
2427
</Link>
2528
</div>
2629
<HeaderNav />
2730
</div>
2831
)
32+
33+
const styles = {
34+
logo: {
35+
display: 'block',
36+
width: 50,
37+
maxWidth: 50,
38+
margin: 0,
39+
border: `2px solid ${gray}`,
40+
boxSizing: 'content-box',
41+
42+
'@media(max-height: 770px)': {
43+
width: 28
44+
}
45+
},
46+
link: {
47+
textDecoration: 'none',
48+
color: 'currentColor'
49+
}
50+
};

src/components/HeaderNav.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ const styles = {
5656
'@media(max-width: 550px)': {
5757
padding: '0 5px',
5858
fontSize: '.9em',
59+
},
60+
'@media(max-height: 770px)': {
61+
fontSize: '.9em',
5962
}
6063
},
6164
linkContainer: {

src/pages/try.js

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,13 +467,23 @@ export default class Try extends Component {
467467
});
468468
}
469469

470+
compile = (code) => {
471+
const _consoleError = console.error;
472+
let warning = '';
473+
console.error = (...args) => args.forEach(argument => warning += argument + `\n`);
474+
const res = JSON.parse(window.ocaml.compile(code));
475+
console.error = _consoleError;
476+
return [res, warning || null];
477+
}
478+
470479
tryCompiling = debounce((reason, ocaml) => {
471480
try {
472-
const res = JSON.parse(window.ocaml.compile(ocaml))
481+
const [res, warning] = this.compile(ocaml);
473482
if (res.js_code) {
474483
this.setState(_ => ({
475484
js: res.js_code,
476485
jsIsLatest: true,
486+
compileWarning: warning
477487
}))
478488
if (this.state.autoEvaluate) {
479489
this.evalJs(res.js_code);
@@ -483,6 +493,7 @@ export default class Try extends Component {
483493
this.errorTimerId = setTimeout(
484494
() => this.setState(_ => ({
485495
compileError: res,
496+
compileWarning: null,
486497
js: '',
487498
})),
488499
errorTimeout
@@ -492,6 +503,7 @@ export default class Try extends Component {
492503
this.errorTimerId = setTimeout(
493504
() => this.setState(_ => ({
494505
compileError: err,
506+
compileWarning: null,
495507
js: '',
496508
})),
497509
errorTimeout
@@ -500,6 +512,7 @@ export default class Try extends Component {
500512
this.setState(_ => {
501513
return {
502514
compileError: null,
515+
compileWarning: null,
503516
jsIsLatest: false,
504517
output: [],
505518
}
@@ -530,11 +543,20 @@ export default class Try extends Component {
530543
}
531544

532545
render() {
533-
const { reason, ocaml, js, reasonSyntaxError, compileError, ocamlSyntaxError, jsError } = this.state
546+
const {
547+
reason,
548+
ocaml,
549+
js,
550+
reasonSyntaxError,
551+
compileError,
552+
compileWarning,
553+
ocamlSyntaxError,
554+
jsError
555+
} = this.state;
534556
const codemirrorStyles = [
535557
styles.codemirror,
536558
isSafari && styles.codemirrorSafari,
537-
]
559+
];
538560
return (
539561
<div css={styles.container}>
540562
<Helmet>
@@ -611,6 +633,12 @@ export default class Try extends Component {
611633
: compileError.message}
612634
</div>
613635
</div>}
636+
{compileWarning &&
637+
<div css={styles.warning}>
638+
<div css={styles.errorBody}>
639+
{compileWarning}
640+
</div>
641+
</div>}
614642
</div>
615643
</div>
616644
<div css={styles.column}>
@@ -674,6 +702,10 @@ const styles = {
674702
backgroundColor: '#faa',
675703
padding: '10px 20px',
676704
},
705+
warning: {
706+
backgroundColor: '#fff8dc',
707+
padding: '10px 20px',
708+
},
677709

678710
container: {
679711
position: 'absolute',
@@ -754,7 +786,11 @@ const styles = {
754786
'&:hover, &:hover button': {
755787
color: accent,
756788
cursor: 'pointer'
757-
}
789+
},
790+
791+
'@media(max-height: 770px)': {
792+
padding: '.5em 1em',
793+
},
758794
},
759795

760796
shareButton: {
@@ -841,8 +877,12 @@ const styles = {
841877
width: '25vw',
842878
boxShadow: '1px 1px 1px rgba(0, 0, 0, .2)',
843879
borderTop: '1px solid #d6d4d4',
880+
margin: 0,
881+
padding: 0,
882+
listStyle: 'none',
844883

845884
'& li': {
885+
margin: 0,
846886
padding: '.5em 2em',
847887

848888
'&:first-child': {

0 commit comments

Comments
 (0)