import React from 'react'; import { connect } from 'react-redux'; import AutosizeInput from 'react-input-autosize'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import faPlus from '@fortawesome/fontawesome-free-solid/faPlus'; import { classes } from 'common/util'; import { actions } from 'reducers'; import { languages } from 'common/config'; import styles from './TabContainer.module.scss'; class TabContainer extends React.Component { handleAddFile() { const { ext } = this.props.env; const { files } = this.props.current; const language = languages.find(language => language.ext === ext); const newFile = { ...language.skeleton }; let count = 0; while (files.some(file => file.name === newFile.name)) newFile.name = `code-${++count}.${ext}`; this.props.addFile(newFile); } render() { const { className, children } = this.props; const { editingFile, files } = this.props.current; return (
{ files.map((file, i) => file === editingFile ? (
this.props.setEditingFile(file)}> e.stopPropagation()} onChange={e => this.props.renameFile(file, e.target.value)}/>
) : (
this.props.setEditingFile(file)}> {file.name}
)) }
this.handleAddFile()}>
{children}
); } } export default connect(({ current, env }) => ({ current, env }), actions)( TabContainer, );