add sorting to goals.
continuous-integration/drone/push Build is passing

This commit is contained in:
2021-01-15 19:50:49 +01:00
parent 1a3a8949f8
commit 14ead20349
+16 -1
View File
@@ -25,7 +25,22 @@ function createGoalStore() {
async load(filter: GoalFilter) { async load(filter: GoalFilter) {
update(v => ({...v, loading: true, filter})); update(v => ({...v, loading: true, filter}));
const goals = await stuffLogClient.listGoals(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] }));
}, },
} }
} }