|
@@ -1,167 +0,0 @@
|
1
|
|
-/* global AJS */
|
2
|
|
-
|
3
|
|
-import PropTypes from 'prop-types';
|
4
|
|
-import React, { Component } from 'react';
|
5
|
|
-
|
6
|
|
-import { translate } from '../../base/i18n';
|
7
|
|
-
|
8
|
|
-/**
|
9
|
|
- * Implements a React Component for the reload timer. Starts counter from
|
10
|
|
- * props.start, adds props.step to the current value on every props.interval
|
11
|
|
- * seconds until the current value reaches props.end. Also displays progress
|
12
|
|
- * bar.
|
13
|
|
- */
|
14
|
|
-class ReloadTimer extends Component {
|
15
|
|
- /**
|
16
|
|
- * ReloadTimer component's property types.
|
17
|
|
- *
|
18
|
|
- * @static
|
19
|
|
- */
|
20
|
|
- static propTypes = {
|
21
|
|
- /**
|
22
|
|
- * The end of the timer. When this.state.current reaches this value the
|
23
|
|
- * timer will stop and call onFinish function.
|
24
|
|
- *
|
25
|
|
- * @public
|
26
|
|
- * @type {number}
|
27
|
|
- */
|
28
|
|
- end: PropTypes.number,
|
29
|
|
-
|
30
|
|
- /**
|
31
|
|
- * The interval in sec for adding this.state.step to this.state.current.
|
32
|
|
- *
|
33
|
|
- * @public
|
34
|
|
- * @type {number}
|
35
|
|
- */
|
36
|
|
- interval: PropTypes.number,
|
37
|
|
-
|
38
|
|
- /**
|
39
|
|
- * The function that will be executed when timer finish (when
|
40
|
|
- * this.state.current === this.props.end)
|
41
|
|
- */
|
42
|
|
- onFinish: PropTypes.func,
|
43
|
|
-
|
44
|
|
- /**
|
45
|
|
- * The start of the timer. The initial value for this.state.current.
|
46
|
|
- *
|
47
|
|
- * @public
|
48
|
|
- * @type {number}
|
49
|
|
- */
|
50
|
|
- start: PropTypes.number,
|
51
|
|
-
|
52
|
|
- /**
|
53
|
|
- * The value which will be added to this.state.current on every step.
|
54
|
|
- *
|
55
|
|
- * @public
|
56
|
|
- * @type {number}
|
57
|
|
- */
|
58
|
|
- step: PropTypes.number,
|
59
|
|
-
|
60
|
|
- /**
|
61
|
|
- * The function to translate human-readable text.
|
62
|
|
- *
|
63
|
|
- * @public
|
64
|
|
- * @type {Function}
|
65
|
|
- */
|
66
|
|
- t: PropTypes.func
|
67
|
|
- };
|
68
|
|
-
|
69
|
|
- /**
|
70
|
|
- * Initializes a new ReloadTimer instance.
|
71
|
|
- *
|
72
|
|
- * @param {Object} props - The read-only properties with which the new
|
73
|
|
- * instance is to be initialized.
|
74
|
|
- * @public
|
75
|
|
- */
|
76
|
|
- constructor(props) {
|
77
|
|
- super(props);
|
78
|
|
-
|
79
|
|
- this.state = {
|
80
|
|
- /**
|
81
|
|
- * Current value(time) of the timer.
|
82
|
|
- *
|
83
|
|
- * @type {number}
|
84
|
|
- */
|
85
|
|
- current: this.props.start,
|
86
|
|
-
|
87
|
|
- /**
|
88
|
|
- * The absolute value of the time from the start of the timer until
|
89
|
|
- * the end of the timer.
|
90
|
|
- *
|
91
|
|
- * @type {number}
|
92
|
|
- */
|
93
|
|
- time: Math.abs(this.props.end - this.props.start)
|
94
|
|
- };
|
95
|
|
- }
|
96
|
|
-
|
97
|
|
- /**
|
98
|
|
- * React Component method that executes once component is mounted.
|
99
|
|
- *
|
100
|
|
- * @inheritdoc
|
101
|
|
- * @returns {void}
|
102
|
|
- * @protected
|
103
|
|
- */
|
104
|
|
- componentDidMount() {
|
105
|
|
- AJS.progressBars.update('#reloadProgressBar', 0);
|
106
|
|
-
|
107
|
|
- const intervalId
|
108
|
|
- = setInterval(
|
109
|
|
- () => {
|
110
|
|
- if (this.state.current === this.props.end) {
|
111
|
|
- clearInterval(intervalId);
|
112
|
|
- this.props.onFinish();
|
113
|
|
- } else {
|
114
|
|
- this.setState((prevState, props) => {
|
115
|
|
- return {
|
116
|
|
- current: prevState.current + props.step
|
117
|
|
- };
|
118
|
|
- });
|
119
|
|
- }
|
120
|
|
- },
|
121
|
|
- Math.abs(this.props.interval) * 1000);
|
122
|
|
- }
|
123
|
|
-
|
124
|
|
- /**
|
125
|
|
- * React Component method that executes once component is updated.
|
126
|
|
- *
|
127
|
|
- * @inheritdoc
|
128
|
|
- * @returns {void}
|
129
|
|
- * @protected
|
130
|
|
- */
|
131
|
|
- componentDidUpdate() {
|
132
|
|
- AJS.progressBars.update(
|
133
|
|
- '#reloadProgressBar',
|
134
|
|
- Math.abs(this.state.current - this.props.start) / this.state.time);
|
135
|
|
- }
|
136
|
|
-
|
137
|
|
- /**
|
138
|
|
- * Implements React's {@link Component#render()}.
|
139
|
|
- *
|
140
|
|
- * @inheritdoc
|
141
|
|
- * @returns {ReactElement|null}
|
142
|
|
- * @public
|
143
|
|
- */
|
144
|
|
- render() {
|
145
|
|
- const { t } = this.props;
|
146
|
|
-
|
147
|
|
- return (
|
148
|
|
- <div>
|
149
|
|
- <div
|
150
|
|
- className = 'aui-progress-indicator'
|
151
|
|
- id = 'reloadProgressBar'>
|
152
|
|
- <span className = 'aui-progress-indicator-value' />
|
153
|
|
- </div>
|
154
|
|
- <span className = 'reload_overlay_text'>
|
155
|
|
- {
|
156
|
|
- this.state.current
|
157
|
|
- }
|
158
|
|
- <span>
|
159
|
|
- { t('dialog.conferenceReloadTimeLeft') }
|
160
|
|
- </span>
|
161
|
|
- </span>
|
162
|
|
- </div>
|
163
|
|
- );
|
164
|
|
- }
|
165
|
|
-}
|
166
|
|
-
|
167
|
|
-export default translate(ReloadTimer);
|