diff --git a/frontend/fic/src/lib/components/ExerciceDownloads.svelte b/frontend/fic/src/lib/components/ExerciceDownloads.svelte index 14ae7e7e..6da12ad5 100644 --- a/frontend/fic/src/lib/components/ExerciceDownloads.svelte +++ b/frontend/fic/src/lib/components/ExerciceDownloads.svelte @@ -9,6 +9,7 @@ ListGroupItem, } from '@sveltestrap/sveltestrap'; + import { hasDownloaded } from '$lib/stores/downloaded.js'; import FileSize from './FileSize.svelte'; export let files = []; @@ -27,8 +28,8 @@ {#each files as file, index} - -

+ hasDownloaded.update((u) => {u[file.path] = true; return u;})}> +

diff --git a/frontend/fic/src/lib/components/ExerciceFlags.svelte b/frontend/fic/src/lib/components/ExerciceFlags.svelte index a84360e4..c5c8e24c 100644 --- a/frontend/fic/src/lib/components/ExerciceFlags.svelte +++ b/frontend/fic/src/lib/components/ExerciceFlags.svelte @@ -17,6 +17,7 @@ import { my } from '$lib/stores/my.js'; import { settings } from '$lib/stores/settings.js'; + import { submissions } from '$lib/stores/submissions.js'; import { timeouted, waitDiff, waitInProgress } from '$lib/wait.js'; import DateFormat from './DateFormat.svelte'; @@ -36,6 +37,20 @@ message = ""; last_submission = JSON.parse(JSON.stringify(responses)); + submissions.update((u) => { + for (const k in last_submission.flags) { + u.flags[k] = last_submission.flags[k]; + } + + for (const k in last_submission.mcqs) { + u.mcqs[k] = last_submission.mcqs[k]; + } + + for (const k in last_submission.justifications) { + u.justifications[k] = last_submission.justifications[k]; + } + }) + if ($my && $my.team_id === 0) { let allGoodResponse = true; for (const f in flags) { diff --git a/frontend/fic/src/lib/components/FlagKey.svelte b/frontend/fic/src/lib/components/FlagKey.svelte index a1084965..411aa26b 100644 --- a/frontend/fic/src/lib/components/FlagKey.svelte +++ b/frontend/fic/src/lib/components/FlagKey.svelte @@ -9,6 +9,7 @@ import { my } from '$lib/stores/my.js'; import { settings } from '$lib/stores/settings.js'; + import { submissions } from '$lib/stores/submissions.js'; export { className as class }; let className = ''; @@ -247,6 +248,15 @@ title="Flag trouvé à {flag.found}" value={value} > + {:else if $submissions && $submissions.flags && $submissions.flags[flag.id]} + {:else} { + update(u); + if (window.localStorage) localStorage.setItem("downloadedStore", JSON.stringify(init)); + }, + } +} + +export const hasDownloaded = createDownloadedStore(); diff --git a/frontend/fic/src/lib/stores/submissions.js b/frontend/fic/src/lib/stores/submissions.js new file mode 100644 index 00000000..c4b5abd8 --- /dev/null +++ b/frontend/fic/src/lib/stores/submissions.js @@ -0,0 +1,33 @@ +import { writable } from 'svelte/store'; + +function createSubmissionsStore() { + let init = { + flags: { }, + mcqs: { }, + justifications: { }, + }; + try { + if (window.localStorage && window.localStorage.getItem("submissionsStore")) { + init = JSON.parse(window.localStorage.getItem("submissionsStore")); + } + } catch { + init = { + flags: { }, + mcqs: { }, + justifications: { }, + }; + } + + const { subscribe, set, update } = writable(init); + + return { + subscribe, + + update: (u) => { + update(u); + if (window.localStorage) localStorage.setItem("submissionsStore", JSON.stringify(init)); + }, + } +} + +export const submissions = createSubmissionsStore();