diff --git a/components/Progress.tsx b/components/Progress.tsx index a916323..59fc855 100644 --- a/components/Progress.tsx +++ b/components/Progress.tsx @@ -4,12 +4,14 @@ import { ContextType, createContext, } from "preact"; +import round from "lodash/round"; type CtxProps = { min: number; max: number; striped: boolean; animated: boolean; + precision: number; }; const PCtx = createContext(null); @@ -26,6 +28,7 @@ type BarProps = { max: number, min: number, ) => string; + precision?: number; }; class ProgressBar extends Component { @@ -39,6 +42,10 @@ class ProgressBar extends Component { const animated = this.props.animated === undefined ? this.context?.animated : this.props.animated; + const precision = + (this.props.precision === undefined + ? this.context?.precision + : this.props.precision) || 2; if (striped || animated) cls += " progress-bar-striped"; if (animated) cls += " progress-bar-animated"; if (this.props.class) cls += " " + this.props.class; @@ -49,7 +56,7 @@ class ProgressBar extends Component { const style = `width: ${per}%;`; let label = this.props.label; if (this.props.set_label) { - label = this.props.set_label(per, v, max, min); + label = this.props.set_label(round(per, precision), v, max, min); } return (
{ @@ -89,6 +98,7 @@ export default class Progress extends Component { max: this.props.max || 100, striped: this.props.striped || false, animated: this.props.animated || false, + precision: this.props.precision || 2, }} > {this.props.children} diff --git a/tasks/download.ts b/tasks/download.ts index b26bcf7..b090c27 100644 --- a/tasks/download.ts +++ b/tasks/download.ts @@ -90,9 +90,9 @@ class DownloadManager { this.#task.id, this.#progress, ); + this.#progress_changed = false; + this.#last_send_progress = now; } - this.#progress_changed = false; - this.#last_send_progress = now; } } #sendEvent() {