feat: add assessment, privacy and support flows

This commit is contained in:
TakuyaYagam1 committed 2026-10-08 08:08:25 +03:00
1 parent ee3738ee73
commit e4f24fa202
339 files changed
+56454 -1126

No files matched your search

@@ -0,0 +1,181 @@
.form {
display: grid;
gap: var(--space-4);
min-width: 0;
}
.fields,
.code-lines {
display: grid;
gap: var(--space-3);
min-width: 0;
margin: 0;
padding: var(--space-4);
border: var(--line-thin) solid var(--color-divider);
border-radius: var(--radius-m);
}
.legend,
.code-lines legend {
padding: 0 var(--space-2);
font-weight: var(--font-weight-bold);
}
.options,
.practice {
display: grid;
gap: var(--space-3);
min-width: 0;
}
.option,
.code-line {
display: flex;
align-items: flex-start;
gap: var(--space-3);
min-width: 0;
padding: var(--space-3);
border: var(--line-thin) solid var(--color-border-strong);
border-radius: var(--radius-s);
cursor: pointer;
}
.option input,
.code-line input {
flex: 0 0 auto;
width: 1.2rem;
height: 1.2rem;
margin-block-start: 0.15rem;
accent-color: var(--color-accent);
}
.field {
display: grid;
gap: var(--space-2);
min-width: 0;
font-weight: var(--font-weight-bold);
}
.field input,
.field select,
.field textarea {
width: 100%;
min-width: 0;
padding: var(--space-3);
border: var(--line-thin) solid var(--color-border-strong);
border-radius: var(--radius-s);
color: var(--color-text);
background: var(--color-surface);
font: inherit;
font-weight: var(--font-weight-regular);
}
.field textarea {
resize: vertical;
font-family: var(--font-mono);
line-height: var(--line-height-body);
overflow-wrap: anywhere;
}
.field :is(input, select, textarea):focus-visible,
.option input:focus-visible,
.code-line input:focus-visible {
outline: var(--line-strong) solid var(--color-accent);
outline-offset: 2px;
}
.hint {
margin: 0;
color: var(--color-text-secondary);
font-size: var(--font-size-s);
font-weight: var(--font-weight-regular);
}
.order {
display: grid;
gap: var(--space-3);
margin: 0;
padding: 0;
list-style: none;
}
.order-item {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
gap: var(--space-3);
min-width: 0;
padding: var(--space-3);
border: var(--line-thin) solid var(--color-border-strong);
border-radius: var(--radius-s);
}
.order-actions,
.actions {
display: flex;
flex-wrap: wrap;
gap: var(--space-2);
align-items: center;
}
.code-lines {
padding-inline: var(--space-3);
}
.code-line {
align-items: baseline;
font-family: var(--font-mono);
overflow-wrap: anywhere;
}
.line-number {
flex: 0 0 2.5rem;
color: var(--color-text-secondary);
text-align: end;
user-select: none;
}
.code-line code {
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.examples {
display: grid;
gap: var(--space-2);
min-width: 0;
padding: var(--space-3);
background: var(--color-canvas);
border-radius: var(--radius-s);
}
.examples h3,
.examples p {
margin: 0;
}
.examples pre {
max-width: 100%;
margin: var(--space-1) 0 var(--space-3);
padding: var(--space-2);
overflow-x: auto;
background: var(--color-surface);
white-space: pre-wrap;
overflow-wrap: anywhere;
}
.error {
margin: 0;
color: var(--color-danger);
}
@media (width < 42rem) {
.fields {
padding: var(--space-3);
}
.order-item {
align-items: flex-start;
}
}
@@ -0,0 +1,281 @@
import { useState, type FormEvent } from "react";
import type { AssessmentItem } from "../../../shared/api/schemas";
import { Button } from "../../../shared/ui";
import { emptyAnswerDraft, type AnswerDraft } from "../model/answer-draft";
import styles from "./answer-form.module.css";
type AnswerFormProps = {
item: AssessmentItem;
isSaving: boolean;
retryable: boolean;
errorMessage: string | null;
onSubmit: (draft: AnswerDraft) => void;
onRetry: () => void;
};
export function AnswerForm({
item,
isSaving,
retryable,
errorMessage,
onSubmit,
onRetry,
}: AnswerFormProps) {
const [draft, setDraft] = useState<AnswerDraft>(() => emptyAnswerDraft(item));
const frozen = isSaving || retryable;
function submit(event: FormEvent<HTMLFormElement>) {
event.preventDefault();
if (frozen) return;
onSubmit(draft);
}
return (
<form className={styles.form} onSubmit={submit}>
<fieldset className={styles.fields} disabled={frozen}>
<legend className={styles.legend}>Ваш ответ</legend>
<AnswerFields item={item} draft={draft} setDraft={setDraft} />
</fieldset>
{errorMessage ? (
<p className={styles.error} role="alert">
{errorMessage}
</p>
) : null}
<div className={styles.actions}>
{retryable ? (
<Button isBusy={isSaving} onClick={onRetry}>
Повторить отправку того же ответа
</Button>
) : (
<Button type="submit" isBusy={isSaving}>
{isSaving ? "Сохраняем ответ..." : "Отправить ответ"}
</Button>
)}
</div>
</form>
);
}
type AnswerFieldsProps = {
item: AssessmentItem;
draft: AnswerDraft;
setDraft: (draft: AnswerDraft) => void;
};
function AnswerFields({ item, draft, setDraft }: AnswerFieldsProps) {
const content = item.content;
switch (content.format) {
case "choice": {
const selected = draft.format === "choice" ? draft.optionIds : [];
return (
<div className={styles.options}>
{content.options.map((option) => {
const checked = selected.includes(option.id);
return (
<label className={styles.option} key={option.id}>
<input
type={content.multiple ? "checkbox" : "radio"}
name={`answer-${item.id}`}
value={option.id}
checked={checked}
onChange={() => {
const optionIds = content.multiple
? checked
? selected.filter((id) => id !== option.id)
: [...selected, option.id]
: [option.id];
setDraft({ format: "choice", optionIds });
}}
/>
<span>{option.text}</span>
</label>
);
})}
</div>
);
}
case "number":
return (
<label className={styles.field}>
<span>Числовой ответ{content.unit ? `, ${content.unit}` : ""}</span>
<input
autoComplete="off"
inputMode="decimal"
maxLength={64}
name="number-answer"
type="text"
value={draft.format === "number" ? draft.value : ""}
onChange={(event) => setDraft({ format: "number", value: event.currentTarget.value })}
/>
<span className={styles.hint}>
Десятичный разделитель - точка. Введенное число отправляется без округления.
</span>
</label>
);
case "string":
return (
<label className={styles.field}>
<span>Краткий ответ</span>
<input
autoComplete="off"
maxLength={content.max_length}
name="text-answer"
type="text"
value={draft.format === "string" ? draft.value : ""}
onChange={(event) => setDraft({ format: "string", value: event.currentTarget.value })}
/>
<span className={styles.hint}>Не более {content.max_length} символов.</span>
</label>
);
case "order": {
const ids =
draft.format === "order" ? draft.elementIds : content.elements.map(({ id }) => id);
const options = new Map(content.elements.map((element) => [element.id, element.text]));
function move(index: number, offset: -1 | 1) {
const nextIndex = index + offset;
if (nextIndex < 0 || nextIndex >= ids.length) return;
const next = [...ids];
[next[index], next[nextIndex]] = [next[nextIndex] as string, next[index] as string];
setDraft({ format: "order", elementIds: next });
}
return (
<ol className={styles.order} aria-label="Порядок элементов">
{ids.map((id, index) => (
<li className={styles["order-item"]} key={id}>
<span>{options.get(id)}</span>
<div className={styles["order-actions"]}>
<Button
variant="secondary"
disabled={index === 0}
aria-label={`Переместить ${options.get(id)} выше`}
onClick={() => move(index, -1)}
>
Выше
</Button>
<Button
variant="secondary"
disabled={index === ids.length - 1}
aria-label={`Переместить ${options.get(id)} ниже`}
onClick={() => move(index, 1)}
>
Ниже
</Button>
</div>
</li>
))}
</ol>
);
}
case "find_error": {
const selected = draft.format === "find_error" ? draft.lineNumbers : [];
return (
<fieldset className={styles["code-lines"]}>
<legend>Отметьте строки с ошибкой</legend>
{content.lines.map((line) => (
<label className={styles["code-line"]} key={line.number}>
<input
type="checkbox"
checked={selected.includes(line.number)}
onChange={(event) => {
const lineNumbers = event.currentTarget.checked
? [...selected, line.number]
: selected.filter((number) => number !== line.number);
setDraft({ format: "find_error", lineNumbers });
}}
/>
<span className={styles["line-number"]}>{line.number}</span>
<code>{line.text}</code>
</label>
))}
<p className={styles.hint}>Можно отметить не более {content.max_selections} строк.</p>
</fieldset>
);
}
case "configuration":
return (
<label className={styles.field}>
<span>Конфигурация ({content.syntax})</span>
<textarea
autoComplete="off"
maxLength={content.max_length}
name="configuration-answer"
rows={12}
spellCheck={false}
value={draft.format === "configuration" ? draft.value : content.initial_config}
onChange={(event) =>
setDraft({ format: "configuration", value: event.currentTarget.value })
}
/>
<span className={styles.hint}>Не более {content.max_length} символов.</span>
</label>
);
case "practice":
return (
<div className={styles.practice}>
{content.languages.length > 1 ? (
<label className={styles.field}>
<span>Язык решения</span>
<select
value={draft.format === "practice" ? (draft.language ?? "") : ""}
onChange={(event) =>
setDraft({
format: "practice",
language:
event.currentTarget.value === ""
? null
: (event.currentTarget.value as "go" | "python"),
sourceCode: draft.format === "practice" ? draft.sourceCode : "",
})
}
>
<option value="">Выберите язык</option>
{content.languages.map((language) => (
<option key={language} value={language}>
{language === "go" ? "Go" : "Python"}
</option>
))}
</select>
</label>
) : content.languages[0] ? (
<p className={styles.hint}>
Язык решения: {content.languages[0] === "go" ? "Go" : "Python"}.
</p>
) : null}
{content.public_examples.length > 0 ? (
<div className={styles.examples}>
<h3>Примеры</h3>
{content.public_examples.map((example, index) => (
<div key={`${index}-${example.input}`}>
<p>Входные данные</p>
<pre>{example.input}</pre>
<p>Ожидаемый вывод</p>
<pre>{example.expected_output}</pre>
</div>
))}
</div>
) : null}
<label className={styles.field}>
<span>Код решения</span>
<textarea
autoComplete="off"
maxLength={content.max_source_length}
name="practice-answer"
rows={16}
spellCheck={false}
value={draft.format === "practice" ? draft.sourceCode : ""}
onChange={(event) =>
setDraft({
format: "practice",
language:
draft.format === "practice" ? draft.language : (content.languages[0] ?? null),
sourceCode: event.currentTarget.value,
})
}
/>
<span className={styles.hint}>Не более {content.max_source_length} символов.</span>
</label>
</div>
);
}
}