Skip to content

Commit b861773

Browse files
committed
fix
1 parent 80248ca commit b861773

4 files changed

Lines changed: 98 additions & 56 deletions

File tree

public/dist/.vite/manifest.json

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
"src": "src/Assets/js/cardEvent.js",
3434
"isEntry": true,
3535
"imports": [
36-
"src/Assets/js/cardUtilities.js",
3736
"_countUp.min.bkv6uBOp.min.js"
3837
]
3938
},
@@ -43,18 +42,14 @@
4342
"src": "src/Assets/js/cardStream.js",
4443
"isEntry": true,
4544
"imports": [
46-
"src/Assets/js/cardUtilities.js",
4745
"_countUp.min.bkv6uBOp.min.js"
4846
]
4947
},
5048
"src/Assets/js/cardUtilities.js": {
5149
"file": "cardUtilities.min.js",
5250
"name": "cardUtilities",
5351
"src": "src/Assets/js/cardUtilities.js",
54-
"isEntry": true,
55-
"imports": [
56-
"_countUp.min.bkv6uBOp.min.js"
57-
]
52+
"isEntry": true
5853
},
5954
"src/Assets/js/event.js": {
6055
"file": "event.min.js",

src/Assets/js/cardEvent.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
import updateCardWidget from './cardUtilities.js';
1+
import { CountUp } from 'countup.js';
22

3+
let counterAmount;
34
let isFetching = false;
45

6+
if (typeof CountUp !== 'undefined' && CountUp) {
7+
const options = {
8+
separator: ' ',
9+
decimal: ',',
10+
suffix: ' €',
11+
};
12+
counterAmount = new CountUp('card-amount', window.currentAmount / 100, options);
13+
}
14+
15+
if (counterAmount) {
16+
counterAmount.start();
17+
}
18+
519
updateCardWidget();
620
fetchEventData();
721
setInterval(fetchEventData, 10000);
822

923
async function fetchEventData() {
10-
if (isFetching) return;
24+
if (isFetching) {
25+
console.warn('Un appel est déjà en cours, ignoré');
26+
return;
27+
}
28+
1129
isFetching = true;
1230

1331
try {
1432
const response = await fetch(`/widget-event-card/${window.charityEventId}/fetch`);
33+
1534
if (response.ok) {
1635
const json = await response.json();
1736
window.currentAmount = json.amount;
1837
window.donorCount = json.donors ?? window.donorCount;
1938
updateCardWidget();
39+
} else {
40+
console.error('Erreur lors de la récupération des données:', response.status);
2041
}
2142
} catch (error) {
2243
console.error('Erreur réseau:', error);
@@ -25,3 +46,27 @@ async function fetchEventData() {
2546
}
2647
}
2748

49+
function updateCardWidget() {
50+
const currentAmountUnit = window.currentAmount / 100;
51+
const goal = window.goalAmount || 1;
52+
const percentage = Math.min(100, Math.round((currentAmountUnit / goal) * 100));
53+
54+
const barFill = document.getElementById('card-bar-fill');
55+
const percentEl = document.getElementById('card-percentage');
56+
const donorsEl = document.getElementById('card-donors');
57+
58+
if (counterAmount) {
59+
counterAmount.update(currentAmountUnit);
60+
} else {
61+
const amountEl = document.getElementById('card-amount');
62+
if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €';
63+
}
64+
65+
if (barFill) barFill.style.width = percentage + '%';
66+
if (percentEl) percentEl.textContent = percentage + '%';
67+
if (donorsEl) donorsEl.textContent = window.donorCount ?? 0;
68+
}
69+
70+
export {
71+
fetchEventData as fetch
72+
};

src/Assets/js/cardStream.js

Lines changed: 47 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,43 @@
1-
import updateCardWidget from './cardUtilities.js';
1+
import { CountUp } from 'countup.js';
22

3+
let counterAmount;
34
let isFetching = false;
45

6+
if (typeof CountUp !== 'undefined' && CountUp) {
7+
const options = {
8+
separator: ' ',
9+
decimal: ',',
10+
suffix: ' €',
11+
};
12+
counterAmount = new CountUp('card-amount', window.currentAmount / 100, options);
13+
}
14+
15+
if (counterAmount) {
16+
counterAmount.start();
17+
}
18+
519
updateCardWidget();
620
fetchDonationData();
721
setInterval(fetchDonationData, 10000);
822

923
async function fetchDonationData() {
10-
if (isFetching) return;
24+
if (isFetching) {
25+
console.warn('Un appel est déjà en cours, ignoré');
26+
return;
27+
}
28+
1129
isFetching = true;
1230

1331
try {
1432
const response = await fetch(`/widget-stream-card/${window.charityStreamId}/fetch`);
33+
1534
if (response.ok) {
1635
const json = await response.json();
1736
window.currentAmount = json.amount;
1837
window.donorCount = json.donors ?? window.donorCount;
1938
updateCardWidget();
39+
} else {
40+
console.error('Erreur lors de la récupération des données:', response.status);
2041
}
2142
} catch (error) {
2243
console.error('Erreur réseau:', error);
@@ -25,3 +46,27 @@ async function fetchDonationData() {
2546
}
2647
}
2748

49+
function updateCardWidget() {
50+
const currentAmountUnit = window.currentAmount / 100;
51+
const goal = window.goalAmount || 1;
52+
const percentage = Math.min(100, Math.round((currentAmountUnit / goal) * 100));
53+
54+
const barFill = document.getElementById('card-bar-fill');
55+
const percentEl = document.getElementById('card-percentage');
56+
const donorsEl = document.getElementById('card-donors');
57+
58+
if (counterAmount) {
59+
counterAmount.update(currentAmountUnit);
60+
} else {
61+
const amountEl = document.getElementById('card-amount');
62+
if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €';
63+
}
64+
65+
if (barFill) barFill.style.width = percentage + '%';
66+
if (percentEl) percentEl.textContent = percentage + '%';
67+
if (donorsEl) donorsEl.textContent = window.donorCount ?? 0;
68+
}
69+
70+
export {
71+
fetchDonationData as fetch
72+
};

src/Assets/js/cardUtilities.js

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,17 @@
1-
import { CountUp } from 'countup.js';
2-
3-
const countUpOptions = {
4-
separator: ' ',
5-
decimal: ',',
6-
suffix: ' €',
7-
duration: 1.5,
8-
};
9-
10-
let amountCountUp = null;
11-
let lastDonorCount = null;
12-
13-
function initCountUp() {
14-
if (!amountCountUp) {
15-
const amountEl = document.getElementById('card-amount');
16-
if (amountEl && typeof CountUp !== 'undefined') {
17-
const startVal = window.currentAmount / 100;
18-
amountCountUp = new CountUp('card-amount', startVal, countUpOptions);
19-
if (!amountCountUp.error) {
20-
amountCountUp.start();
21-
}
22-
}
23-
}
24-
}
25-
261
function updateCardWidget() {
272
const currentAmountUnit = window.currentAmount / 100;
283
const goal = window.goalAmount || 1;
294
const percentage = Math.min(100, Math.round((currentAmountUnit / goal) * 100));
305

6+
const amountEl = document.getElementById('card-amount');
317
const barFill = document.getElementById('card-bar-fill');
328
const percentEl = document.getElementById('card-percentage');
339
const donorsEl = document.getElementById('card-donors');
3410

35-
// Animate amount with CountUp
36-
initCountUp();
37-
if (amountCountUp) {
38-
amountCountUp.update(currentAmountUnit);
39-
} else {
40-
const amountEl = document.getElementById('card-amount');
41-
if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €';
42-
}
43-
11+
if (amountEl) amountEl.textContent = currentAmountUnit.toLocaleString('fr-FR') + ' €';
4412
if (barFill) barFill.style.width = percentage + '%';
4513
if (percentEl) percentEl.textContent = percentage + '%';
46-
47-
// Animate donor count change
48-
const newDonorCount = window.donorCount ?? 0;
49-
if (donorsEl) {
50-
if (lastDonorCount !== null && newDonorCount !== lastDonorCount) {
51-
donorsEl.classList.add('card-widget__pulse');
52-
setTimeout(() => donorsEl.classList.remove('card-widget__pulse'), 600);
53-
}
54-
donorsEl.textContent = newDonorCount;
55-
}
56-
lastDonorCount = newDonorCount;
14+
if (donorsEl) donorsEl.textContent = window.donorCount ?? 0;
5715
}
5816

5917
export default updateCardWidget;
60-

0 commit comments

Comments
 (0)