From 14ead20349d2ee471e6bd3d2493c6ecdfb2cbbc8 Mon Sep 17 00:00:00 2001 From: Gisle Aune Date: Fri, 15 Jan 2021 19:50:49 +0100 Subject: [PATCH] add sorting to goals. --- svelte-ui/src/stores/goal.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/svelte-ui/src/stores/goal.ts b/svelte-ui/src/stores/goal.ts index 893441c..012a99e 100644 --- a/svelte-ui/src/stores/goal.ts +++ b/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] })); }, } }