ui: Randomize themes list
This commit is contained in:
parent
451b678e73
commit
23d5ea7c97
5 changed files with 39 additions and 7 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { derived } from 'svelte/store';
|
||||
|
||||
import seedrandom from 'seedrandom';
|
||||
|
||||
import { my } from './my.js';
|
||||
import { themesStore } from './themes.js';
|
||||
|
||||
|
|
@ -21,6 +23,31 @@ export const myThemes = derived([my, themesStore], ([$my, $themesStore]) => {
|
|||
return themes;
|
||||
});
|
||||
|
||||
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]);
|
||||
}
|
||||
const size = arr.length;
|
||||
const rng = new seedrandom($my && $my.team_id ? $my.team_id : 0);
|
||||
const resp = [];
|
||||
const keys = [];
|
||||
|
||||
for(let i=0;i<size;i++) keys.push(i);
|
||||
for(let i=0;i<size;i++) {
|
||||
const r = Math.floor(rng() * keys.length);
|
||||
const g = keys[r];
|
||||
keys.splice(r,1);
|
||||
resp.push(arr[g]);
|
||||
}
|
||||
|
||||
return resp;
|
||||
},
|
||||
);
|
||||
|
||||
export const tags = derived([my, themesStore], ([$my, $themesStore]) => {
|
||||
const tags = {};
|
||||
|
||||
|
|
|
|||
Reference in a new issue