From b85c806ba7f80a81d7a80b773dbd846ed2444163 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sun, 12 Feb 2023 12:48:37 -0600 Subject: [PATCH] fix(gui): switch back to indeterminate progress when reported steps exceed estimate (#90) --- gui/src/components/LoadingCard.tsx | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/gui/src/components/LoadingCard.tsx b/gui/src/components/LoadingCard.tsx index db3120bf..b0105673 100644 --- a/gui/src/components/LoadingCard.tsx +++ b/gui/src/components/LoadingCard.tsx @@ -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)); @@ -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 ; } else { return ; @@ -90,7 +110,7 @@ export function LoadingCard(props: LoadingCardProps) { sx={{ alignItems: 'center' }} > {renderProgress()} - {getProgress()}/{props.loading.params.steps} steps + {getProgress()}/{getTotal()} steps