Skip to content

Commit

Permalink
fix(gui): switch back to indeterminate progress when reported steps e…
Browse files Browse the repository at this point in the history
…xceed estimate (#90)
  • Loading branch information
ssube committed Feb 12, 2023
1 parent aaf82a4 commit b85c806
Showing 1 changed file with 23 additions and 3 deletions.
26 changes: 23 additions & 3 deletions gui/src/components/LoadingCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ import { POLL_TIME } from '../config.js';
import { ClientContext, ConfigContext, StateContext } from '../state.js';

const LOADING_PERCENT = 100;
const LOADING_OVERAGE = 99;

export interface LoadingCardProps {
loading: ImageResponse;
}

export function LoadingCard(props: LoadingCardProps) {
const { steps } = props.loading.params;

const client = mustExist(React.useContext(ClientContext));
const { params } = mustExist(useContext(ConfigContext));

Expand Down Expand Up @@ -44,16 +47,33 @@ export function LoadingCard(props: LoadingCardProps) {
}

function getPercent() {
const pct = getProgress() / props.loading.params.steps;
const progress = getProgress();
if (progress > steps) {
// steps was not complete, show 99% until done
return LOADING_OVERAGE;
}

const pct = progress / steps;
return Math.ceil(pct * LOADING_PERCENT);
}

function getTotal() {
const progress = getProgress();
if (progress > steps) {
// steps was not complete, show 99% until done
return 'many';
}

return steps.toFixed(0);
}

function getReady() {
return doesExist(ready.data) && ready.data.ready;
}

function renderProgress() {
if (getProgress() > 0) {
const progress = getProgress();
if (progress > 0 && progress <= steps) {
return <CircularProgress variant='determinate' value={getPercent()} />;
} else {
return <CircularProgress />;
Expand Down Expand Up @@ -90,7 +110,7 @@ export function LoadingCard(props: LoadingCardProps) {
sx={{ alignItems: 'center' }}
>
{renderProgress()}
<Typography>{getProgress()}/{props.loading.params.steps} steps</Typography>
<Typography>{getProgress()}/{getTotal()} steps</Typography>
<Button onClick={() => cancel.mutate()}>Cancel</Button>
</Stack>
</Box>
Expand Down

0 comments on commit b85c806

Please sign in to comment.