ui: Solve scenario loading mess
This commit is contained in:
parent
ffd43ac8e1
commit
3d35cee67d
10 changed files with 202 additions and 151 deletions
19
frontend/ui/src/lib/stores/exercices.js
Normal file
19
frontend/ui/src/lib/stores/exercices.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
import { exercices_idx_urlid } from './themes';
|
||||
|
||||
export const set_current_exercice = writable(null)
|
||||
|
||||
export const current_exercice = derived(
|
||||
[set_current_exercice, exercices_idx_urlid],
|
||||
([$set_current_exercice, $exercices_idx_urlid]) => {
|
||||
if ($exercices_idx_urlid === null || Object.keys($exercices_idx_urlid).length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($exercices_idx_urlid[$set_current_exercice])
|
||||
return $exercices_idx_urlid[$set_current_exercice];
|
||||
|
||||
return undefined;
|
||||
}
|
||||
)
|
||||
|
|
@ -78,6 +78,22 @@ export const themes = derived(
|
|||
},
|
||||
);
|
||||
|
||||
export const themes_idx = derived(
|
||||
themes,
|
||||
($themes) => {
|
||||
const ret = {};
|
||||
|
||||
for (const key in $themes) {
|
||||
const theme = $themes[key];
|
||||
|
||||
ret[theme.urlid] = theme;
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
null,
|
||||
);
|
||||
|
||||
export const exercices_idx = derived(
|
||||
themesStore,
|
||||
($themesStore) => {
|
||||
|
|
@ -94,6 +110,23 @@ export const exercices_idx = derived(
|
|||
},
|
||||
);
|
||||
|
||||
export const exercices_idx_urlid = derived(
|
||||
themesStore,
|
||||
($themesStore) => {
|
||||
const ret = {};
|
||||
|
||||
for (const key in $themesStore) {
|
||||
const theme = $themesStore[key];
|
||||
for (let k in theme.exercices) {
|
||||
ret[theme.exercices[k].urlid] = theme.exercices[k];
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
null
|
||||
);
|
||||
|
||||
export const max_solved = derived(
|
||||
themesStore,
|
||||
($themesStore) => {
|
||||
|
|
@ -109,3 +142,19 @@ export const max_solved = derived(
|
|||
return ret;
|
||||
},
|
||||
);
|
||||
|
||||
export const set_current_theme = writable(null)
|
||||
|
||||
export const current_theme = derived(
|
||||
[set_current_theme, themes_idx],
|
||||
([$set_current_theme, $themes_idx]) => {
|
||||
if ($themes_idx === null || Object.keys($themes_idx).length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($themes_idx[$set_current_theme])
|
||||
return $themes_idx[$set_current_theme];
|
||||
|
||||
return undefined;
|
||||
}
|
||||
)
|
||||
|
|
|
|||
Reference in a new issue