Skip to content

Commit 5949012

Browse files
authored
Merge branch 'develop' into filip/v18/badges-alt-attribute
2 parents 5e3829b + 42ae3af commit 5949012

2 files changed

Lines changed: 37 additions & 20 deletions

File tree

assets/js/web-components/prpl-badge-progress-bar.js

Lines changed: 33 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,6 @@ const prplUpdatePreviousMonthBadgeProgressBar = ( pointsDiff ) => {
112112
`.prpl-previous-month-badge-progress-bar-wrapper[data-badge-id="${ badgeId }"] .prpl-previous-month-badge-progress-bar-remaining`
113113
);
114114

115-
const remainingPointsEls = document.querySelectorAll(
116-
`.prpl-previous-month-badge-progress-bar-wrapper .prpl-previous-month-badge-progress-bar-remaining`
117-
);
118-
119115
if ( remainingPointsEl ) {
120116
remainingPointsEl.textContent = remainingPointsEl.textContent.replace(
121117
remainingPointsEl.getAttribute( 'data-remaining' ),
@@ -125,21 +121,6 @@ const prplUpdatePreviousMonthBadgeProgressBar = ( pointsDiff ) => {
125121
'data-remaining',
126122
badgeMaxPoints - badgeNewPoints
127123
);
128-
129-
remainingPointsEls.forEach( ( pointsEl ) => {
130-
const totalPoints = pointsEl.getAttribute(
131-
'data-remaining-total-points'
132-
);
133-
pointsEl.setAttribute(
134-
'data-remaining-total-points',
135-
totalPoints - pointsDiff
136-
);
137-
138-
const numberEl = pointsEl.querySelector( '.number' );
139-
if ( numberEl ) {
140-
numberEl.textContent = totalPoints - pointsDiff;
141-
}
142-
} );
143124
}
144125

145126
// Update the previous month badge points number.
@@ -181,3 +162,36 @@ const prplUpdatePreviousMonthBadgeProgressBar = ( pointsDiff ) => {
181162
}
182163
}
183164
};
165+
166+
/**
167+
* Update the previous month badge counters.
168+
*
169+
* @param {number} pointsDiff The points difference.
170+
*
171+
* @return {void}
172+
*/
173+
// eslint-disable-next-line no-unused-vars
174+
const prplUpdatePreviousMonthBadgeCounters = ( pointsDiff ) => {
175+
const remainingPointsEls = document.querySelectorAll(
176+
`.prpl-previous-month-badge-progress-bar-wrapper .prpl-previous-month-badge-progress-bar-remaining`
177+
);
178+
179+
if ( ! remainingPointsEls.length ) {
180+
return;
181+
}
182+
183+
remainingPointsEls.forEach( ( pointsEl ) => {
184+
const totalPoints = pointsEl.getAttribute(
185+
'data-remaining-total-points'
186+
);
187+
pointsEl.setAttribute(
188+
'data-remaining-total-points',
189+
totalPoints - pointsDiff
190+
);
191+
192+
const numberEl = pointsEl.querySelector( '.number' );
193+
if ( numberEl ) {
194+
numberEl.textContent = totalPoints - pointsDiff;
195+
}
196+
} );
197+
};

assets/js/web-components/prpl-gauge.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* global customElements, HTMLElement, prplUpdatePreviousMonthBadgeProgressBar */
1+
/* global customElements, HTMLElement, prplUpdatePreviousMonthBadgeProgressBar, prplUpdatePreviousMonthBadgeCounters */
22
/*
33
* Web Component: prpl-gauge
44
*
@@ -152,6 +152,9 @@ const prplUpdateRaviGauge = ( pointsDiff ) => {
152152
oldCounter.textContent = newValue + 'pt';
153153
}
154154

155+
// Update the previous month badge counters.
156+
prplUpdatePreviousMonthBadgeCounters( pointsDiff );
157+
155158
// Mark badge as completed, in the a Monthly badges widgets, if we reached the max points.
156159
if ( newValue >= parseInt( gaugeProps.max ) ) {
157160
// We have multiple badges, one in widget and the other in the popover.

0 commit comments

Comments
 (0)