ui: Refactor stores
This commit is contained in:
parent
9d171cfe89
commit
ffd43ac8e1
6 changed files with 136 additions and 86 deletions
|
|
@ -3,33 +3,33 @@ import { derived } from 'svelte/store';
|
|||
import seedrandom from 'seedrandom';
|
||||
|
||||
import { my } from './my.js';
|
||||
import { themesStore } from './themes.js';
|
||||
import { themes as themesStore } from './themes.js';
|
||||
|
||||
export const myThemes = derived([my, themesStore], ([$my, $themesStore]) => {
|
||||
const themes = {};
|
||||
const mythemes = {};
|
||||
|
||||
for (let key in $themesStore.themes) {
|
||||
themes[key] = {exercice_solved: 0};
|
||||
for (let key in $themesStore) {
|
||||
mythemes[key] = {exercice_solved: 0};
|
||||
|
||||
if ($my && $my.exercices) {
|
||||
for (let k in $themesStore.themes[key].exercices) {
|
||||
for (let k in $themesStore[key].exercices) {
|
||||
if ($my.exercices[k] && $my.exercices[k].solved_rank) {
|
||||
themes[key].exercice_solved++;
|
||||
mythemes[key].exercice_solved++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return themes;
|
||||
return mythemes;
|
||||
});
|
||||
|
||||
export const themes = derived(
|
||||
[my, themesStore],
|
||||
([$my, $themesStore]) => {
|
||||
const arr = [];
|
||||
for (let th in $themesStore.themes) {
|
||||
$themesStore.themes[th].id = th
|
||||
arr.push($themesStore.themes[th]);
|
||||
for (let th in $themesStore) {
|
||||
$themesStore[th].id = th
|
||||
arr.push($themesStore[th]);
|
||||
}
|
||||
const size = arr.length;
|
||||
const rng = new seedrandom($my && $my.team_id ? $my.team_id : 0);
|
||||
|
|
@ -51,9 +51,9 @@ export const themes = derived(
|
|||
export const tags = derived([my, themesStore], ([$my, $themesStore]) => {
|
||||
const tags = {};
|
||||
|
||||
for (let key in $themesStore.themes) {
|
||||
for (let k in $themesStore.themes[key].exercices) {
|
||||
$themesStore.themes[key].exercices[k].tags.forEach((tag) => {
|
||||
for (let key in $themesStore) {
|
||||
for (let k in $themesStore[key].exercices) {
|
||||
$themesStore[key].exercices[k].tags.forEach((tag) => {
|
||||
if (!tags[tag])
|
||||
tags[tag] = {count: 1, solved: 0};
|
||||
else
|
||||
|
|
|
|||
Reference in a new issue