From eea4e21d9bd7b89f7124fa1acbe3347d68db6d90 Mon Sep 17 00:00:00 2001
From: Jake Vanderwerf <get@jakevanderwerf.ca>
Date: Sun, 04 Jan 2026 19:35:27 +0000
Subject: [PATCH] =further taxonomyCreator.js debugging

---
 assets/js/concise/TaxonomySelector.js |   30 ++++++++++++++++++++++++------
 1 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/assets/js/concise/TaxonomySelector.js b/assets/js/concise/TaxonomySelector.js
index 7f27f13..8ae44bb 100644
--- a/assets/js/concise/TaxonomySelector.js
+++ b/assets/js/concise/TaxonomySelector.js
@@ -16,7 +16,7 @@
 
 		this.subscribers = new Set();
 
-		this.store = window.jvbStore.register(
+		const store = window.jvbStore.register(
 			'taxonomies',
 			{
 				storeName: `terms`,
@@ -39,6 +39,7 @@
 				required: 'taxonomy',
 				delayFetch: true,
 			});
+		this.store = store.terms;
 
 		// Central field management
 		this.fields = new Map();
@@ -479,7 +480,13 @@
 
 	initAutocomplete()
 	{
-		this.autocompleteHandler = window.debounce((e) => this.handleAutocomplete(e), 300);
+		this.autocompleteHandler = (e) => {
+			window.debouncer.schedule(
+				'taxonomy-autocomplete',
+				() => this.handleAutocomplete(e),
+				300
+			);
+		};
 		document.addEventListener('input', this.autocompleteHandler);
 		document.addEventListener('blur', this.cleanupAutocomplete.bind(this));
 		// Preload taxonomy data on focus
@@ -1125,11 +1132,17 @@
 			});
 		}
 
-		// Use stored current query instead of debounced one
+		// Only show create button if exact match doesn't exist
 		const currentQuery = field.currentAutocompleteQuery || query;
 		if (field.canCreate && currentQuery && window.jvbTaxCreator) {
-			const createOption = this.createNewTermOption(currentQuery);
-			dropdown.appendChild(createOption);
+			const exactMatch = terms.find(term =>
+				term.name.toLowerCase() === currentQuery.toLowerCase()
+			);
+
+			if (!exactMatch) {
+				const createOption = this.createNewTermOption(currentQuery);
+				dropdown.appendChild(createOption);
+			}
 		}
 
 		dropdown.hidden = false;
@@ -1544,5 +1557,10 @@
  * Initialize singleton
  */
 document.addEventListener('DOMContentLoaded', function() {
-	window.jvbSelector = new TaxonomySelector();
+	window.auth.subscribe((event) => {
+		if (event === 'auth-loaded') {
+			window.jvbSelector = new TaxonomySelector();
+		}
+	});
+
 });

--
Gitblit v1.10.0