Browse Source

add sorting to goals.

main
Gisle Aune 4 years ago
parent
commit
14ead20349
  1. 17
      svelte-ui/src/stores/goal.ts

17
svelte-ui/src/stores/goal.ts

@ -25,7 +25,22 @@ function createGoalStore() {
async load(filter: GoalFilter) {
update(v => ({...v, loading: true, filter}));
const goals = await stuffLogClient.listGoals(filter);
update(v => ({...v, loading: false, stale: false, goals }));
const expireds = [];
const upcomings = [];
const actives = [];
const now = Date.now();
for (const goal of goals) {
if (Date.parse(goal.endTime) < now) {
expireds.push(goal);
} else if (Date.parse(goal.startTime) > now) {
upcomings.push(goal);
} else {
actives.push(goal);
}
}
update(v => ({...v, loading: false, stale: false, goals: [...upcomings, ...actives, ...expireds] }));
},
}
}

Loading…
Cancel
Save