=priority: load heats

This commit is contained in:
Miki 2023-12-13 15:30:13 +01:00
parent 95d3b8ae4a
commit 50a1d74e65
10 changed files with 75 additions and 18 deletions

View file

@ -9,13 +9,15 @@
console.log('Not dev mode');
}
let surfers = [
{ name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
{ name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
{ name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' },
{ name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' },
{ name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' }
];
let heat_number;
let heats = [];
$: surfers = [];
// { name: 'Kanoa Igarashi', color: 'red', score: '4.50', priority: '3' },
// { name: 'Griffin Colapinto', color: 'white', score: '5.60', priority: 'P' },
// { name: 'Jack Robinson', color: 'blue', score: '6.10', priority: '5' },
// { name: 'Gabriel Medina', color: 'green', score: '4.30', priority: '2' },
// { name: 'Italo Ferreira', color: 'black', score: '6.50', priority: '4' }
// ];
let width;
// $: activeUrl = $page.url.pathname;
@ -40,8 +42,14 @@
surfers[i].priority = Msg.priority[i];
}
} else if (Msg.mode === 'time') {
console.log(`duration: ${Msg.duration}`);
min, sec = Msg.duration.split(":");
// console.log(`duration: ${Msg.duration}`);
let min_sec = Msg.duration.split(":");
min = min_sec[0];
sec = min_sec[1];
// console.log(`min & sec = ${min} & ${sec}`);
if (!start) {
start = true;
}
} else if (Msg.mode === 'stop') {
console.log(`stop duration: ${Msg.duration}`);
end = true;
@ -67,7 +75,7 @@
const res = await fetch(`/api/start`, {
method: 'POST',
body: JSON.stringify({
duration: "0m10s",
duration: min+"m",
mode: 'time'
}),
headers: {
@ -79,6 +87,24 @@
end = false;
}
async function loadHeats() {
const res = await fetch(`/api/load`);
const data = await res.json();
for (let i in data) {
heats[i] = data[i];
console.log(`${i} retval: ${JSON.stringify(data[i])}`);
}
}
function setHeat(id) {
console.log(`setHeat: ${id}`);
if (id === 99) {
return;
}
min = heats[id].timer;
surfers = heats[id].surfers;
}
async function click(id) {
console.log(surfers[id]);
if (surfers[id].priority === 'P') {
@ -144,6 +170,13 @@
<svelte:window bind:innerWidth={width} />
<div class="header">
<button class="button" on:click={() => loadHeats()} disabled={start}>Load</button>
<select name="heats" id="heats" bind:value={heat_number} on:change={() => setHeat(heat_number)}>
<option value=99>Select</option>
{#each heats as heat, id}
<option value={id}>{heat.name} {heat.category} {heat.number}</option>
{/each}
</select>
{#if !end}
<div class="timer">{pad2(min)}:{pad2(sec)}</div>
{:else}