| | |
| | | // Update button icon |
| | | button.innerHTML = jvbSettings.icons[button.classList.contains('favourited') ? 'heart-filled' : 'heart']; |
| | | |
| | | this.store.setItem(button.dataset.id, { |
| | | 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, |
| | | artist: button.dataset.artist, |
| | | }); |
| | | }).then(()=>{}); |
| | | } else { |
| | | await this.store.delete(button.dataset.id).then(()=>{}); |
| | | } |
| | | } |
| | | |
| | | // async toggleFavourite(itemType, itemId) { |