1+ import React , { useState , useEffect } from 'react' ;
2+ import useInterval from '@use-it/interval'
3+ import '../../../sass/main.css'
4+ import Title from '../../../components/Title' ;
5+ import PracticeBox from '../../../components/PracticeBox' ;
6+ import { useSelector , useDispatch } from 'react-redux' ;
7+ import { initState , selectProgressPercent , selectTypeCount , updateTypeSpeed , selectTitle } from "./scriptSlice" ;
8+
9+ function PracticeScript ( ) {
10+ const dispatch = useDispatch ( ) ;
11+ const progressPecent = useSelector ( selectProgressPercent ) ;
12+ const typeCount = useSelector ( selectTypeCount ) ;
13+ const [ tick , setTick ] = useState ( 0 ) ; // 시작 후 흐른 시간
14+ const [ typeSpeed , setTypeSpeed ] = useState ( 0 ) ;
15+ const [ maxTypeSpeed , setMaxTypeSpeed ] = useState ( 0 ) ;
16+ const [ praticeInformation , setPractiveInformation ] = useState ( [ ] ) ;
17+ const title = useSelector ( selectTitle ) ;
18+
19+ useEffect ( ( ) => {
20+ dispatch ( initState ( ) ) ;
21+ } , [ ] ) ;
22+
23+ useEffect ( ( ) => {
24+ setPractiveInformation ( [
25+ { title : "진행도" , figure : progressPecent , id : "noBorder" } ,
26+ { title : "현재 타수" , figure : typeSpeed } ,
27+ { title : "최대 타수" , figure : maxTypeSpeed } ,
28+ { title : "스크립트명" , figure : title } ,
29+ ] ) ;
30+ } , [ tick ] ) ;
31+
32+ useInterval ( ( ) => {
33+ setTypeSpeed ( parseInt ( typeCount / tick * 60 ) | 0 ) ;
34+ setMaxTypeSpeed ( Math . max ( typeSpeed , maxTypeSpeed ) ) ;
35+ setTick ( tick + 0.1 ) ;
36+ dispatch ( updateTypeSpeed ( typeSpeed ) ) ;
37+ } , 100 ) ;
38+
39+ return (
40+ < div className = "content" >
41+ < Title title = "스크립트 연습" />
42+ < PracticeBox type = "script" information = { praticeInformation } />
43+ </ div >
44+ ) ;
45+ }
46+
47+ export default PracticeScript ;
0 commit comments