Jake Vanderwerf
2 days ago 235ce5716edc2f7cbe80fdccf26eac7269587839
assets/js/concise/FrontendFavourites.js
@@ -7,6 +7,9 @@
            storeName: 'favourites',
            keyPath: 'id',
            endpoint: 'favourites',
            headers: {
               'X-Action-Nonce': window.auth.getNonce('favourites')
            },
            indexes: [
               {name: 'content', keyPath: 'content'},
               {name: 'listId', keyPath: 'listId'},
@@ -68,12 +71,40 @@
      // Update button icon
      button.innerHTML = jvbSettings.icons[button.classList.contains('favourited') ? 'heart-filled' : 'heart'];
      this.store.setItem(button.dataset.id, {
         target_id: button.dataset.id,
         action: action,
         type: button.dataset.type,
         artist: button.dataset.artist,
      });
      window.debouncer.schedule(
         `favourite-${button.dataset.id}`,
         this.postFavourite({
            user: window.auth.getUser(),
            target_id: button.dataset.id,
            action: action,
            type: button.dataset.type
         }),
         100
      );
   }
   async postFavourite(args) {
      await window.auth.fetch(
         `${jvbSettings.api}favourites`,
         {
            method: 'POST',
            headers: {
               'X-Action-Nonce': window.auth.getNonce('favourites')
            },
            body: args
         }
      );
      if (args.action === 'add') {
         await this.store.setItem(button.dataset.id, {
            target_id: button.dataset.id,
            action: action,
            type: button.dataset.type,
         }).then(()=>{});
      } else {
         await this.store.delete(button.dataset.id).then(()=>{});
      }
   }
   // async toggleFavourite(itemType, itemId) {