import React from 'react'; import verify from '../verifySentence'; import { convertToTeX, convertToEG, wrapVarsTeX } from '../converters'; // KATEX import 'katex/dist/katex.min.css'; import TeX from '@matejmazur/react-katex'; import './CreateNew.scss'; class CreateNew extends React.Component { constructor(props) { super(props); this.state = { premises: [ '' ], conclusion: '' }; this.handleChange.bind(this) this.removePremise.bind(this) this.verify = this.verify.bind(this) this.create = this.create.bind(this) this.filename = React.createRef() } componentDidMount() { } handleChange(e, i) { if (i != null) { let { premises } = this.state; premises[i] = e.target.value; this.setState({ premises: premises }) } else this.setState({ conclusion: e.target.value }) } removePremise(index) { let { premises } = this.state; premises.splice(index, 1); this.setState({ premises: premises }) } verify() { let { premises, conclusion } = this.state; for (let i in premises) { if (premises[i] === '' || !premises[i]) return false; } if (conclusion === '' || !conclusion) return false; return true; } create() { let { useFitchNotation } = this.props; if (this.verify()) { let { premises, conclusion } = this.state; for (let i in premises) { premises[i] = useFitchNotation ? convertToEG(premises[i]) : wrapVarsTeX(premises[i]) } conclusion = useFitchNotation ? convertToEG(conclusion) : wrapVarsTeX(conclusion) this.props.setupFunc(this.filename.current.value, { premises, conclusion, steps: [] }) } } getFormulaCell(formula, i) { let tex, eg if (verify(formula)) { tex = convertToTeX(formula); if (this.props.useFitchNotation) eg = convertToEG(formula); else { eg = convertToEG(formula); } } let closeBtn =
| Formula | {this.props.useFitchNotation &&TeX notation | }EG notation | |
| this.setState({ premises: premises.concat(['']) }) }> Add New Premise | {this.props.useFitchNotation &&} |