Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit696b27f

Browse files
committed
Refactor to new file
Signed-off-by: Shubham <shubhamshahrising@gmail.com>
1 parentde37051 commit696b27f

File tree

2 files changed

+33
-17
lines changed

2 files changed

+33
-17
lines changed

‎web-app/src/containers/Tutorial/components/ProgressPie.tsx

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,14 @@
11
import*asReactfrom'react'
22
import{Progress,Icon}from'@alifd/next'
3+
importuseNaturalProgressfrom'services/hooks/useNaturalProgress'
34

45
interfaceProps{
56
current:number
67
max:number
78
}
89

910
constProgressPie=(props:Props)=>{
10-
const[progress,setProgress]=React.useState(0)
11-
React.useEffect(()=>{
12-
lettimeout:any
13-
letdifference=(props.current-progress)/4
14-
// for difference>0.01 update progress or make it stop
15-
letnewProgress=difference>0.01 ?progress+difference :props.current
16-
if(progress<props.current){
17-
timeout=setTimeout(()=>{
18-
setProgress(newProgress)
19-
},100)
20-
}
21-
return()=>{
22-
if(timeout){
23-
clearTimeout(timeout)
24-
}
25-
}
26-
},[progress])
11+
constprogress=useNaturalProgress({stop:props.current})
2712

2813
constprogressPercent=Math.floor((progress/props.max)*100)
2914

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import{useEffect,useState}from'react'
2+
3+
interfaceProgressConfig{
4+
start?:number
5+
stop:number
6+
updateDuration?:number
7+
}
8+
9+
constuseNaturalProgress=(config:ProgressConfig):number=>{
10+
const{ start, stop, updateDuration}=config
11+
const[progress,setProgress]=useState(start||0)
12+
useEffect(()=>{
13+
lettimeout:any
14+
letdifference=(stop-progress)/4
15+
// for difference>0.01 update progress or make it stop
16+
letnewProgress=difference>0.01 ?progress+difference :stop
17+
if(progress<stop){
18+
timeout=setTimeout(()=>{
19+
setProgress(newProgress)
20+
},updateDuration||100)
21+
}
22+
return()=>{
23+
if(timeout){
24+
clearTimeout(timeout)
25+
}
26+
}
27+
},[progress,stop,updateDuration])
28+
returnprogress
29+
}
30+
31+
exportdefaultuseNaturalProgress

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp