Skip to content

Commit

Permalink
fix(api): show indeterminate spinner until progress has been determined
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 4, 2023
1 parent 53f4924 commit 88815b3
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions gui/src/components/LoadingCard.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { doesExist, mustExist } from '@apextoaster/js-utils';
import { Box, Button, Card, CardContent, CircularProgress, Typography } from '@mui/material';
import { Stack } from '@mui/system';
import * as React from 'react';
import { useContext, useEffect } from 'react';
import { useMutation, useQuery } from 'react-query';
Expand Down Expand Up @@ -51,6 +52,14 @@ export function LoadingCard(props: LoadingCardProps) {
return doesExist(ready.data) && ready.data.ready;
}

function renderProgress() {
if (ready.status === 'success') {
return <CircularProgress variant='determinate' value={getPercent()} />;
} else {
return <CircularProgress />;
}
}

useEffect(() => {
if (cancel.status === 'success') {
clearLoading();
Expand All @@ -75,9 +84,15 @@ export function LoadingCard(props: LoadingCardProps) {
justifyContent: 'center',
minHeight: params.height.default,
}}>
<CircularProgress variant='determinate' value={getPercent()} />
<Typography>{getProgress()} of {props.loading.params.steps}</Typography>
<Button onClick={() => cancel.mutate()}>Cancel</Button>
<Stack
direction='column'
spacing={2}
sx={{ alignItems: 'center' }}
>
{renderProgress()}
<Typography>{getProgress()} of {props.loading.params.steps}</Typography>
<Button onClick={() => cancel.mutate()}>Cancel</Button>
</Stack>
</Box>
</CardContent>
</Card>;
Expand Down

0 comments on commit 88815b3

Please sign in to comment.