ui: Almost all interface done with Svelte
This commit is contained in:
parent
9fa1ede69c
commit
7e13cf28bd
54 changed files with 2809 additions and 16 deletions
45
frontend/ui/src/stores/teams.js
Normal file
45
frontend/ui/src/stores/teams.js
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
import { derived, writable } from 'svelte/store';
|
||||
|
||||
function createTeamsStore() {
|
||||
const { subscribe, set, update } = writable({teams:{}, teams_count: 0, rank: []});
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
update: (res_teams, cb=null) => {
|
||||
if (res_teams.status === 200) {
|
||||
res_teams.json().then((teams) => {
|
||||
const teams_count = Object.keys(teams).length
|
||||
|
||||
const rank = [];
|
||||
for (const tid in teams) {
|
||||
teams[tid].id = Number(tid);
|
||||
rank.push(teams[tid]);
|
||||
}
|
||||
|
||||
update((t) => (Object.assign(t, {teams, teams_count, rank})));
|
||||
|
||||
if (cb) {
|
||||
cb(teams, teams_count, rank);
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const teamsStore = createTeamsStore();
|
||||
|
||||
export const teams = derived(
|
||||
teamsStore,
|
||||
($teamsStore) => ($teamsStore.teams)
|
||||
);
|
||||
|
||||
export const teams_count = derived(
|
||||
teamsStore,
|
||||
($teamsStore) => ($teamsStore.teams_count)
|
||||
);
|
||||
|
||||
export const rank = derived(
|
||||
teamsStore,
|
||||
($teamsStore) => ($teamsStore.rank)
|
||||
);
|
||||
Reference in a new issue