From 235ce5716edc2f7cbe80fdccf26eac7269587839 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Mon, 08 Jun 2026 04:38:18 +0000
Subject: [PATCH] =FavouritesManager.php and FavouritesRoutes.php fixes. Moving all logic to FavouritesManager.php. Still some left to do

---
 assets/js/concise/FrontendFavourites.js |   43 +++++++++++++++++++++++++++++++++++++------
 1 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/assets/js/concise/FrontendFavourites.js b/assets/js/concise/FrontendFavourites.js
index e016107..47befbe 100644
--- a/assets/js/concise/FrontendFavourites.js
+++ b/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) {

--
Gitblit v1.10.0