import React from 'react';
import { sortBy } from 'lodash';
import request from 'vj/utils/request';
export default class ObjectiveContainer extends React.PureComponent {
constructor(args) {
super(args);
this.state = {};
this.onChange = this.onChange.bind(this);
this.onSubmit = this.onSubmit.bind(this);
}
onChange(ev) {
this.setState({ [ev.target.name]: ev.target.value });
}
onSubmit(ev) {
ev.preventDefault();
const entries = sortBy(Object.entries(this.state).map((i) => [+i[0], i[1]]));
const total = entries[entries.length - 1][0];
const ans = new Array(total).fill('');
entries.forEach((i) => ans[i[0]] = i[1]); // eslint-disable-line
request
.post(this.props.target, {
lang: '_',
code: ans.join('\n'),
})
.then((res) => {
window.location.href = res.url;
})
.catch((e) => {
Notification.error(e.message);
});
}
Textbox(args, name) {
return (
);
}
Radio(args, name) {
return (
<>
{name + 1}. {args.desc.split('\n').map((i, index) => {
if (index) return <>
{i}>;
return i;
})}
{args.choices.map((i) => (
))}
>
);
}
render() {
return (