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