bw-hspc-contest-env/extension/bwcontest/webviews/components/ProblemPanel.svelte
David Poeschl 4a3ff56e7a
VSCode Extension: Sidebar UI showing team's submissions, automatically updating and showing alerts as submissions are judged (#14)
* Add an Output Panel channel named "BWContest Log"

* Allow client logout when no contest

And make login/logout error messages clearer

* Show contest name & team name in Code extension side panel

* submission icons for sidebar panel

* Start VSCode extension "onStartupFinished"

instead of waiting for Sidebar to be opened

* VSCode: Sidebar UI for up-to-date problem/submissions status

- VSCode: poll API every 30 seconds to get contest metadata and all submission metadata for the logged in team
- The Sidebar now shows all problems in the contest, along with their submissions and overall status, which automatically updates as submissions are submitted & judged
- Web: "contestState" API to get all info for an activeTeam via their token
- Update submit API to return the submission id, allowing the VSCode UI to immediately render it as Pending without waiting for a polling cycle
-

* Add "Compilation Failed" message to submissions that fail to build

* Contest Import - Option to create repos & immediately activate the imported contest

Useful for testing with old contests (including the submissions)

* Test/Submit panel, use fixed-width font in input/output areas

* Fix build error for 'pluralize'

* Clear all state & halt polling loops on logout, restart them on login

* Improve the debug fastPolling option

- Toggleable via package.json config
- Setting the option changes the initial state as well as ability to toggle states

* Web project 'npm run format'
2024-03-05 17:50:16 -05:00

181 lines
4.1 KiB
Svelte

<script lang="ts">
import { onMount } from 'svelte';
import type { WebviewMessageType, MessageType, ProblemData } from '../../src/problemPanel';
function postMessage(message: MessageType) {
vscode.postMessage(message);
}
// let savedInputs: Map<number, { input: string; output: string }> = new Map();
let activeProblemIndex = 0;
let problemData: ProblemData | undefined;
let sampleInputValue: string;
let outputValue: string;
let running = false;
$: if (problemData && problemData.length !== 0) {
activeProblemIndex = 0;
}
function resetInput() {
if (problemData) {
sampleInputValue = problemData[activeProblemIndex].sampleInput;
} else {
sampleInputValue = '';
}
}
function onRun() {
if (problemData !== undefined) {
postMessage({
msg: 'onRun',
data: { input: sampleInputValue, problemId: problemData[activeProblemIndex].id }
});
}
}
function updateTextBoxes() {
// if (savedInputs.has(activeProblem.id)) {
// sampleInputText.value = savedInputs.get(activeProblem.id)!.input;
// outputText.value = savedInputs.get(activeProblem.id)!.output;
// } else {
if (problemData !== undefined) {
sampleInputValue = problemData[activeProblemIndex].sampleInput;
}
outputValue = '[Run to get output]';
// }
}
function onSubmit() {
if (problemData !== undefined) {
postMessage({ msg: 'onSubmit', data: { problemId: problemData[activeProblemIndex].id } });
}
}
function onKill() {
postMessage({ msg: 'onKill' });
}
onMount(() => {
postMessage({ msg: 'onRequestProblemData' });
});
window.addEventListener('message', async (event) => {
const m = (event as MessageEvent).data as WebviewMessageType;
if (m.msg === 'onProblemData') {
problemData = m.data;
updateTextBoxes();
} else if (m.msg === 'onRunning') {
running = true;
} else if (m.msg === 'onRunningDone') {
running = false;
} else if (m.msg === 'onRunningOutput') {
outputValue = m.data;
}
});
</script>
<h1>Test & Submit Problems</h1>
{#if problemData}
<div class="tab-container">
{#each problemData as problem, i}
<button
on:click={() => {
if (!running) {
// savedInputs.set(activeProblem.id, {
// input: sampleInputText.value,
// output: outputText.value
// });
activeProblemIndex = i;
updateTextBoxes();
}
}}
id={`problem_${problem.id}`}
type="button"
class={'tab ' + (activeProblemIndex === i ? 'active' : '')}>{problem.name}</button
>
{/each}
</div>
{/if}
{#if problemData !== undefined}
<h2>{problemData[activeProblemIndex].name}</h2>
<div style="display:flex">
<div style="flex:1; margin-right:20px">
<h3>Sample Input (You can edit this!)</h3>
<textarea class="inputOutputArea" bind:value={sampleInputValue} />
<button style="margin-top:5px" on:click={resetInput} type="button">Reset Input</button>
</div>
<div style="flex:1">
<div style="display:flex">
<h3 style="margin-right:5px">Output</h3>
{#if running}
<span class="loader"></span>
{/if}
</div>
<textarea class="inputOutputArea" bind:value={outputValue} readonly />
{#if !running}
<button style="margin-top:5px" on:click={onRun} type="button">Run</button>
{:else}
<button style="margin-top:5px" on:click={onKill} type="button">Stop</button>
{/if}
</div>
</div>
<button on:click={onSubmit} type="button">Submit</button>
{/if}
<style>
textarea {
resize: vertical;
height: 250px;
}
.tab-container {
display: flex;
flex-direction: row;
align-items: center;
justify-content: space-between;
height: 30px;
margin-bottom: 10px;
}
.tab {
flex: 1;
border: none;
cursor: pointer;
text-align: center;
}
.tab.active {
background-color: rgb(95, 103, 118);
}
.loader {
width: 16px;
height: 16px;
border: 3px solid #fff;
border-bottom-color: transparent;
border-radius: 50%;
display: inline-block;
box-sizing: border-box;
animation: rotation 1s linear infinite;
}
.inputOutputArea {
font-family: monospace;
}
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>