+ state
This commit is contained in:
parent
d962709f1f
commit
29ee89f9ba
1 changed files with 40 additions and 20 deletions
|
@ -4,16 +4,20 @@
|
||||||
import { rounds } from "$lib/stores/rounds.js";
|
import { rounds } from "$lib/stores/rounds.js";
|
||||||
import { categories } from "$lib/stores/categories.js";
|
import { categories } from "$lib/stores/categories.js";
|
||||||
|
|
||||||
let surfers = [];
|
|
||||||
let start = false;
|
|
||||||
let timer;
|
let timer;
|
||||||
let info = {
|
|
||||||
time: "00",
|
let surfers = $state([]);
|
||||||
|
let start = $state(false);
|
||||||
|
|
||||||
|
let info = $state({
|
||||||
cat: "U12 M",
|
cat: "U12 M",
|
||||||
round: "Qualifying",
|
round: "Qualifying",
|
||||||
heat: "1",
|
heat: "1",
|
||||||
};
|
});
|
||||||
let round_name = false;
|
let mins = $state(0);
|
||||||
|
let secs = $state(0);
|
||||||
|
|
||||||
|
let round_name = $state(false);
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
LoadFromLocalCache();
|
LoadFromLocalCache();
|
||||||
|
@ -45,11 +49,12 @@
|
||||||
];
|
];
|
||||||
start = false;
|
start = false;
|
||||||
info = {
|
info = {
|
||||||
time: "00",
|
|
||||||
cat: "U12 M",
|
cat: "U12 M",
|
||||||
round: "Qualifying",
|
round: "Qualifying",
|
||||||
heat: "1",
|
heat: "1",
|
||||||
};
|
};
|
||||||
|
mins = 0;
|
||||||
|
secs = 0;
|
||||||
round_name = false;
|
round_name = false;
|
||||||
console.log(`reset store: ${JSON.stringify(surfers)}`);
|
console.log(`reset store: ${JSON.stringify(surfers)}`);
|
||||||
}
|
}
|
||||||
|
@ -57,7 +62,6 @@
|
||||||
function SaveToLocalCahe() {
|
function SaveToLocalCahe() {
|
||||||
window.sessionStorage.setItem("surfers", JSON.stringify(surfers));
|
window.sessionStorage.setItem("surfers", JSON.stringify(surfers));
|
||||||
window.sessionStorage.setItem("info", JSON.stringify(info));
|
window.sessionStorage.setItem("info", JSON.stringify(info));
|
||||||
window.sessionStorage.setItem("start", JSON.stringify(start));
|
|
||||||
console.log(`update cache: ${JSON.stringify(surfers)}`);
|
console.log(`update cache: ${JSON.stringify(surfers)}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,7 +69,23 @@
|
||||||
console.log("StartHeat");
|
console.log("StartHeat");
|
||||||
start = true;
|
start = true;
|
||||||
SaveToLocalCahe();
|
SaveToLocalCahe();
|
||||||
timer = setInterval(info.time - 1, 1000);
|
timer = setInterval(Timer, 200);
|
||||||
|
}
|
||||||
|
|
||||||
|
function pad(n) {
|
||||||
|
return n < 10 ? "0" + n : n;
|
||||||
|
}
|
||||||
|
|
||||||
|
function Timer() {
|
||||||
|
console.log(mins + ":" + secs);
|
||||||
|
if (secs == 0) {
|
||||||
|
mins = mins - 1;
|
||||||
|
secs = 59;
|
||||||
|
console.log("sec = 0: " + mins + ":" + secs);
|
||||||
|
} else {
|
||||||
|
secs = secs - 1;
|
||||||
|
console.log("sec > 0: " + mins + ":" + secs);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function StopHeat() {
|
function StopHeat() {
|
||||||
|
@ -107,8 +127,8 @@
|
||||||
<div id="score-container">
|
<div id="score-container">
|
||||||
<div class="info-box">
|
<div class="info-box">
|
||||||
<div class="Time">
|
<div class="Time">
|
||||||
{#if info.time > "00"}
|
{#if mins >= 0}
|
||||||
<span id="time">{info.time}:00</span>
|
<span id="time">{pad(mins)}:{pad(secs)}</span>
|
||||||
{/if}
|
{/if}
|
||||||
</div>
|
</div>
|
||||||
<div class="Cat">
|
<div class="Cat">
|
||||||
|
@ -146,12 +166,12 @@
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="btn btn-danger mt-1 mb-3 w-100"
|
class="btn btn-danger mt-1 mb-3 w-100"
|
||||||
on:click={StopHeat}>Stop</button>
|
onclick={StopHeat}>Stop</button>
|
||||||
{:else}
|
{:else}
|
||||||
<button
|
<button
|
||||||
type="submit"
|
type="submit"
|
||||||
class="btn btn-primary mt-1 mb-3 w-100"
|
class="btn btn-primary mt-1 mb-3 w-100"
|
||||||
on:click={StartHeat}>Start</button>
|
onclick={StartHeat}>Start</button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<div class="input-group mb-1">
|
<div class="input-group mb-1">
|
||||||
|
@ -164,7 +184,7 @@
|
||||||
pattern="^[0-9][0-9]$"
|
pattern="^[0-9][0-9]$"
|
||||||
maxlength="2"
|
maxlength="2"
|
||||||
size="2"
|
size="2"
|
||||||
bind:value={info.time} />
|
bind:value={mins} />
|
||||||
<span class="input-group-text">category</span>
|
<span class="input-group-text">category</span>
|
||||||
<select
|
<select
|
||||||
class="form-select"
|
class="form-select"
|
||||||
|
@ -197,7 +217,7 @@
|
||||||
class="form-check-input mt-0"
|
class="form-check-input mt-0"
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
bind:checked={round_name}
|
bind:checked={round_name}
|
||||||
on:change={CheckRound}
|
onchange={CheckRound}
|
||||||
aria-label="Checkbox for following text input" />
|
aria-label="Checkbox for following text input" />
|
||||||
</div>
|
</div>
|
||||||
<span class="input-group-text">heat</span>
|
<span class="input-group-text">heat</span>
|
||||||
|
@ -256,11 +276,11 @@
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-primary mt-1 mb-1 w-100"
|
class="btn btn-primary mt-1 mb-1 w-100"
|
||||||
on:click={SaveToLocalCahe}>Save</button>
|
onclick={SaveToLocalCahe}>Save</button>
|
||||||
<button
|
<button
|
||||||
type="button"
|
type="button"
|
||||||
class="btn btn-primary mt-1 mb-1 w-100"
|
class="btn btn-primary mt-1 mb-1 w-100"
|
||||||
on:click={ResetLocalCache}>Reset</button>
|
onclick={ResetLocalCache}>Reset</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -278,7 +298,7 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
top: 6px;
|
top: 6px;
|
||||||
left: 6px;
|
left: 6px;
|
||||||
width: 250px;
|
width: 254px;
|
||||||
padding: 6px;
|
padding: 6px;
|
||||||
background: rgba(50, 50, 50, 0.7);
|
background: rgba(50, 50, 50, 0.7);
|
||||||
color: white;
|
color: white;
|
||||||
|
@ -295,7 +315,7 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-template-columns: 1fr 4fr 1fr;
|
grid-template-columns: 1fr 4fr 1fr;
|
||||||
grid-template-areas: "color surfer score";
|
grid-template-areas: "color surfer score";
|
||||||
width: 220px;
|
width: 254px;
|
||||||
padding-left: 6px;
|
padding-left: 6px;
|
||||||
padding-right: 6px;
|
padding-right: 6px;
|
||||||
padding-top: 2px;
|
padding-top: 2px;
|
||||||
|
@ -365,7 +385,7 @@
|
||||||
.score {
|
.score {
|
||||||
grid-area: score;
|
grid-area: score;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
text-align: end;
|
text-align: start;
|
||||||
align-content: center;
|
align-content: center;
|
||||||
margin-right: 2px;
|
margin-right: 2px;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue