← All changes
|
assets/src/apps/js/frontend/quiz/components/timer/index.js
+10
-3
4.1.7.2
→
4.4.10
View file →
| @@ -8,12 +8,13 @@ | ||
| 8 | 8 | |
| 9 | 9 | const Timer = () => { |
| 10 | 10 | const { getData } = select( 'learnpress/quiz' ); |
| 11 | 11 | const { submitQuiz } = dispatch( 'learnpress/quiz' ); |
| 12 | - const totalTime = getData( 'totalTime' ); | |
| 12 | + let totalTime = getData( 'totalTime' ); | |
| 13 | 13 | const durationTime = getData( 'duration' ); |
| 14 | + const timeSpendG = getData( 'timeSpend' ); | |
| 14 | 15 | const [ seconds, setSeconds ] = useState( totalTime ); |
| 15 | - let [ timeSpend, setTimeSpend ] = useState( 0 ); | |
| 16 | + let [ timeSpend, setTimeSpend ] = useState( timeSpendG ); | |
| 16 | 17 | |
| 17 | 18 | useEffect( () => { |
| 18 | 19 | const myInterval = setInterval( () => { |
| 19 | 20 | if ( durationTime > 0 ) { |
| @@ -19,8 +20,10 @@ | ||
| 19 | 20 | if ( durationTime > 0 ) { |
| 20 | 21 | let remainSeconds = seconds; |
| 21 | 22 | remainSeconds -= 1; |
| 22 | 23 | |
| 24 | + remainSeconds = wp.hooks.applyFilters( 'js-lp-quiz-remaining_time', remainSeconds, durationTime ); | |
| 25 | + | |
| 23 | 26 | if ( remainSeconds > 0 ) { |
| 24 | 27 | setSeconds( remainSeconds ); |
| 25 | 28 | timeSpend++; |
| 26 | 29 | setTimeSpend( durationTime - remainSeconds ); |
| @@ -41,8 +44,12 @@ | ||
| 41 | 44 | const formatTime = ( separator = ':' ) => { |
| 42 | 45 | const t = []; |
| 43 | 46 | let m; |
| 44 | 47 | |
| 48 | + if ( timeSpendG ) { | |
| 49 | + totalTime = timeSpendG; | |
| 50 | + } | |
| 51 | + | |
| 45 | 52 | if ( totalTime < 3600 ) { |
| 46 | 53 | t.push( ( seconds - ( seconds % 60 ) ) / 60 ); |
| 47 | 54 | t.push( seconds % 60 ); |
| 48 | 55 | } else if ( totalTime ) { |
| @@ -58,9 +65,9 @@ | ||
| 58 | 65 | }; |
| 59 | 66 | |
| 60 | 67 | return ( |
| 61 | 68 | <div className="countdown"> |
| 62 | - <i className="fas fa-stopwatch"></i> | |
| 69 | + <i className="lp-icon-stopwatch"></i> | |
| 63 | 70 | <span>{ formatTime() }</span> |
| 64 | 71 | <input type="hidden" name="lp-quiz-time-spend" value={ timeSpend } /> |
| 65 | 72 | </div> |
| 66 | 73 | ); |