frontend: Refactor waitDiff func
This commit is contained in:
parent
ac39fe2493
commit
a0c34018cf
@ -16,8 +16,8 @@
|
||||
import { blake2b } from 'hash-wasm';
|
||||
|
||||
import { my } from '$lib/stores/my.js';
|
||||
import { teamsStore } from '$lib/stores/teams.js';
|
||||
import { settings } from '$lib/stores/settings.js';
|
||||
import { timeouted, waitDiff, waitInProgress } from '$lib/wait.js';
|
||||
|
||||
import DateFormat from './DateFormat.svelte';
|
||||
import FlagKey from './FlagKey.svelte';
|
||||
@ -27,24 +27,10 @@
|
||||
export let flags = [];
|
||||
export let readonly = false;
|
||||
|
||||
function waitDiff(i) {
|
||||
my.refresh((my) => {
|
||||
if (my && (my.exercices[exercice.id].tries != exercice.tries || my.exercices[exercice.id].solved_rank != exercice.solved_rank || my.exercices[exercice.id].solved_time != exercice.solved_time)) {
|
||||
submitInProgress = false;
|
||||
teamsStore.refresh();
|
||||
} else if (i > 0) {
|
||||
setTimeout(waitDiff, (12-i)*50+440, i-1);
|
||||
} else {
|
||||
timeouted = true;
|
||||
submitInProgress = false;
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
export let forcesolved = false;
|
||||
let responses = { };
|
||||
async function submitFlags() {
|
||||
submitInProgress = true;
|
||||
waitInProgress.set(true);
|
||||
sberr = "";
|
||||
message = "";
|
||||
|
||||
@ -91,7 +77,7 @@
|
||||
exercice.solved_time = new Date();
|
||||
exercice = exercice;
|
||||
|
||||
submitInProgress = false;
|
||||
waitInProgress.set(false);
|
||||
} else {
|
||||
const response = await fetch(
|
||||
"submit/" + exercice.id,
|
||||
@ -106,9 +92,9 @@
|
||||
const data = await response.json();
|
||||
messageClass = 'text-success';
|
||||
message = data.errmsg;
|
||||
waitDiff(13);
|
||||
waitDiff(13, exercice);
|
||||
} else {
|
||||
submitInProgress = false;
|
||||
waitInProgress.set(false);
|
||||
|
||||
messageClass = 'text-danger';
|
||||
|
||||
@ -146,8 +132,6 @@
|
||||
let sberr = "";
|
||||
let message = "";
|
||||
let messageClass = "text-danger";
|
||||
let timeouted = false;
|
||||
let submitInProgress = false;
|
||||
</script>
|
||||
|
||||
<Card class="border-danger mb-2">
|
||||
@ -165,7 +149,7 @@
|
||||
{exercice.flags.filter((f) => f.type !== undefined).length}/{exercice.nb_flags}
|
||||
</Progress>
|
||||
{/if}
|
||||
{#if exercice.tries || exercice.solved_time || exercice.submitted || sberr || timeouted}
|
||||
{#if exercice.tries || exercice.solved_time || exercice.submitted || sberr || $timeouted}
|
||||
<ListGroup class="border-dark">
|
||||
{#if exercice.solved_time || exercice.tries}
|
||||
<ListGroupItem class="text-warning rounded-0">
|
||||
@ -187,7 +171,7 @@
|
||||
{/if}
|
||||
</ListGroupItem>
|
||||
{/if}
|
||||
{#if timeouted}
|
||||
{#if $timeouted}
|
||||
<ListGroupItem class="text-danger rounded-0">
|
||||
<strong>Oops</strong>
|
||||
La requête a dépassé le délai d'attente. Vous devriez réessayer dans quelques instant…
|
||||
@ -225,9 +209,9 @@
|
||||
type="submit"
|
||||
color="danger"
|
||||
id="submission-{exercice.id}"
|
||||
disabled={submitInProgress || $settings.disablesubmitbutton || readonly}
|
||||
disabled={$waitInProgress || $settings.disablesubmitbutton || readonly}
|
||||
>
|
||||
{#if submitInProgress}
|
||||
{#if $waitInProgress}
|
||||
<Spinner size="sm" class="me-2" />
|
||||
{/if}
|
||||
Soumettre
|
||||
|
22
frontend/fic/src/lib/wait.js
Normal file
22
frontend/fic/src/lib/wait.js
Normal file
@ -0,0 +1,22 @@
|
||||
import { writable } from 'svelte/store';
|
||||
|
||||
import { my } from '$lib/stores/my.js';
|
||||
import { teamsStore } from '$lib/stores/teams.js';
|
||||
|
||||
export let waitInProgress = writable(false);
|
||||
export let timeouted = writable(false);
|
||||
|
||||
export function waitDiff(i, exercice) {
|
||||
timeouted.set(false);
|
||||
my.refresh((my) => {
|
||||
if (my && (my.exercices[exercice.id].tries != exercice.tries || my.exercices[exercice.id].solved_rank != exercice.solved_rank || my.exercices[exercice.id].solved_time != exercice.solved_time)) {
|
||||
waitInProgress.set(false);
|
||||
teamsStore.refresh();
|
||||
} else if (i > 0) {
|
||||
setTimeout(waitDiff, (12-i)*50+440, i-1, exercice);
|
||||
} else {
|
||||
timeouted.set(true);
|
||||
waitInProgress.set(false);
|
||||
}
|
||||
})
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user