jbilcke-hf HF staff commited on
Commit
c32c4ae
·
1 Parent(s): ba3ad8d

fix for the progress component

Browse files
src/components/business/image-renderer.tsx CHANGED
@@ -18,6 +18,7 @@ export const ImageRenderer = ({
18
  onUserHover: (actionnable: string) => void
19
  isLoading?: boolean
20
  }) => {
 
21
  const imgRef = useRef<HTMLImageElement | null>(null)
22
  const canvasRef = useRef<HTMLCanvasElement | null>(null)
23
  const contextRef = useRef<CanvasRenderingContext2D | null>(null)
@@ -147,14 +148,17 @@ export const ImageRenderer = ({
147
  };
148
 
149
  useEffect(() => {
 
150
  let progress = 0
151
-
152
  // note: when everything is fine, it takes about 45 seconds to render a new scene
153
 
154
  const computeProgress = async () => {
155
  if (!showLoaderRef.current) {
156
  console.log("Asked to hide the loader")
 
157
  setProcessPercent(100)
 
158
  return
159
  }
160
 
@@ -164,14 +168,13 @@ export const ImageRenderer = ({
164
  progress = progress + 1
165
  setProcessPercent(progress)
166
 
167
- setTimeout(() => {
168
  computeProgress()
169
  }, 1000)
170
-
171
  }
172
 
173
  computeProgress()
174
- }, [])
175
 
176
 
177
  useEffect(() => {
 
18
  onUserHover: (actionnable: string) => void
19
  isLoading?: boolean
20
  }) => {
21
+ const timeoutRef = useRef<any>()
22
  const imgRef = useRef<HTMLImageElement | null>(null)
23
  const canvasRef = useRef<HTMLCanvasElement | null>(null)
24
  const contextRef = useRef<CanvasRenderingContext2D | null>(null)
 
148
  };
149
 
150
  useEffect(() => {
151
+ clearTimeout(timeoutRef.current)
152
  let progress = 0
153
+ setProcessPercent(0)
154
  // note: when everything is fine, it takes about 45 seconds to render a new scene
155
 
156
  const computeProgress = async () => {
157
  if (!showLoaderRef.current) {
158
  console.log("Asked to hide the loader")
159
+ progress = 100
160
  setProcessPercent(100)
161
+ clearTimeout(timeoutRef.current)
162
  return
163
  }
164
 
 
168
  progress = progress + 1
169
  setProcessPercent(progress)
170
 
171
+ timeoutRef.current = setTimeout(() => {
172
  computeProgress()
173
  }, 1000)
 
174
  }
175
 
176
  computeProgress()
177
+ }, [assetUrl])
178
 
179
 
180
  useEffect(() => {