bw-hspc-contest-env/extension/bwcontest/webviews/components/ProblemPanel.svelte

181 lines
4.1 KiB
Svelte
Raw Normal View History

2023-05-07 11:01:27 -04:00
<script lang="ts">
2023-10-15 18:35:49 -04:00
import { onMount } from 'svelte';
2023-10-16 13:11:54 -04:00
import type { WebviewMessageType, MessageType, ProblemData } from '../../src/problemPanel';
2023-10-15 18:35:49 -04:00
2023-10-16 13:11:54 -04:00
function postMessage(message: MessageType) {
2023-10-15 18:35:49 -04:00
vscode.postMessage(message);
}
2023-10-16 13:11:54 -04:00
// let savedInputs: Map<number, { input: string; output: string }> = new Map();
2023-10-15 18:35:49 -04:00
2023-10-16 13:11:54 -04:00
let activeProblemIndex = 0;
2023-10-15 18:35:49 -04:00
let problemData: ProblemData | undefined;
2023-10-16 13:11:54 -04:00
let sampleInputValue: string;
let outputValue: string;
2023-10-15 18:35:49 -04:00
let running = false;
$: if (problemData && problemData.length !== 0) {
2023-10-16 13:11:54 -04:00
activeProblemIndex = 0;
2023-10-15 18:35:49 -04:00
}
function resetInput() {
2023-10-16 13:11:54 -04:00
if (problemData) {
sampleInputValue = problemData[activeProblemIndex].sampleInput;
} else {
sampleInputValue = '';
}
2023-10-15 18:35:49 -04:00
}
function onRun() {
2023-10-16 15:32:26 -04:00
if (problemData !== undefined) {
postMessage({
msg: 'onRun',
data: { input: sampleInputValue, problemId: problemData[activeProblemIndex].id }
});
}
2023-10-15 18:35:49 -04:00
}
function updateTextBoxes() {
2023-10-16 13:11:54 -04:00
// 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;
2023-10-15 18:35:49 -04:00
}
2023-10-16 13:11:54 -04:00
outputValue = '[Run to get output]';
// }
2023-10-15 18:35:49 -04:00
}
function onSubmit() {
2023-10-17 12:50:13 -04:00
if (problemData !== undefined) {
postMessage({ msg: 'onSubmit', data: { problemId: problemData[activeProblemIndex].id } });
}
2023-10-15 18:35:49 -04:00
}
function onKill() {
2023-10-16 15:32:26 -04:00
postMessage({ msg: 'onKill' });
2023-10-15 18:35:49 -04:00
}
2023-10-16 13:11:54 -04:00
onMount(() => {
postMessage({ msg: 'onRequestProblemData' });
});
2023-10-15 18:35:49 -04:00
window.addEventListener('message', async (event) => {
2023-10-16 13:11:54 -04:00
const m = (event as MessageEvent).data as WebviewMessageType;
if (m.msg === 'onProblemData') {
problemData = m.data;
updateTextBoxes();
2023-10-16 15:32:26 -04:00
} else if (m.msg === 'onRunning') {
running = true;
} else if (m.msg === 'onRunningDone') {
running = false;
} else if (m.msg === 'onRunningOutput') {
outputValue = m.data;
2023-10-15 18:35:49 -04:00
}
});
2023-05-07 11:01:27 -04:00
</script>
<h1>Test & Submit Problems</h1>
{#if problemData}
2023-10-15 18:35:49 -04:00
<div class="tab-container">
2023-10-16 13:11:54 -04:00
{#each problemData as problem, i}
2023-10-15 18:35:49 -04:00
<button
on:click={() => {
if (!running) {
2023-10-16 13:11:54 -04:00
// savedInputs.set(activeProblem.id, {
// input: sampleInputText.value,
// output: outputText.value
// });
activeProblemIndex = i;
2023-10-15 18:35:49 -04:00
updateTextBoxes();
}
}}
id={`problem_${problem.id}`}
type="button"
2023-10-16 13:11:54 -04:00
class={'tab ' + (activeProblemIndex === i ? 'active' : '')}>{problem.name}</button
2023-10-15 18:35:49 -04:00
>
{/each}
</div>
2023-05-07 11:01:27 -04:00
{/if}
2023-10-16 13:11:54 -04:00
{#if problemData !== undefined}
<h2>{problemData[activeProblemIndex].name}</h2>
2023-10-15 18:35:49 -04:00
<div style="display:flex">
<div style="flex:1; margin-right:20px">
<h3>Sample Input (You can edit this!)</h3>
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
<textarea class="inputOutputArea" bind:value={sampleInputValue} />
2023-10-15 18:35:49 -04:00
<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>
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
<textarea class="inputOutputArea" bind:value={outputValue} readonly />
2023-10-15 18:35:49 -04:00
{#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>
2023-05-07 11:01:27 -04:00
{/if}
<style>
2023-10-15 18:35:49 -04:00
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;
}
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
.inputOutputArea {
font-family: monospace;
}
2023-10-15 18:35:49 -04:00
@keyframes rotation {
0% {
transform: rotate(0deg);
}
100% {
transform: rotate(360deg);
}
}
</style>