import React, { useState } 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; }; export function CodingContractPopup(props: IProps): React.ReactElement { const [answer, setAnswer] = useState(""); function onChange(event: React.ChangeEvent): void { setAnswer(event.target.value); } function onKeyDown(event: React.KeyboardEvent): void { // React just won't cooperate on this one. // "React.KeyboardEvent" seems like the right type but // whatever ... const value = (event.target as any).value; if (event.keyCode === KEY.ENTER && value !== "") { event.preventDefault(); props.onAttempt(answer); } else if (event.keyCode === KEY.ESC) { event.preventDefault(); props.onClose(); } } const contractType: CodingContractType = CodingContractTypes[props.c.type]; const description = []; for (const [i, value] of contractType.desc(props.c.data).split("\n").entries()) description.push(" }}>); return (


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


{description}


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