Jake Vanderwerf
2025-10-18 b0194e10a87e16797a568d8a30d53ebecd27d8a4
assets/js/concise/FrontendFavourites.js
@@ -3,9 +3,13 @@
      // Initialize DataStore for queue persistence
      this.store = new window.jvbStore({
         name: 'favourites',
         storeName: 'favourites',
         endpoint: 'favourites',
         useIndexedDB: true,
         TTL: Infinity,
         indexes: [
            {name: 'content', keyPath: 'content'},
            {name: 'listId', keyPath: 'listId'},
         ],
         TTL: 86400000,
         showLoading: false,
         filters: {
            user: jvbSettings.currentUser,
@@ -17,6 +21,14 @@
         }
      });
      this.listStore = new window.jvbStore({
         name: 'favourites_lists',
         storeName: 'lists',
         keyPath: 'listId',
         endpoint: 'favourites/lists',
         TTL: 86400000,
      })
      this.store.subscribe((event, data) => {
         switch (event) {
            case 'data-fetched':
@@ -61,12 +73,110 @@
      });
   }
   isFavourited(content, id){
      if(!jvbSettings.currentUser){
         return false;
      }
      let item = this.store.getItem(id);
      return (item) ? item.action === 'add' : false;
   // async toggleFavourite(itemType, itemId) {
   //    const favId = `${this.userId}_${itemType}_${itemId}`;
   //    const existing = this.store.get(favId);
   //
   //    if (existing) {
   //       // Remove favorite
   //       await this.store.delete(favId);
   //
   //       // Queue for server deletion
   //       if (window.jvbQueue) {
   //          window.jvbQueue.addOperation({
   //             type: 'remove_favourite',
   //             endpoint: 'favourites',
   //             data: { favId }
   //          });
   //       }
   //
   //       return false; // Not favorited anymore
   //
   //    } else {
   //       // Add favorite
   //       const favourite = {
   //          id: favId,
   //          userId: this.userId,
   //          itemType,
   //          itemId,
   //          listId: 'default',
   //          timestamp: Date.now()
   //       };
   //
   //       await this.store.save(favourite);
   //
   //       // Queue for server save
   //       if (window.jvbQueue) {
   //          window.jvbQueue.addOperation({
   //             type: 'add_favourite',
   //             endpoint: 'favourites',
   //             data: favourite
   //          });
   //       }
   //
   //       return true; // Now favorited
   //    }
   // }
   // async createList(name, visibility = 'private') {
   //    const list = {
   //       listId: `list_${Date.now()}`,
   //       userId: this.userId,
   //       name,
   //       visibility,
   //       created: Date.now(),
   //       itemCount: 0
   //    };
   //
   //    await this.listsStore.save(list);
   //
   //    // Queue for server
   //    if (window.jvbQueue) {
   //       window.jvbQueue.addOperation({
   //          type: 'create_list',
   //          endpoint: 'favourite-lists',
   //          data: list
   //       });
   //    }
   //
   //    return list;
   // }
   //
   // async addToList(listId, itemType, itemId) {
   //    const favId = `${this.userId}_${itemType}_${itemId}_${listId}`;
   //
   //    const favourite = {
   //       id: favId,
   //       userId: this.userId,
   //       itemType,
   //       itemId,
   //       listId,
   //       timestamp: Date.now()
   //    };
   //
   //    await this.store.save(favourite);
   //
   //    // Update list count
   //    const list = this.listsStore.get(listId);
   //    if (list) {
   //       list.itemCount++;
   //       await this.listsStore.save(list);
   //    }
   //
   //    // Queue for server
   //    if (window.jvbQueue) {
   //       window.jvbQueue.addOperation({
   //          type: 'add_to_list',
   //          endpoint: 'favourites',
   //          data: favourite
   //       });
   //    }
   // }
   isFavourited(itemType, itemId) {
      const favId = `${this.userId}_${itemType}_${itemId}`;
      return this.store.get(favId) !== undefined;
   }
}
document.addEventListener('DOMContentLoaded', function() {