[web] Add output to review page

This commit is contained in:
orosmatthew 2023-05-09 16:51:19 -04:00
parent bd91cb7044
commit 2f06247f6d
5 changed files with 33 additions and 10 deletions

3
web/src/lib/util.ts Normal file
View File

@ -0,0 +1,3 @@
export function stretchTextarea(textarea: HTMLTextAreaElement) {
textarea.style.height = textarea.scrollHeight + 'px';
}

View File

@ -17,7 +17,7 @@ export const load = (async ({ params }) => {
throw error(500, 'Invalid problem'); throw error(500, 'Invalid problem');
} }
return { diff: submission.diff, submissionId: submission.id }; return { diff: submission.diff, submissionId: submission.id, output: submission.actualOutput };
}) satisfies PageServerLoad; }) satisfies PageServerLoad;
export const actions = { export const actions = {

View File

@ -5,6 +5,7 @@
import type { Actions, PageData } from './$types'; import type { Actions, PageData } from './$types';
import { enhance } from '$app/forms'; import { enhance } from '$app/forms';
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { stretchTextarea } from '$lib/util';
export let data: PageData; export let data: PageData;
export let form: Actions; export let form: Actions;
@ -52,10 +53,10 @@
</script> </script>
<svelte:head> <svelte:head>
<title>Diff</title> <title>Review Submission</title>
</svelte:head> </svelte:head>
<h1 style="text-align:center" class="mb-4">Diff</h1> <h1 style="text-align:center" class="mb-4">Review Submission</h1>
{#if form && !form.success} {#if form && !form.success}
<div class="alert alert-danger">Submission was not successful</div> <div class="alert alert-danger">Submission was not successful</div>
@ -63,11 +64,17 @@
<div class="alert alert-success">Success!</div> <div class="alert alert-success">Success!</div>
{/if} {/if}
<div class="col"> <div class="mb-3 col">
<a href="/admin/reviews" class="btn btn-outline-primary">All Reviews</a> <a href="/admin/reviews" class="btn btn-outline-primary">All Reviews</a>
<a href={`/admin/submissions/${data.submissionId.toString()}`} class="btn btn-outline-primary">Go to Submission</a> <a href={`/admin/submissions/${data.submissionId.toString()}`} class="btn btn-outline-primary"
>Go to Submission</a
>
</div> </div>
<h3>Output</h3>
<textarea use:stretchTextarea class="mb-3 form-control" disabled>{data.output}</textarea>
<h3>Diff</h3>
<div class="mt-3" id="diff" /> <div class="mt-3" id="diff" />
<form method="POST" action="?/submit" use:enhance> <form method="POST" action="?/submit" use:enhance>

View File

@ -1,6 +1,7 @@
<script lang="ts"> <script lang="ts">
import { goto } from '$app/navigation'; import { goto } from '$app/navigation';
import { page } from '$app/stores'; import { page } from '$app/stores';
import { stretchTextarea } from '$lib/util';
import type { Actions, PageData } from './$types'; import type { Actions, PageData } from './$types';
let editing = false; let editing = false;
@ -9,10 +10,6 @@
export let data: PageData; export let data: PageData;
export let form: Actions; export let form: Actions;
function stretchTextarea(textarea: HTMLTextAreaElement) {
textarea.style.height = textarea.scrollHeight + 'px';
}
async function deleteProblem() { async function deleteProblem() {
const sure = confirm('Are you sure?'); const sure = confirm('Are you sure?');
if (!sure) { if (!sure) {

View File

@ -13,7 +13,10 @@ export const POST = (async ({ params, request }) => {
const sessionToken = params.session; const sessionToken = params.session;
const activeTeam = await db.activeTeam.findUnique({ const activeTeam = await db.activeTeam.findUnique({
where: { sessionToken: sessionToken }, where: { sessionToken: sessionToken },
include: { contest: { include: { problems: { select: { id: true } } } } } include: {
contest: { include: { problems: { select: { id: true } } } },
team: { include: { submissions: true } }
}
}); });
if (!activeTeam) { if (!activeTeam) {
throw error(400); throw error(400);
@ -31,6 +34,19 @@ export const POST = (async ({ params, request }) => {
throw error(400); throw error(400);
} }
// Make sure no submission is currently marked correct
const correctSubmissions = activeTeam.team.submissions.filter((submission) => {
return (
submission.contestId === activeTeam.contestId &&
submission.state === 'Correct' &&
submission.problemId === data.data.problemId
);
}).length;
if (correctSubmissions !== 0) {
return json({ success: false, message: 'Already submitted correct submission' });
}
await db.submission.create({ await db.submission.create({
data: { data: {
state: SubmissionState.Queued, state: SubmissionState.Queued,