@bebranded/bb-contents 1.0.46-beta → 1.0.47-beta

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/bb-contents.js +37 -5
  2. package/package.json +1 -1
package/bb-contents.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * BeBranded Contents
3
3
  * Contenus additionnels français pour Webflow
4
- * @version 1.0.46-beta
4
+ * @version 1.0.47-beta
5
5
  * @author BeBranded
6
6
  * @license MIT
7
7
  * @website https://www.bebranded.xyz
@@ -22,7 +22,7 @@
22
22
 
23
23
  // Configuration
24
24
  const config = {
25
- version: '1.0.46-beta',
25
+ version: '1.0.47-beta',
26
26
  debug: true, // Activé temporairement pour debug
27
27
  prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
28
28
  youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
@@ -723,12 +723,38 @@
723
723
  const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}_${language}`;
724
724
  const cachedData = this.cache.get(cacheKey);
725
725
 
726
- if (cachedData) {
726
+ if (cachedData && cachedData.value) {
727
727
  // Données YouTube récupérées du cache (économie API)
728
+ console.log('[DEBUG] Using cached YouTube data for element');
728
729
  this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
729
730
  return;
730
731
  }
731
732
 
733
+ // Vérifier si un appel API est déjà en cours pour cette clé
734
+ const loadingKey = `loading_${cacheKey}`;
735
+ if (window[loadingKey]) {
736
+ console.log('[DEBUG] API call already in progress, waiting...');
737
+ // Attendre que l'autre appel se termine
738
+ const checkLoading = () => {
739
+ if (!window[loadingKey]) {
740
+ // L'autre appel est terminé, vérifier le cache
741
+ const newCachedData = this.cache.get(cacheKey);
742
+ if (newCachedData && newCachedData.value) {
743
+ this.generateYouTubeFeed(container, template, newCachedData.value, allowShorts, language);
744
+ } else {
745
+ container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Erreur de chargement</div>';
746
+ }
747
+ } else {
748
+ setTimeout(checkLoading, 100);
749
+ }
750
+ };
751
+ checkLoading();
752
+ return;
753
+ }
754
+
755
+ // Marquer qu'un appel API est en cours
756
+ window[loadingKey] = true;
757
+
732
758
  // Afficher un loader
733
759
  container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
734
760
 
@@ -753,11 +779,17 @@
753
779
  // Données YouTube mises en cache pour 24h (économie API)
754
780
 
755
781
  this.generateYouTubeFeed(container, template, data, allowShorts, language);
782
+
783
+ // Libérer le verrou
784
+ window[loadingKey] = false;
756
785
  })
757
786
  .catch(error => {
758
787
  console.error('[DEBUG] YouTube API error:', error);
759
788
  // Erreur dans le module youtube
760
789
 
790
+ // Libérer le verrou en cas d'erreur
791
+ window[loadingKey] = false;
792
+
761
793
  // En cas d'erreur, essayer de récupérer du cache même expiré
762
794
  const expiredCache = localStorage.getItem(cacheKey);
763
795
  if (expiredCache) {
@@ -779,8 +811,8 @@
779
811
 
780
812
  generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
781
813
  console.log('[DEBUG] generateYouTubeFeed called with data:', data);
782
- if (!data.items || data.items.length === 0) {
783
- console.log('[DEBUG] No videos found in data');
814
+ if (!data || !data.items || data.items.length === 0) {
815
+ console.log('[DEBUG] No videos found in data or data is undefined');
784
816
  container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
785
817
  return;
786
818
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bebranded/bb-contents",
3
- "version": "1.0.46-beta",
3
+ "version": "1.0.47-beta",
4
4
  "description": "Contenus additionnels français pour Webflow",
5
5
  "main": "bb-contents.js",
6
6
  "scripts": {