import * as React from "react"; import { KEY } from "../../../utils/helpers/keyCodes"; import { CodingContract, CodingContractType, CodingContractTypes } from "../../CodingContracts"; import { ClickableTag, CopyableText } from "./CopyableText"; import { PopupCloseButton } from "./PopupCloseButton"; type IProps = { c: CodingContract; popupId: string; onClose: () => void; onAttempt: (answer: string) => void; } type IState = { answer: string; } export class CodingContractPopup extends React.Component{ constructor(props: IProps) { super(props); this.state = { answer: ''}; this.setAnswer = this.setAnswer.bind(this); this.onInputKeydown = this.onInputKeydown.bind(this); } setAnswer(event: any) { this.setState({ answer: event.target.value }); } onInputKeydown(e:any){ if (e.keyCode === KEY.ENTER && e.target.value !== "") { e.preventDefault(); this.props.onAttempt(this.state.answer); } else if (e.keyCode === KEY.ESC) { e.preventDefault(); this.props.onClose(); } } render(): React.ReactNode { const contractType: CodingContractType = CodingContractTypes[this.props.c.type]; const description = []; for (const [i, value] of contractType.desc(this.props.c.data).split('\n').entries()) description.push('}}>); return (


You are attempting to solve a Coding Contract. You have {this.props.c.getMaxNumTries() - this.props.c.tries} tries remaining, after which the contract will self-destruct.


{description}


this.props.onAttempt(this.state.answer)} text={"Solve"} />
) } }