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

77 lines
1.6 KiB
Svelte
Raw Normal View History

2023-05-06 00: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, TeamData } from '../../src/SidebarProvider';
2023-05-06 00:01:27 -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-15 18:35:49 -04:00
let teamname: string;
let password: string;
2023-10-15 18:35:49 -04:00
let loggedIn = false;
2023-10-15 18:35:49 -04:00
let teamData: TeamData | undefined;
2023-10-15 18:35:49 -04:00
function onClone() {
if (teamData) {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onClone',
data: { contestId: teamData.contestId, teamId: teamData.teamId }
2023-10-15 18:35:49 -04:00
});
}
}
2023-05-06 00:01:27 -04:00
2023-10-15 18:35:49 -04:00
function onLogin() {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onLogin',
data: { teamName: teamname, password: password }
2023-10-15 18:35:49 -04:00
});
}
2023-10-15 18:35:49 -04:00
function onLogout() {
postMessage({
2023-10-16 13:11:54 -04:00
msg: 'onLogout'
2023-10-15 18:35:49 -04:00
});
}
2023-10-15 18:35:49 -04:00
function onTestAndSubmit() {
2023-10-16 13:11:54 -04:00
postMessage({ msg: 'onTestAndSubmit' });
2023-10-15 18:35:49 -04:00
}
2023-10-15 18:35:49 -04:00
onMount(() => {
2023-10-16 13:11:54 -04:00
postMessage({ msg: 'onStartup' });
2023-10-15 18:35:49 -04:00
});
2023-05-07 11:01:27 -04:00
2023-10-15 18:35:49 -04:00
window.addEventListener('message', (event) => {
2023-10-16 13:11:54 -04:00
const m = (event as MessageEvent).data as WebviewMessageType;
if (m.msg === 'onLogin') {
2023-10-15 18:35:49 -04:00
loggedIn = true;
2023-10-16 13:11:54 -04:00
teamData = m.data;
} else if (m.msg === 'onLogout') {
2023-10-15 18:35:49 -04:00
loggedIn = false;
teamData = undefined;
}
});
2023-05-06 00:01:27 -04:00
</script>
<h1>Contest</h1>
2023-10-15 18:35:49 -04:00
{#if !loggedIn}
<label for="teamname">Team Name</label>
<input bind:value={teamname} id="teamname" type="text" />
2023-05-06 00:01:27 -04:00
2023-10-15 18:35:49 -04:00
<label for="password">Password</label>
<input bind:value={password} id="password" type="password" />
2023-05-06 00:01:27 -04:00
2023-10-15 18:35:49 -04:00
<button on:click={onLogin}>Login</button>
2023-05-06 00:01:27 -04:00
{:else}
2023-10-15 18:35:49 -04:00
<button on:click={onLogout}>Logout</button>
{#if teamData}
<p>TeamID: {teamData.teamId}</p>
<p>ContestID: {teamData.contestId}</p>
<button on:click={onClone}>Clone and Open Repo</button>
<button on:click={onTestAndSubmit}>Test & Submit</button>
{/if}
{/if}