[web] Auto refresh submisisons

This commit is contained in:
orosmatthew 2023-05-09 16:20:23 -04:00
parent 36a8050a4b
commit bd91cb7044
6 changed files with 61 additions and 23 deletions

View File

@ -64,6 +64,8 @@ export const actions = {
return { success: false };
}
await db.submission.deleteMany({ where: { contestId: contest.id } });
contest.teams.forEach(async (team) => {
await db.activeTeam.create({ data: { teamId: team.id, contestId: contest.id } });
});

View File

@ -1,8 +1,5 @@
import { db } from '$lib/server/prisma';
import path, { join } from 'path';
import type { Actions, PageServerLoad } from './$types';
import fs from 'fs';
import { simpleGit } from 'simple-git';
import { createRepos } from '../util';
export const load = (async () => {
@ -18,22 +15,6 @@ export const load = (async () => {
};
}) satisfies PageServerLoad;
function copyFolderSync(source: string, target: string) {
if (!fs.existsSync(target)) {
fs.mkdirSync(target);
}
fs.readdirSync(source).forEach((file) => {
const sourcePath = path.join(source, file);
const targetPath = path.join(target, file);
if (fs.lstatSync(sourcePath).isDirectory()) {
copyFolderSync(sourcePath, targetPath);
} else {
fs.copyFileSync(sourcePath, targetPath);
}
});
}
export const actions = {
create: async ({ request }) => {
const data = await request.formData();

View File

@ -1,12 +1,13 @@
import { db } from '$lib/server/prisma';
import { SubmissionState } from '@prisma/client';
import type {PageServerLoad } from './$types';
import type { PageServerLoad } from './$types';
export const load = (async () => {
const submissions = await db.submission.findMany({ where: { state: SubmissionState.InReview } });
const teams = await db.team.findMany();
const problems = await db.problem.findMany();
return {
timestamp: new Date(),
reviewList: submissions.map((row) => {
return { id: row.id, createdAt: row.createdAt };
}),
@ -18,4 +19,3 @@ export const load = (async () => {
})
};
}) satisfies PageServerLoad;

View File

@ -1,7 +1,26 @@
<script lang="ts">
import { onDestroy, onMount } from 'svelte';
import type { PageData } from './$types';
import { invalidateAll } from '$app/navigation';
export let data: PageData;
let updateInterval: ReturnType<typeof setInterval> | undefined;
let updating = false;
onMount(() => {
updateInterval = setInterval(async () => {
updating = true;
await invalidateAll();
updating = false;
}, 10000);
});
onDestroy(() => {
if (updateInterval) {
clearInterval(updateInterval);
}
});
</script>
<svelte:head>
@ -10,6 +29,13 @@
<h1 style="text-align:center" class="mb-4">Reviews</h1>
<div class="mb-3 text-end">
{#if updating}
<div class="spinner-border spinner-border-sm text-secondary" />
{/if}
<strong>Last Updated: </strong>{data.timestamp.toLocaleTimeString()}
</div>
<ul class="list-group">
{#if data.reviewList.length === 0}
<div class="alert alert-success">No Submission to Review!</div>

View File

@ -6,6 +6,7 @@ export const load = (async () => {
const problems = await db.problem.findMany();
const teams = await db.team.findMany();
return {
timestamp: new Date(),
submissions: submissions.map((row) => {
return {
id: row.id,

View File

@ -1,12 +1,30 @@
<script lang="ts">
import type { PageData } from './$types';
import { goto } from '$app/navigation';
import { goto, invalidateAll } from '$app/navigation';
import { onDestroy, onMount } from 'svelte';
export let data: PageData;
$: data.submissions.sort((a, b) => {
return b.createdAt.valueOf() - a.createdAt.valueOf();
});
let updateInterval: ReturnType<typeof setInterval> | undefined;
let updating = false;
onMount(() => {
updateInterval = setInterval(async () => {
updating = true;
await invalidateAll();
updating = false;
}, 10000);
});
onDestroy(() => {
if (updateInterval) {
clearInterval(updateInterval);
}
});
</script>
<svelte:head>
@ -15,7 +33,17 @@
<h1 style="text-align:center" class="mb-4">Submissions</h1>
<p>Rows are color coded: Red - Incorrect, Green - Correct, Yellow - In Review</p>
<div class="row">
<div class="col-8">
<p>Rows are color coded: Red - Incorrect, Green - Correct, Yellow - In Review</p>
</div>
<div class="col-4 text-end">
{#if updating}
<div class="spinner-border spinner-border-sm text-secondary" />
{/if}
<strong>Last Updated: </strong>{data.timestamp.toLocaleTimeString()}
</div>
</div>
<table class="table table-bordered table-hover">
<thead>