From 18e7e415339ccc9adf8ade562f93abef606da16d Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Wed, 26 Aug 2026 22:24:18 +0000
Subject: [PATCH] =Cache::connects throughout codebase refactored

---
 inc/managers/ScriptLoader.php |  248 +++++++++++++++++++++++++++++++++++++++++++++++--
 1 files changed, 235 insertions(+), 13 deletions(-)

diff --git a/inc/managers/ScriptLoader.php b/inc/managers/ScriptLoader.php
index 623eb88..c433857 100644
--- a/inc/managers/ScriptLoader.php
+++ b/inc/managers/ScriptLoader.php
@@ -1,12 +1,30 @@
 <?php
+
+if (!defined('ABSPATH')) {
+	exit; // Exit if accessed directly
+}
+
+use JVBase\base\Site;
+use JVBase\registrar\Registrar;
+use JVBase\rest\routes\LoginRoutes;
+
 add_action('init', 'jvbRegisterScripts', 5);
 
 function jvbRegisterScripts() {
-	$version = '1.1.33';
+	$version = '1.1.68';
 	$strategy = [
 		'strategy'	=> 'defer',
 		'in_footer'	=> true
 	];
+	wp_register_script(
+		'jvb-login',
+		JVB_URL.'assets/js/min/login.min.js',
+		[
+			'jvb-auth',
+			'jvb-form',
+		],
+		$version
+	);
 
 	wp_register_style(
 		'jvb-form',
@@ -44,16 +62,18 @@
 		$version,
 		$strategy
 	);
-	wp_register_script(
-		'jvb-interactions',
-		JVB_URL.'assets/js/min/interactions.min.js',
-		[
-			'jvb-queue',
-			'jvb-data-store'
-		],
-		$version,
-		$strategy
-	);
+	wp_localize_script('jvb-auth', 'jvbBase', ['base' => BASE]);
+	wp_localize_script('jvb-auth', 'jvbAuth', LoginRoutes::auth());
+//	wp_register_script(
+//		'jvb-interactions',
+//		JVB_URL.'assets/js/min/interactions.min.js',
+//		[
+//			'jvb-queue',
+//			'jvb-data-store'
+//		],
+//		$version,
+//		$strategy
+//	);
 
 
 	wp_register_script(
@@ -62,7 +82,6 @@
 		[
 			'jvb-queue',
 			'jvb-data-store',
-			'jvb-interactions',
 		],
 		$version,
 		$strategy
@@ -74,7 +93,6 @@
 		[
 			'jvb-queue',
 			'jvb-data-store',
-			'jvb-interactions',
 		],
 		$version,
 		$strategy
@@ -212,6 +230,7 @@
 		$strategy
 	);
 
+
 	//SEO Admin
 	wp_register_script(
 		'jvb-schema',
@@ -557,3 +576,206 @@
 		$strategy
 	);
 }
+
+/**
+ * Scripts
+ */
+add_action('wp_enqueue_scripts', 'jvbScripts', 10);
+
+function jvbScripts():void
+{
+	add_action('wp_head', 'jvbInlineNavStyles');
+
+	if (Site::has('dashboard')) {
+		wp_enqueue_script('jvb-queue');
+	}
+
+	wp_enqueue_script('jvb-auth');
+	wp_enqueue_script('jvb-settings');
+	wp_enqueue_script('jvb-navigation');
+//    wp_enqueue_script('jvb-ui');
+//    wp_enqueue_script('jvb-media');
+	wp_enqueue_script('jvb-gallery');
+	wp_enqueue_script('jvb-cache');
+
+
+	$interactions = [];
+	if (Site::has('favourites')) {
+		$interactions[] = 'favourites';
+	}
+	if (!empty(Registrar::withFeature('karma'))) {
+		$interactions[] = 'karma';
+	}
+	if (Site::has('notifications')) {
+		$interactions[] = 'notifications';
+	}
+
+	if (!empty($interactions)) {
+		foreach($interactions as $interaction) {
+			wp_enqueue_script('jvb-'.$interaction);
+		}
+	}
+
+
+	$queue = [
+		'api' => rest_url('jvb/v1/'),
+		'redirect' => get_home_url(null, '/login/'),
+		'labels' => Registrar::getLabels(),
+	];
+
+	wp_localize_script('jvb-auth', 'jvbSettings', $queue);
+
+
+	$initUserSettings = 'async function initUserItems() {
+	if (!jvbSettings.currentUser) return;
+
+	window.userFavourites = {};
+	window.userVotes = {};
+	';
+	if (Site::has('favourites')) {
+		wp_enqueue_script('jvb-favourites');
+		$initUserSettings .= '
+		//Fetch user favourites
+		try {
+			const result = await window.jvbCache.fetchWithCache(
+				`${jvbSettings.api}favourites?all=true`,
+                {
+                    method: \'GET\',
+                    headers: {\'X-WP-Nonce\': jvbSettings.nonce}
+                }
+            );
+
+            if (result && result.favourites) {
+				for (const key in result.favourites) {
+					window.userFavourites[key] = new Set();
+					result.favourites[key].forEach(id => {
+						window.userFavourites[key].add(parseInt(id));
+					});
+                }
+            }
+        } catch (error) {
+			console.error(\'Failed to fetch user favourites:\', error);
+		}';
+	}
+
+	if (!empty(Registrar::withFeature('karma'))) {
+		wp_enqueue_script('jvb-votes');
+		$initUserSettings .= '// Fetch user votes
+        try {
+			const result = await window.jvbCache.fetchWithCache(
+				`${jvbSettings.api}vote?user=${jvbSettings.currentUser}`,
+                {
+                    method: \'GET\',
+                    headers: {\'X-WP-Nonce\': jvbSettings.nonce}
+                },
+                {forceRefresh: true}
+            );
+
+            window.userVotes = {};
+            if (result) {
+				for (const key in result) {
+					window.userVotes[key] = new Map();
+					for (const [id, vote] of Object.entries(result[key])) {
+						window.userVotes[key].set(parseInt(id), vote);
+					}
+                }
+            }
+        } catch (error) {
+			console.error(\'Failed to fetch user votes:\', error);
+		}';
+	}
+
+	$initUserSettings .= '} initUserItems();';
+
+//	wp_add_inline_script('jvb-queue', $initUserSettings, 'after');
+
+
+	if (is_search() ||
+		is_tax(BASE.'shop') ||
+		is_singular(BASE.'artist') ||
+		jvbIsDirectory()
+	) {
+		wp_enqueue_script('jvb-page-nav');
+	}
+
+	if (has_block('jvb/summaryBlock')) {
+		wp_enqueue_script('jvb-page-nav');
+	}
+
+	// Only load on single shop pages or other relevant pages
+	if (is_tax(BASE.'shop') ||
+		is_singular(BASE.'partner')) {
+		$ID = get_queried_object_id();
+		if (is_tax()) {
+			$check = get_term_meta($ID, BASE.'has_map', true);
+		} else {
+			$check = get_post_meta($ID, BASE.'has_map', true);
+		}
+
+//        if ($check && $check !== '') {
+////            wp_enqueue_script(
+////                'google-maps-frontend',
+////                'https://maps.googleapis.com/maps/api/js?key=' . GOOGLE_API . '&callback=googleMapsLoaded',
+////                [],
+////                null,
+////                ['strategy' => 'async',
+////                 'in_footer' => true]
+////            );
+//
+//            // Add the callback function
+//            wp_add_inline_script('google-maps-frontend', '
+//            function googleMapsLoaded() {
+//                if (window.googleMapsCallbacks && window.googleMapsCallbacks.length) {
+//                    window.googleMapsCallbacks.forEach(callback => callback());
+//                }
+//            }
+//        ');
+//        }
+	}
+	if (is_user_logged_in() && Site::has('notifications')) {
+		wp_enqueue_script('jvb-notifications');
+
+		wp_localize_script('jvb-notifications', 'notificationSettings', array(
+			'homeUrl' => home_url(),
+			'strings' => array(
+				'loading' => 'Loading...',
+				'error' => 'Failed to load notifications',
+				'noNotifications' => 'No new notifications',
+				'viewAll' => 'View All Notifications',
+				'markRead' => 'Mark as read',
+				'review' => 'Review'
+			)
+		));
+	}
+
+//    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-queue');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-selector');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-data-store');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-cache');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-a11y');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-utility');
+	jvbAddScriptDependency('jvb-feed-view-script', 'jvb-gallery');
+//    jvbAddScriptDependency('jvb-feed-view-script', 'jvb-loading');
+	jvbAddScriptDependency('jvb-forms-view-script', 'jvb-queue');
+	jvbAddScriptDependency('jvb-forms-view-script', 'jvb-quill');
+	jvbAddScriptDependency('jvb-forms-view-script', 'jvb-form');
+	jvbAddScriptDependency('jvb-forms-view-script', 'jvb-tabs');
+
+	jvbAddScriptDependency('jvb-timeline-view-script', 'jvb-gallery');
+}
+
+function jvbAddScriptDependency(string $handle, string $dep):bool
+{
+	global $wp_scripts;
+
+	$script = $wp_scripts->query($handle);
+	if (!$script) {
+		return false;
+	}
+
+	if (!in_array($dep, $script->deps)) {
+		$script->deps[] = $dep;
+	}
+
+	return true;
+}

--
Gitblit v1.10.0