From f4be611c51473359e6d41780f0313c446079e9d3 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Tue, 09 Jun 2026 15:19:24 +0000
Subject: [PATCH] =Switched the /base/options.php to the same pattern as Site.php: a class based approached rather than a filter. Updated Meta.php to play along with the defined fields from there in Meta::forOptions. Had to change openingHoursSpecificationsTrait.php to not use the translater functions __('text','textdomain') for now, as we load before init.
---
assets/js/concise/FrontendFavourites.js | 72 ++++++++++++++++++++++++++----------
1 files changed, 52 insertions(+), 20 deletions(-)
diff --git a/assets/js/concise/FrontendFavourites.js b/assets/js/concise/FrontendFavourites.js
index 47befbe..f986ff1 100644
--- a/assets/js/concise/FrontendFavourites.js
+++ b/assets/js/concise/FrontendFavourites.js
@@ -26,6 +26,11 @@
}
});
+ this.queue = {
+ add: new Map(),
+ remove: new Map(),
+ };
+
this.store = store.favourites;
// this.listStore = window.jvbStore.register(
@@ -71,39 +76,66 @@
// Update button icon
button.innerHTML = jvbSettings.icons[button.classList.contains('favourited') ? 'heart-filled' : 'heart'];
- 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
- );
+ this.checkQueue(action, {
+ target_id: button.dataset.id,
+ action: action,
+ type: button.dataset.type
+ });
+ window.debouncer.schedule('favourites', this.postFavourites.bind(this), 200);
+
}
- async postFavourite(args) {
- await window.auth.fetch(
+ checkQueue(action, item) {
+ switch (action) {
+ case 'add':
+ if (this.queue.remove.has(item.target_id)) {
+ this.queue.remove.delete(item.target_id);
+ }
+ this.queue.add.set(item.target_id, item);
+ break;
+ case 'remove':
+ if (this.queue.add.has(item.target_id)) {
+ this.queue.add.delete(item.target_id);
+ }
+ this.queue.remove.set(item.target_id, item);
+ break;
+ default:
+ return;
+ }
+ }
+ async postFavourites() {
+ console.log(this.queue,'Posting favourites');
+ const response = await window.auth.fetch(
`${jvbSettings.api}favourites`,
{
method: 'POST',
headers: {
'X-Action-Nonce': window.auth.getNonce('favourites')
},
- body: args
+ body: {
+ user: window.auth.getUser(),
+ ... this.queue
+ }
}
);
- if (args.action === 'add') {
- await this.store.setItem(button.dataset.id, {
- target_id: button.dataset.id,
- action: action,
- type: button.dataset.type,
- }).then(()=>{});
+ if (response.ok) {
+ console.log('Posted favourites - clearing queue');
+ //Add or remove from store
+ for (let item of this.queue.add.entries()) {
+ await this.store.setItem(item.target_id,
+ item);
+ }
+ for (let item of this.queue.remove.entries()) {
+ await this.store.delete(item.target_id);
+ }
+ //Clear the favourite queue
+ this.queue.add.clear();
+ this.queue.remove.clear();
} else {
- await this.store.delete(button.dataset.id).then(()=>{});
+ console.log(await response.json(), 'Something went wrong');
+ window.debouncer.schedule('favourites', this.postFavourites.bind(this), 200);
}
}
--
Gitblit v1.10.0