Skip to content

Commit

Permalink
Re-arrange promise logic for message-count-week-chart
Browse files Browse the repository at this point in the history
  • Loading branch information
linda-baker committed May 29, 2024
1 parent c3988f9 commit 32a0c07
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions gui/src/components/message-counts/message-count-week-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const MessageCountWeekChart = (props: {
type ChartData = { date: string; count: number; dayOfWeek: string };

const [messageCounts, setMessageCounts] = useState<ChartData[]>([]);
let promises: Promise<{ date: string; count: number; dayOfWeek: string; }>[] = [];

useEffect(() => {
if (accessToken) {
Expand All @@ -45,20 +46,23 @@ useEffect(() => {
dayStart,
dayEnd
);
messageCountPromise
.then((count) => {
weekCounts[i] = {
date: dayStart.toLocaleDateString(undefined, { month: '2-digit', day: '2-digit' }),
promises.push(
messageCountPromise.then((count) => {
return {
date: dayStart.toLocaleDateString(undefined, { month: '2-digit', day: '2-digit' }),
count: count,
dayOfWeek: dayStart.toLocaleDateString(undefined, { weekday: 'long' })
};
if (i === 6) {
setMessageCounts(weekCounts);
}
})
.catch((error) => console.error(error));

);
}

Promise.all(promises)
.then((weekCounts) => {
setMessageCounts(weekCounts);
})
.catch((error) => console.error(error));

}
}, [intersectionId]);

Expand Down

0 comments on commit 32a0c07

Please sign in to comment.