Jake Vanderwerf
3 days ago ba1e1ccf869b818f7a7a897264dfea05563a7796
assets/js/concise/UserInteractions.js
@@ -1,5 +1,4 @@
/**
 * FrontendInteractions - Unified class for frontend user interactions
 * Handles: Favourites, Votes, and related user actions
 */
class UserInteractions {
@@ -8,8 +7,10 @@
         return; // Don't initialize if not logged in
      }
      this.stores = {};
      // Initialize favourites store
      this.favouritesStore = window.jvbStore.register(
      this.stores['favourites'] = window.jvbStore.register(
         'favourites',
         {
            storeName: 'favourites',
@@ -32,7 +33,7 @@
      );
      // Initialize favourites lists store
      this.listsStore = window.jvbStore.register(
      this.stores['lists'] = window.jvbStore.register(
         'favourites_lists',
         {
            storeName: 'lists',
@@ -43,7 +44,7 @@
      );
      // Initialize votes store
      this.votesStore = window.jvbStore.register(
      this.stores['votes'] = window.jvbStore.register(
         'votes',
         {
            storeName: 'votes',
@@ -177,32 +178,10 @@
   }
}
// Lazy initialization using requestIdleCallback for better performance
function initFrontendInteractions() {
   if (window.auth.getUser()) {
      window.jvbInteractions = new FrontendInteractions();
   }
}
// Initialize after DOM is ready but without blocking render
if ('requestIdleCallback' in window) {
   requestIdleCallback(async function() {
      window.auth.subscribe((event) => {
         if (event === 'auth-loaded') {
            if (document.readyState === 'loading') {
               document.addEventListener('DOMContentLoaded', initFrontendInteractions);
            } else {
               initFrontendInteractions();
            }
         }
      });
   });
} else {
   // Fallback for browsers without requestIdleCallback
   if (document.readyState === 'loading') {
      document.addEventListener('DOMContentLoaded', initFrontendInteractions);
   } else {
      setTimeout(initFrontendInteractions, 1);
      window.jvbInteractions = new UserInteractions();
   }
}