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] })); }, } }