Skip to content

Commit

Permalink
Added throbber to display while message-count-week-charts load
Browse files Browse the repository at this point in the history
  • Loading branch information
linda-baker committed May 29, 2024
1 parent 32a0c07 commit 86d8b7a
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions gui/src/components/message-counts/message-count-week-chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ import {
Typography,
CardHeader,
CardContent,
Box,
} from "@mui/material";
import React, { useEffect, useState} from "react";
import MessageMonitorApi from '../../apis/mm-api';
import {LocalizationProvider } from '@mui/x-date-pickers';
import AdapterDateFns from '@date-io/date-fns';
import { LineChart, Line, XAxis, YAxis, ResponsiveContainer, Tooltip, TooltipProps } from 'recharts';
import { NameType, ValueType } from "recharts/types/component/DefaultTooltipContent";
import CircularProgress from '@mui/material/CircularProgress';

export const MessageCountWeekChart = (props: {
accessToken: string | undefined;
Expand All @@ -24,10 +26,12 @@ export const MessageCountWeekChart = (props: {
type ChartData = { date: string; count: number; dayOfWeek: string };

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

useEffect(() => {
if (accessToken) {
setLoading(true);
const weekCounts: ChartData[] = [];

for (let i = 0; i < 7; i++) {
Expand Down Expand Up @@ -60,6 +64,7 @@ useEffect(() => {
Promise.all(promises)
.then((weekCounts) => {
setMessageCounts(weekCounts);
setLoading(false);
})
.catch((error) => console.error(error));

Expand Down Expand Up @@ -113,8 +118,17 @@ return (
sx={{ pb: 0 }}
/>
<CardContent sx={{ pt: 1}}>
<ResponsiveContainer height={hasData ? 250 : 50}>
{hasData ? (
<ResponsiveContainer height={loading ? 250 : (hasData ? 250 : 50)}>
{loading ? (
<Box
display="flex"
justifyContent="center"
alignItems="center"
height="100%"
>
<CircularProgress />
</Box>
) : hasData ? (
<LineChart data={messageCounts} margin={{ top: 5, right: 5}}>
<XAxis
dataKey="date"
Expand Down

0 comments on commit 86d8b7a

Please sign in to comment.