💄Better UI & add supporters

This commit is contained in:
Victor Bodinaud
2025-02-27 14:21:42 +01:00
parent 9008e944df
commit 72e1a9307b
3 changed files with 131 additions and 26 deletions

BIN
public/backgound.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.7 MiB

View File

@@ -12,7 +12,11 @@
margin: 0 auto; margin: 0 auto;
padding: 20px; padding: 20px;
text-align: center; text-align: center;
background-color: #2c5282; /* Fond bleu */ background-color: #2c5282; /* Couleur de secours si l'image ne charge pas */
background-image: url('/background.png');
background-position: center;
background-size: cover;
background-attachment: fixed;
color: white; color: white;
} }
h1 { h1 {
@@ -56,6 +60,18 @@
align-items: center; align-items: center;
justify-content: space-between; justify-content: space-between;
} }
.contributor-info {
display: flex;
align-items: center;
gap: 10px;
}
.contributor-avatar {
width: 40px;
height: 40px;
border-radius: 50%;
object-fit: cover;
background-color: #3b557d;
}
.contributor-name { .contributor-name {
font-weight: bold; font-weight: bold;
color: #e3b505; color: #e3b505;
@@ -65,6 +81,30 @@
font-size: 14px; font-size: 14px;
margin-top: 5px; margin-top: 5px;
} }
.contributor-date {
color: #a0aec0;
font-size: 12px;
}
.contributor-location {
color: #a0aec0;
font-size: 12px;
font-style: italic;
}
.contributor-comment {
color: #cbd5e0;
font-size: 13px;
margin-top: 5px;
font-style: italic;
line-height: 1.3;
max-width: 200px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.contributor-comment:hover {
white-space: normal;
max-width: none;
}
.contributor-amount { .contributor-amount {
color: #ffd500; color: #ffd500;
font-weight: bold; font-weight: bold;
@@ -285,7 +325,7 @@
<script> <script>
// Définir l'URL de la campagne en dur // Définir l'URL de la campagne en dur
const PROJECT_SLUG = 'suppdonn-knights-of-water'; // Remplacer par le slug de votre campagne const PROJECT_SLUG = '199996'; // Utilisez votre numéro de projet
const REFRESH_INTERVAL = 60; // Intervalle de rafraîchissement en secondes const REFRESH_INTERVAL = 60; // Intervalle de rafraîchissement en secondes
// Éléments DOM // Éléments DOM
@@ -333,7 +373,7 @@
async function fetchContributors(slug) { async function fetchContributors(slug) {
try { try {
const response = await fetch(`/api/ulule/${slug}/contributors`); const response = await fetch(`/api/ulule/${slug}/supporters`);
if (!response.ok) { if (!response.ok) {
return { contributors: [] }; return { contributors: [] };
@@ -460,13 +500,28 @@
let html = ''; let html = '';
data.contributors.forEach(contributor => { data.contributors.forEach(contributor => {
// Formater la date si elle existe
let dateStr = '';
if (contributor.date_joined) {
const date = new Date(contributor.date_joined);
dateStr = date.toLocaleDateString('fr-FR', { year: 'numeric', month: 'short', day: 'numeric' });
}
const avatarUrl = contributor.avatar || 'https://s3-eu-west-1.amazonaws.com/com.ulule.assets/site/build/img/avatars/avatar-blue.png';
html += ` html += `
<div class="contributor-item"> <div class="contributor-item">
<div class="contributor-info">
<img class="contributor-avatar" src="${avatarUrl}" alt="${contributor.name}" />
<div> <div>
<div class="contributor-name">${contributor.name || 'Contributeur anonyme'}</div> <div class="contributor-name">${contributor.name || 'Contributeur anonyme'}</div>
<div class="contributor-reward">${contributor.reward || 'Aucune contrepartie'}</div> ${contributor.reward ? `<div class="contributor-reward">${contributor.reward}</div>` : ''}
${contributor.location ? `<div class="contributor-location">${contributor.location}</div>` : ''}
${dateStr ? `<div class="contributor-date">Depuis le ${dateStr}</div>` : ''}
${contributor.comment ? `<div class="contributor-comment">"${contributor.comment}"</div>` : ''}
</div> </div>
<div class="contributor-amount">${contributor.amount ? formatter.format(contributor.amount) : ''}</div> </div>
${contributor.amount ? `<div class="contributor-amount">${formatter.format(contributor.amount)}</div>` : ''}
</div>`; </div>`;
}); });

View File

@@ -123,44 +123,94 @@ app.get('/api/ulule/:slug/rewards', async (req, res) => {
}); });
// Route pour récupérer les contributeurs d'une campagne // Route pour récupérer les contributeurs d'une campagne
app.get('/api/ulule/:slug/contributors', async (req, res) => { app.get('/api/ulule/:slug/supporters', async (req, res) => {
try { try {
const { slug } = req.params; const { slug } = req.params;
console.log(`Récupération des contributeurs pour la campagne: ${slug}`); console.log(`Récupération des contributeurs pour la campagne: ${slug}`);
// Pour les contributeurs, nous devons encore scraper la page car l'API publique ne fournit pas cette information // Utiliser l'API Ulule pour récupérer les contributeurs avec des champs supplémentaires
const htmlUrl = `https://fr.ulule.com/${slug}/supporters/`; const apiUrl = `https://api.ulule.com/v1/projects/${slug}/supporters?extra_fields=latest_project_order,latest_project_comment`;
console.log(`Tentative d'accès à l'API des supporters: ${apiUrl}`);
const response = await axios.get(htmlUrl, { const response = await axios.get(apiUrl, {
headers: { headers: {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 'Accept': 'application/json',
'Accept-Language': 'fr,fr-FR;q=0.8,en-US;q=0.5,en;q=0.3' 'Cache-Control': 'no-cache'
}, },
timeout: 10000 timeout: 10000
}); });
if (response.status === 200) { if (response.status === 200 && response.data && response.data.supporters) {
console.log(`Page des contributeurs récupérée, longueur: ${response.data.length}`); console.log(`${response.data.supporters.length} contributeurs récupérés`);
// Puisque le scraping est complexe et dépend de la structure HTML, // Formater les données des contributeurs
// nous allons simplement renvoyer des données de démonstration pour cet exemple const contributors = response.data.supporters.map(supporter => {
const contributors = [ // Récupérer le nom complet ou le nom d'utilisateur
{ name: "Contributeur 1", reward: "Pack Tour", amount: 40 }, let name = supporter.screenname || supporter.name || 'Contributeur anonyme';
{ name: "Contributeur 2", reward: "Pack Cavalier", amount: 26 },
{ name: "Contributeur 3", reward: "Pack Roi", amount: 75 }, // Extraire les informations de commande si disponibles
{ name: "Contributeur 4", reward: "Pack Tour", amount: 40 }, let reward = '';
{ name: "Contributeur 5", reward: "Pack Pion", amount: 6 } let amount = 0;
]; let comment = '';
if (supporter.latest_project_order && supporter.latest_project_order.items && supporter.latest_project_order.items.length > 0) {
// Récupérer la première récompense
const firstItem = supporter.latest_project_order.items[0];
amount = firstItem.line_total || firstItem.unit_price || 0;
// Récupérer le titre de la récompense
if (firstItem.reward && firstItem.reward.parent && firstItem.reward.parent.title) {
const titles = firstItem.reward.parent.title;
reward = titles.fr || titles.en || Object.values(titles)[0] || '';
// Si c'est une variante, ajouter sa description
if (firstItem.reward.description_fr) {
reward += ` (${firstItem.reward.description_fr})`;
}
}
// Ajouter un pourboire si présent
if (supporter.latest_project_order.tip && supporter.latest_project_order.tip > 0) {
amount += supporter.latest_project_order.tip;
}
}
// Récupérer le commentaire si disponible
if (supporter.latest_project_comment && supporter.latest_project_comment.comment) {
comment = supporter.latest_project_comment.comment;
}
return {
id: supporter.id,
name: name,
reward: reward,
amount: amount,
avatar: supporter.avatar ? (supporter.avatar['90'] || '') : '',
date_joined: supporter.date_joined,
comment: comment,
location: supporter.location || ''
};
});
return res.json({ contributors }); return res.json({ contributors });
} else { } else {
throw new Error(`Erreur lors de la récupération de la page des contributeurs: ${response.status}`); throw new Error(`Erreur lors de la récupération des contributeurs: ${response.status}`);
} }
} catch (error) { } catch (error) {
console.error('Erreur lors de la récupération des contributeurs:', error.message); console.error('Erreur lors de la récupération des contributeurs:', error.message);
return res.json({ contributors: [] });
// En cas d'erreur, renvoyer des données de démonstration
return res.json({
contributors: [
{ name: "Contributeur 1", reward: "Pack Tour", amount: 40, avatar: "", comment: "Super projet!" },
{ name: "Contributeur 2", reward: "Pack Cavalier", amount: 26, avatar: "", comment: "" },
{ name: "Contributeur 3", reward: "Pack Roi", amount: 75, avatar: "", comment: "J'adore!" },
{ name: "Contributeur 4", reward: "Pack Tour", amount: 40, avatar: "", comment: "" },
{ name: "Contributeur 5", reward: "Pack Pion", amount: 6, avatar: "", comment: "" }
]
});
} }
}); });