|
1 | | -/* global customElements, HTMLElement */ |
| 1 | +/* global customElements, HTMLElement, prplUpdatePreviousMonthBadgeProgressBar */ |
2 | 2 | /* |
3 | 3 | * Web Component: prpl-gauge |
4 | 4 | * |
@@ -187,101 +187,3 @@ const prplUpdateRaviGauge = ( pointsDiff ) => { |
187 | 187 | } |
188 | 188 | } |
189 | 189 | }; |
190 | | - |
191 | | -const prplUpdatePreviousMonthBadgeProgressBar = ( pointsDiff ) => { |
192 | | - const progressBars = document.querySelectorAll( |
193 | | - '.prpl-previous-month-badge-progress-bar-wrapper prpl-badge-progress-bar' |
194 | | - ); |
195 | | - |
196 | | - // Bail early if no badge progress bars are found. |
197 | | - if ( ! progressBars.length ) { |
198 | | - return; |
199 | | - } |
200 | | - |
201 | | - // Get the 1st incomplete badge progress bar. |
202 | | - const progressBar = |
203 | | - parseInt( progressBars[ 0 ]?.getAttribute( 'data-points' ) ) >= |
204 | | - parseInt( progressBars[ 0 ]?.getAttribute( 'data-max-points' ) ) |
205 | | - ? progressBars[ 1 ] |
206 | | - : progressBars[ 0 ]; |
207 | | - |
208 | | - // Bail early if no badge progress bar is found. |
209 | | - if ( ! progressBar ) { |
210 | | - return; |
211 | | - } |
212 | | - |
213 | | - // Get the badge progress bar properties. |
214 | | - const badgeId = progressBar.getAttribute( 'data-badge-id' ); |
215 | | - const badgePoints = progressBar.getAttribute( 'data-points' ); |
216 | | - const badgeMaxPoints = progressBar.getAttribute( 'data-max-points' ); |
217 | | - const badgeProgress = customElements.get( 'prpl-badge-progress-bar' ); |
218 | | - const badgeNewPoints = parseInt( badgePoints ) + pointsDiff; |
219 | | - |
220 | | - // Create a new badge progress bar. |
221 | | - const newProgressBar = new badgeProgress( |
222 | | - badgeId, |
223 | | - badgeNewPoints, |
224 | | - badgeMaxPoints |
225 | | - ); |
226 | | - newProgressBar.setAttribute( 'data-badge-id', badgeId ); |
227 | | - newProgressBar.setAttribute( 'data-points', badgeNewPoints ); |
228 | | - newProgressBar.setAttribute( 'data-max-points', badgeMaxPoints ); |
229 | | - |
230 | | - // Replace the old badge progress bar with the new one. |
231 | | - progressBar.replaceWith( newProgressBar ); |
232 | | - |
233 | | - // Update the remaining points. |
234 | | - const remainingPointsEl = document.querySelector( |
235 | | - `.prpl-previous-month-badge-progress-bar-wrapper[data-badge-id="${ badgeId }"] .prpl-previous-month-badge-progress-bar-remaining` |
236 | | - ); |
237 | | - |
238 | | - if ( remainingPointsEl ) { |
239 | | - remainingPointsEl.textContent = remainingPointsEl.textContent.replace( |
240 | | - remainingPointsEl.getAttribute( 'data-remaining' ), |
241 | | - badgeMaxPoints - badgeNewPoints |
242 | | - ); |
243 | | - remainingPointsEl.setAttribute( |
244 | | - 'data-remaining', |
245 | | - badgeMaxPoints - badgeNewPoints |
246 | | - ); |
247 | | - } |
248 | | - |
249 | | - // Update the previous month badge points number. |
250 | | - const badgePointsNumberEl = document.querySelector( |
251 | | - `.prpl-previous-month-badge-progress-bar-wrapper[data-badge-id="${ badgeId }"] .prpl-widget-previous-ravi-points-number` |
252 | | - ); |
253 | | - if ( badgePointsNumberEl ) { |
254 | | - badgePointsNumberEl.textContent = badgeNewPoints + 'pt'; |
255 | | - } |
256 | | - |
257 | | - // If the previous month badge is completed, update badge elements. |
258 | | - if ( badgeNewPoints >= parseInt( badgeMaxPoints ) ) { |
259 | | - document |
260 | | - .querySelectorAll( |
261 | | - `.prpl-badge-row-wrapper-inner .prpl-badge prpl-badge[complete="false"][badge-id="${ badgeId }"]` |
262 | | - ) |
263 | | - ?.forEach( ( badge ) => { |
264 | | - badge.setAttribute( 'complete', 'true' ); |
265 | | - } ); |
266 | | - |
267 | | - // Remove the previous month badge progress bar. |
268 | | - document |
269 | | - .querySelector( |
270 | | - `.prpl-previous-month-badge-progress-bar-wrapper[data-badge-id="${ badgeId }"]` |
271 | | - ) |
272 | | - ?.remove(); |
273 | | - |
274 | | - // If there are no more progress bars, remove the previous month badge progress bar wrapper. |
275 | | - if ( |
276 | | - ! document.querySelector( |
277 | | - '.prpl-previous-month-badge-progress-bar-wrapper' |
278 | | - ) |
279 | | - ) { |
280 | | - document |
281 | | - .querySelector( |
282 | | - '.prpl-previous-month-badge-progress-bars-wrapper' |
283 | | - ) |
284 | | - ?.remove(); |
285 | | - } |
286 | | - } |
287 | | -}; |
0 commit comments