import React from 'react'; import { connect } from 'react-redux'; import InputRange from 'react-input-range'; import AutosizeInput from 'react-input-autosize'; import screenfull from 'screenfull'; import FontAwesomeIcon from '@fortawesome/react-fontawesome'; import faAngleRight from '@fortawesome/fontawesome-free-solid/faAngleRight'; import faCaretDown from '@fortawesome/fontawesome-free-solid/faCaretDown'; import faCaretRight from '@fortawesome/fontawesome-free-solid/faCaretRight'; import faPlay from '@fortawesome/fontawesome-free-solid/faPlay'; import faChevronLeft from '@fortawesome/fontawesome-free-solid/faChevronLeft'; import faPause from '@fortawesome/fontawesome-free-solid/faPause'; import faExpandArrowsAlt from '@fortawesome/fontawesome-free-solid/faExpandArrowsAlt'; import faGithub from '@fortawesome/fontawesome-free-brands/faGithub'; import faTrashAlt from '@fortawesome/fontawesome-free-solid/faTrashAlt'; import faSave from '@fortawesome/fontawesome-free-solid/faSave'; import faShare from '@fortawesome/fontawesome-free-solid/faShare'; import faStar from '@fortawesome/fontawesome-free-solid/faStar'; import { GitHubApi } from '/apis'; import { classes } from '/common/util'; import { actions } from '/reducers'; import { languages } from '/common/config'; import { Button, Ellipsis, ListItem } from '/components'; import { tracerManager } from '/core'; import styles from './stylesheet.scss'; import Promise from 'bluebird'; import { withRouter } from 'react-router-dom'; @withRouter @connect(({ current, env }) => ({ current, env }), actions) class Header extends React.Component { constructor(props) { super(props); const { interval, paused, started } = tracerManager; this.state = { interval, paused, started, profile: { avatar_url: null, login: null, }, }; } componentDidMount() { const { signedIn } = this.props.env; if (signedIn) { GitHubApi.getProfile() .then(result => { const { avatar_url, login } = result; const profile = { avatar_url, login }; this.setState({ profile }); }); } tracerManager.setOnUpdateStatus(update => this.setState(update)); } componentWillUnmount() { tracerManager.setOnUpdateStatus(null); } handleClickFullScreen() { if (screenfull.enabled) { if (screenfull.isFullscreen) { screenfull.exit(); } else { screenfull.request(); } } } handleChangeTitle(e) { const { value } = e.target; this.props.renameScratchPaper(value); } saveGist() { const { gistId, titles, files } = this.props.current; const gist = { description: titles[1], files: { 'algorithm-visualizer': { content: 'https://algorithm-visualizer.org/', }, }, }; files.forEach(file => { gist.files[file.name] = { content: file.content, }; }); const savePromise = gistId === 'new' ? GitHubApi.createGist(gist) : GitHubApi.editGist(gistId, gist); savePromise.then(data => this.props.saveScratchPaper(data.id)).then(this.props.loadScratchPapers); } deleteGist() { const { gistId } = this.props.current; const deletePromise = gistId === 'new' ? Promise.resolve() : GitHubApi.deleteGist(gistId); deletePromise.then(() => this.props.loadAlgorithm({})).then(this.props.loadScratchPapers); } render() { const { interval, paused, started, profile } = this.state; const { className, onClickTitleBar, navigatorOpened, onAction } = this.props; const { gistId, titles, saved } = this.props.current; const { signedIn, ext } = this.props.env; return (
{ signedIn ? : }
{ started ? ( ) : ( ) } { paused ? ( ) : ( ) }
Speed tracerManager.setInterval(interval)} />
); } } export default Header;