added loadingbar when fetching other intervals #63
@@ -14,6 +14,7 @@ import FormHelperText from '@material-ui/core/FormHelperText';
|
|||||||
import MenuItem from '@material-ui/core/MenuItem';
|
import MenuItem from '@material-ui/core/MenuItem';
|
||||||
import FormControl from '@material-ui/core/FormControl';
|
import FormControl from '@material-ui/core/FormControl';
|
||||||
import Select from '@material-ui/core/Select';
|
import Select from '@material-ui/core/Select';
|
||||||
|
import LinearProgress from '@material-ui/core/LinearProgress';
|
||||||
|
|
||||||
const useStyles = makeStyles((theme) => ({
|
const useStyles = makeStyles((theme) => ({
|
||||||
root: {
|
root: {
|
||||||
@@ -40,8 +41,12 @@ export default function ResourceChart(props) {
|
|||||||
const classes = useStyles();
|
const classes = useStyles();
|
||||||
const [data, setData] = React.useState(null);
|
const [data, setData] = React.useState(null);
|
||||||
const [interval, setInterval] = React.useState('day');
|
const [interval, setInterval] = React.useState('day');
|
||||||
|
const [loading, setLoading] = React.useState(null);
|
||||||
let { id } = useParams();
|
let { id } = useParams();
|
||||||
const loadData = async () => {
|
const loadData = async () => {
|
||||||
|
if (loading === null) {
|
||||||
|
setLoading(<LinearProgress />)
|
||||||
|
}
|
||||||
let dayData = await fetch(`/simcompanies/API/${interval}?kind=${id}`);
|
let dayData = await fetch(`/simcompanies/API/${interval}?kind=${id}`);
|
||||||
let dataWithDate = await dayData.json();
|
let dataWithDate = await dayData.json();
|
||||||
let qualitySortedData = [];
|
let qualitySortedData = [];
|
||||||
@@ -91,9 +96,9 @@ export default function ResourceChart(props) {
|
|||||||
} else {
|
} else {
|
||||||
qualitySortedData[i]["time"] = qualitySortedData[i]["time"].toLocaleDateString();
|
qualitySortedData[i]["time"] = qualitySortedData[i]["time"].toLocaleDateString();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
setData(qualitySortedData)
|
setData(qualitySortedData)
|
||||||
|
setLoading(null)
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -110,7 +115,6 @@ export default function ResourceChart(props) {
|
|||||||
const handleChange = (event) => {
|
const handleChange = (event) => {
|
||||||
setInterval(event.target.value);
|
setInterval(event.target.value);
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classes.root}>
|
<div className={classes.root}>
|
||||||
<Grid container spacing={2}>
|
<Grid container spacing={2}>
|
||||||
@@ -134,6 +138,7 @@ export default function ResourceChart(props) {
|
|||||||
</Select>
|
</Select>
|
||||||
<FormHelperText>Select Interval</FormHelperText>
|
<FormHelperText>Select Interval</FormHelperText>
|
||||||
</FormControl>
|
</FormControl>
|
||||||
|
{loading}
|
||||||
<CardContent style={{ padding: 0 }}>
|
<CardContent style={{ padding: 0 }}>
|
||||||
{output(data)}
|
{output(data)}
|
||||||
</CardContent>
|
</CardContent>
|
||||||
|
|||||||
Reference in New Issue
Block a user