diff --git a/frontend/ui/src/lib/stores/exercices.js b/frontend/ui/src/lib/stores/exercices.js
new file mode 100644
index 00000000..139a50a5
--- /dev/null
+++ b/frontend/ui/src/lib/stores/exercices.js
@@ -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;
+ }
+)
diff --git a/frontend/ui/src/lib/stores/themes.js b/frontend/ui/src/lib/stores/themes.js
index 592cf13c..247d2c12 100644
--- a/frontend/ui/src/lib/stores/themes.js
+++ b/frontend/ui/src/lib/stores/themes.js
@@ -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;
+ }
+)
diff --git a/frontend/ui/src/routes/[theme]/+layout.js b/frontend/ui/src/routes/[theme]/+layout.js
index 2baa5eb2..c5264093 100644
--- a/frontend/ui/src/routes/[theme]/+layout.js
+++ b/frontend/ui/src/routes/[theme]/+layout.js
@@ -1,19 +1,5 @@
-import { get_store_value } from 'svelte/internal';
+import { set_current_theme } from '$lib/stores/themes';
-import { themes } from '$lib/stores/themes.js';
-
-export async function load({ params }) {
- const thms = get_store_value(themes);
-
- let theme = null;
- for (let th in thms) {
- if (thms[th] && thms[th].urlid === params.theme) {
- theme = thms[th];
- break;
- }
- }
-
- return {
- theme,
- };
+export function load({ params }) {
+ set_current_theme.set(params.theme);
}
diff --git a/frontend/ui/src/routes/[theme]/+layout.svelte b/frontend/ui/src/routes/[theme]/+layout.svelte
index 1645772a..40800d53 100644
--- a/frontend/ui/src/routes/[theme]/+layout.svelte
+++ b/frontend/ui/src/routes/[theme]/+layout.svelte
@@ -1,31 +1,44 @@