2017-11-29 15:44:51 -08:00
|
|
|
import React, { PureComponent } from 'react';
|
2017-11-09 17:10:30 -08:00
|
|
|
import PropTypes from 'prop-types';
|
2016-08-16 16:07:52 -07:00
|
|
|
import { Button, ButtonGroup, Tooltip, OverlayTrigger } from 'react-bootstrap';
|
2016-03-05 21:06:04 -08:00
|
|
|
|
2016-08-16 16:07:52 -07:00
|
|
|
const unlockWarning = (
|
|
|
|
<Tooltip id='tooltip'>
|
|
|
|
<h4>
|
|
|
|
<strong>Careful!</strong> Only run code you trust
|
|
|
|
</h4>
|
|
|
|
</Tooltip>
|
|
|
|
);
|
2016-11-08 17:26:58 -08:00
|
|
|
|
|
|
|
const propTypes = {
|
|
|
|
executeChallenge: PropTypes.func.isRequired,
|
|
|
|
helpChatRoom: PropTypes.string,
|
|
|
|
hint: PropTypes.string,
|
|
|
|
isCodeLocked: PropTypes.bool,
|
|
|
|
makeToast: PropTypes.func.isRequired,
|
|
|
|
openBugModal: PropTypes.func.isRequired,
|
|
|
|
unlockUntrustedCode: PropTypes.func.isRequired,
|
|
|
|
updateHint: PropTypes.func.isRequired
|
|
|
|
};
|
|
|
|
|
2016-06-14 18:47:43 -07:00
|
|
|
export default class ToolPanel extends PureComponent {
|
|
|
|
constructor(...props) {
|
|
|
|
super(...props);
|
|
|
|
this.makeHint = this.makeHint.bind(this);
|
2016-07-07 20:02:03 -07:00
|
|
|
this.makeReset = this.makeReset.bind(this);
|
2016-06-14 18:47:43 -07:00
|
|
|
}
|
|
|
|
makeHint() {
|
|
|
|
this.props.makeToast({
|
2016-07-08 12:06:02 -07:00
|
|
|
message: this.props.hint,
|
|
|
|
timeout: 4000
|
2016-06-14 18:47:43 -07:00
|
|
|
});
|
|
|
|
this.props.updateHint();
|
|
|
|
}
|
|
|
|
|
2016-07-07 20:02:03 -07:00
|
|
|
makeReset() {
|
|
|
|
this.props.makeToast({
|
|
|
|
message: 'This will restore your code editor to its original state.',
|
|
|
|
action: 'clear my code',
|
2017-11-09 17:10:30 -08:00
|
|
|
actionCreator: 'clickOnReset',
|
2016-07-08 12:06:02 -07:00
|
|
|
timeout: 4000
|
2016-07-07 20:02:03 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-06-14 18:47:43 -07:00
|
|
|
renderHint(hint, makeHint) {
|
|
|
|
if (!hint) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
block={ true }
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-big'
|
|
|
|
onClick={ makeHint }
|
|
|
|
>
|
2016-07-07 20:02:03 -07:00
|
|
|
Hint
|
2016-06-14 18:47:43 -07:00
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-08-16 15:59:23 -07:00
|
|
|
renderExecute(isCodeLocked, executeChallenge, unlockUntrustedCode) {
|
|
|
|
if (isCodeLocked) {
|
|
|
|
return (
|
2016-08-16 16:07:52 -07:00
|
|
|
<OverlayTrigger
|
|
|
|
overlay={ unlockWarning }
|
|
|
|
placement='right'
|
2016-08-16 15:59:23 -07:00
|
|
|
>
|
2016-08-16 16:07:52 -07:00
|
|
|
<Button
|
|
|
|
block={ true }
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-big'
|
|
|
|
onClick={ unlockUntrustedCode }
|
|
|
|
>
|
|
|
|
Code Locked. Unlock?
|
|
|
|
</Button>
|
|
|
|
</OverlayTrigger>
|
2016-08-16 15:59:23 -07:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
block={ true }
|
|
|
|
bsStyle='primary'
|
|
|
|
className='btn-big'
|
|
|
|
onClick={ executeChallenge }
|
|
|
|
>
|
|
|
|
Run tests (ctrl + enter)
|
|
|
|
</Button>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-03-05 21:06:04 -08:00
|
|
|
render() {
|
2016-07-11 17:44:50 -07:00
|
|
|
const {
|
2016-11-08 17:26:58 -08:00
|
|
|
executeChallenge,
|
|
|
|
helpChatRoom,
|
2016-07-11 17:44:50 -07:00
|
|
|
hint,
|
2016-08-16 15:59:23 -07:00
|
|
|
isCodeLocked,
|
|
|
|
openBugModal,
|
|
|
|
unlockUntrustedCode
|
2016-07-11 17:44:50 -07:00
|
|
|
} = this.props;
|
2016-03-05 21:06:04 -08:00
|
|
|
return (
|
|
|
|
<div>
|
2016-06-14 18:47:43 -07:00
|
|
|
{ this.renderHint(hint, this.makeHint) }
|
2016-08-16 15:59:23 -07:00
|
|
|
{
|
|
|
|
this.renderExecute(
|
|
|
|
isCodeLocked,
|
|
|
|
executeChallenge,
|
|
|
|
unlockUntrustedCode
|
|
|
|
)
|
|
|
|
}
|
2016-03-05 21:06:04 -08:00
|
|
|
<div className='button-spacer' />
|
|
|
|
<ButtonGroup
|
|
|
|
className='input-group'
|
2016-06-10 14:01:13 -07:00
|
|
|
justified={ true }
|
|
|
|
>
|
2016-03-05 21:06:04 -08:00
|
|
|
<Button
|
|
|
|
bsSize='large'
|
|
|
|
bsStyle='primary'
|
2016-06-10 14:01:13 -07:00
|
|
|
componentClass='label'
|
2016-07-07 20:02:03 -07:00
|
|
|
onClick={ this.makeReset }
|
2016-06-10 14:01:13 -07:00
|
|
|
>
|
2016-03-05 21:06:04 -08:00
|
|
|
Reset
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
bsSize='large'
|
|
|
|
bsStyle='primary'
|
2016-11-08 17:26:58 -08:00
|
|
|
componentClass='a'
|
|
|
|
href={ `https://gitter.im/freecodecamp/${helpChatRoom}` }
|
|
|
|
target='_blank'
|
2016-06-10 14:01:13 -07:00
|
|
|
>
|
2016-03-05 21:06:04 -08:00
|
|
|
Help
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
bsSize='large'
|
|
|
|
bsStyle='primary'
|
2016-06-10 14:01:13 -07:00
|
|
|
componentClass='label'
|
2016-07-11 21:54:55 -07:00
|
|
|
onClick={ openBugModal }
|
2016-06-10 14:01:13 -07:00
|
|
|
>
|
2016-03-05 21:06:04 -08:00
|
|
|
Bug
|
|
|
|
</Button>
|
|
|
|
</ButtonGroup>
|
|
|
|
<div className='button-spacer' />
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2016-11-08 17:26:58 -08:00
|
|
|
|
|
|
|
ToolPanel.displayName = 'ToolPanel';
|
|
|
|
ToolPanel.propTypes = propTypes;
|