From a9b3b28d001941921aa70d37fdc87c758a163a44 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Fri, 05 Jun 2026 16:47:03 +0000
Subject: [PATCH] =Some hefty changes to FeedBlock. Transitioning to loading first page in php to save on extra requests. Got a bit to do yet, but I have to work on Northeh for a bit here.

---
 src/feed/view.js |   45 +++++++++++++++++++++------------------------
 1 files changed, 21 insertions(+), 24 deletions(-)

diff --git a/src/feed/view.js b/src/feed/view.js
index 5abe47d..a8c9946 100644
--- a/src/feed/view.js
+++ b/src/feed/view.js
@@ -7,6 +7,7 @@
 		this.error = window.jvbError;
 		this.cache = new window.jvbCache('feed');
 		this.templates = window.jvbTemplates;
+		this.isFirstLoad = true;
 
 		this.config = {
 			contextId: '',
@@ -17,35 +18,23 @@
 			... this.container.dataset
 		};
 
+
 		this.init();
 	}
 	init() {
 		this.initElements();
 		this.defineTemplates();
+
 		this.initListeners();
 		this.initFilters();
 
-		if ('requestIdleCallback' in window) {
-			requestIdleCallback(() => {
-				this.initStore();
-				this.initTaxonomies();
+		this.initStore();
+		this.initTaxonomies().then(r => {});
 
-				this.processCachedFilters();
-				this.processURLFilters();
-				this.updateFilterUI();
-				this.initGallery();
-			}, { timeout: 2000 });
-		} else {
-			setTimeout(() => {
-				this.initStore();
-				this.initTaxonomies();
-
-				this.processCachedFilters();
-				this.processURLFilters();
-				this.updateFilterUI();
-				this.initGallery();
-			}, 100);
-		}
+		this.processCachedFilters();
+		this.processURLFilters();
+		this.updateFilterUI();
+		this.initGallery();
 	}
 
 	initElements() {
@@ -486,7 +475,8 @@
 				TTL: 6 * 60 * 60 * 1000, //6 hours
 				showLoading: true,
 				required: 'content',
-			}
+			},
+			2
 		);
 
 		this.store = store.feed;
@@ -494,6 +484,14 @@
 		this.store.subscribe((event, data) => {
 			switch (event) {
 				case 'data-loaded':
+					if (this.isFirstLoad) {
+						//We rendered the first page in php already
+						this.isFirstLoad = false;
+						return;
+					}
+					// if (this.store.filters.page === 1) {
+					// 	return;
+					// }
 					this.renderItems(data.items);
 					this.ui.buttons.loadMore.hidden = true;
 					if (this.store.lastResponse && this.store.lastResponse?.has_more) {
@@ -659,10 +657,10 @@
 		];
 
 		if (afterEl) {
-			afterEl.textContent = `After ${item.number - 1} Tx`;
+			afterEl.textContent = `After ${item.number} Tx`;
 		}
 		if (number) {
-			number.textContent = item.number - 1;
+			number.textContent = item.number;
 		}
 		if (started) {
 			this.formatTimeField(started, item.fields.timeline[0]['post_date']);
@@ -710,7 +708,6 @@
 					if (manyRefs.fields) {
 						for (let field of manyRefs.fields) {
 							if (isTimeline && ['timeline','number'].includes(field.dataset.field)) continue;
-
 							const value = Object.hasOwn(data.fields, field.dataset.field)? data.fields[field.dataset.field] : false;
 							if (!value) {
 								field.remove();

--
Gitblit v1.10.0